Skip to content

Commit 5a2e4f2

Browse files
committed
Updates for REST API server
1 parent ca840fb commit 5a2e4f2

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

convex-cli/src/main/java/convex/cli/local/LocalStart.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ private List<AKeyPair> getPeerKeyPairs(int n) {
8787
}
8888
int left=n-keyPairList.size();
8989
if (left>0) {
90-
log.warn("Insufficient key pairs specified. Additional "+left+" keypair(s) will be generated");
90+
informWarning("Insufficient key pairs specified. Additional "+left+" keypair(s) will be generated");
9191
for (int i=0; i<left; i++) {
9292
AKeyPair kp=AKeyPair.generate();
9393
keyPairList.add(kp);
94-
log.warn("Generated key: "+kp.getAccountKey().toChecksumHex()+" Priv: "+kp.getSeed());
94+
log.info("Generated key: "+kp.getAccountKey().toChecksumHex()+" Priv: "+kp.getSeed());
9595
}
9696
}
9797

@@ -111,7 +111,7 @@ public void run() {
111111
try {
112112
peerPorts = Helpers.getPortList(ports, count);
113113
} catch (NumberFormatException e) {
114-
log.warn("cannot convert port number " + e);
114+
informWarning("Cannot convert port number " + e);
115115
return;
116116
}
117117
if (peerPorts.length < count) {
@@ -130,7 +130,7 @@ public void run() {
130130
}
131131
launchRestAPI(servers.get(0));
132132
} catch (Throwable t) {
133-
log.warn("Failed to start REST server: "+t);
133+
informWarning("Failed to start REST server: "+t);
134134
}
135135

136136
// Loop until we end

convex-restapi/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<properties>
1818
<json.simple.version>1.1.1</json.simple.version>
19-
<javalin.version>6.1.6</javalin.version>
19+
<javalin.version>6.2.0</javalin.version>
2020
</properties>
2121

2222
<build>

convex-restapi/src/main/java/convex/restapi/RESTServer.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import io.javalin.community.ssl.SslPlugin;
2121
import io.javalin.config.JavalinConfig;
2222
import io.javalin.http.staticfiles.Location;
23+
import io.javalin.openapi.JsonSchemaLoader;
24+
import io.javalin.openapi.JsonSchemaResource;
2325
import io.javalin.openapi.plugin.OpenApiPlugin;
2426
import io.javalin.openapi.plugin.redoc.ReDocPlugin;
2527
import io.javalin.openapi.plugin.swagger.SwaggerPlugin;
@@ -98,18 +100,30 @@ protected SslPlugin getSSLPlugin(HashMap<Keyword, Object> config) {
98100
}
99101

100102
protected void addOpenApiPlugins(JavalinConfig config) {
103+
String docsPath="openapi-plugin/openapi-default.json";
104+
101105
config.registerPlugin(new OpenApiPlugin(pluginConfig -> {
102106

103-
pluginConfig.withDefinitionConfiguration((version, definition) -> {
107+
pluginConfig
108+
.withDocumentationPath(docsPath)
109+
.withDefinitionConfiguration((version, definition) -> {
104110
definition.withOpenApiInfo(info -> {
105111
info.setTitle("Convex REST API");
106112
info.setVersion("0.1.1");
107113
});
108114
});
109115
}));
110116

111-
config.registerPlugin(new SwaggerPlugin());
112-
config.registerPlugin(new ReDocPlugin());
117+
config.registerPlugin(new SwaggerPlugin(swaggerConfiguration->{
118+
swaggerConfiguration.setDocumentationPath(docsPath);
119+
}));
120+
config.registerPlugin(new ReDocPlugin(reDocConfiguration -> {
121+
reDocConfiguration.setDocumentationPath(docsPath);
122+
}));
123+
124+
for (JsonSchemaResource generatedJsonSchema : new JsonSchemaLoader().loadGeneratedSchemes()) {
125+
System.out.println(generatedJsonSchema.getName());
126+
}
113127
}
114128

115129
protected ChainAPI chainAPI;

convex-restapi/src/main/java/convex/restapi/api/ChainAPI.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import convex.core.util.Utils;
3939
import convex.java.JSON;
4040
import convex.restapi.RESTServer;
41+
import convex.restapi.model.CreateAccountRequest;
4142
import io.javalin.Javalin;
4243
import io.javalin.http.BadRequestResponse;
4344
import io.javalin.http.Context;
@@ -112,11 +113,15 @@ public void getData(Context ctx) {
112113
operationId = "createAccount",
113114
summary="Create a new Convex account",
114115
requestBody = @OpenApiRequestBody(
115-
description = "Complex bodies",
116+
description = "Create Account request, must provide an accountKey for the new Account",
116117
content= {@OpenApiContent(
117-
from = String.class,
118-
// type = "application/json",
119-
example = "{}")}))
118+
from = CreateAccountRequest.class,
119+
type = "application/json",
120+
exampleObjects = {
121+
@OpenApiExampleProperty(name="accountKey", value = "d82e78594610f708ad47f666bbacbab1711760652cb88bf7515ed6c3ae84a08d")
122+
}
123+
//example = "{\"accountKey\": \"d82e78594610f708ad47f666bbacbab1711760652cb88bf7515ed6c3ae84a08d\"}")}
124+
)}))
120125
public void createAccount(Context ctx) {
121126
Map<String, Object> req=getJSONBody(ctx);
122127
Object key = req.get("accountKey");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package convex.restapi.model;
2+
3+
import io.javalin.openapi.OpenApiByFields;
4+
5+
@OpenApiByFields
6+
public class CreateAccountRequest {
7+
public String accountKey;
8+
}

0 commit comments

Comments
 (0)