Skip to content

Commit ab27a1d

Browse files
committed
More OpenAPI docs
1 parent 8e557f4 commit ab27a1d

File tree

5 files changed

+37
-23
lines changed

5 files changed

+37
-23
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected void addOpenApiPlugins(JavalinConfig config) {
109109
.withDefinitionConfiguration((version, definition) -> {
110110
definition.withOpenApiInfo(info -> {
111111
info.setTitle("Convex REST API");
112-
info.setVersion("0.1.1");
112+
info.setVersion("0.7.0");
113113
});
114114
});
115115
}));

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,19 @@
4040
import convex.restapi.RESTServer;
4141
import convex.restapi.model.CreateAccountRequest;
4242
import convex.restapi.model.CreateAccountResponse;
43-
import convex.restapi.model.QueryAccountRequest;
43+
import convex.restapi.model.QueryAccountResponse;
4444
import io.javalin.Javalin;
4545
import io.javalin.http.BadRequestResponse;
4646
import io.javalin.http.Context;
4747
import io.javalin.http.InternalServerErrorResponse;
4848
import io.javalin.http.ServiceUnavailableResponse;
49-
import io.javalin.openapi.*;
49+
import io.javalin.openapi.HttpMethod;
50+
import io.javalin.openapi.OpenApi;
51+
import io.javalin.openapi.OpenApiContent;
52+
import io.javalin.openapi.OpenApiExampleProperty;
53+
import io.javalin.openapi.OpenApiParam;
54+
import io.javalin.openapi.OpenApiRequestBody;
55+
import io.javalin.openapi.OpenApiResponse;
5056

5157
public class ChainAPI extends ABaseAPI {
5258

@@ -154,40 +160,32 @@ public void createAccount(Context ctx) {
154160
ctx.result("{\"address\": " + a.longValue() + "}");
155161
}
156162

157-
@OpenApi(path = ROUTE + "account/{account}",
158-
methods = HttpMethod.POST,
163+
@OpenApi(path = ROUTE + "accounts/{address}",
164+
methods = HttpMethod.GET,
159165
operationId = "queryAccount",
160166
tags = { "Account"},
161167
summary = "Get Convex account information",
162-
requestBody = @OpenApiRequestBody(
163-
description = "Query Account request, must provide a valid address",
164-
content = {@OpenApiContent(
165-
from = QueryAccountRequest.class,
166-
type = "application/json",
167-
exampleObjects = {
168-
@OpenApiExampleProperty(name = "address", value = "#14") })}
169-
),
168+
pathParams = {
169+
@OpenApiParam(name = "address", description = "Address of Account", required = true, type = String.class, example="14")
170+
},
170171
responses = {
171172
@OpenApiResponse(status = "200",
172173
description = "Account queried sucecssfully",
173174
content = {
174175
@OpenApiContent(
176+
from=QueryAccountResponse.class,
175177
type = "application/json") }),
176-
@OpenApiResponse(status = "400",
178+
@OpenApiResponse(status = "404",
177179
description = "Account does not exist" )
178180
}
179181
)
180182
public void queryAccount(Context ctx) {
181183
Address addr = null;
182184
String addrParam = ctx.pathParam("addr");
183-
try {
184-
long a = Long.parseLong(addrParam);
185-
addr = Address.create(a);
186-
if (addr == null)
187-
throw new BadRequestResponse(jsonError("Invalid address: " + a));
188-
} catch (Exception e) {
189-
throw new BadRequestResponse(
190-
jsonError("Expected valid account number in path but got [" + addrParam + "]"));
185+
186+
addr = Address.parse(addrParam);
187+
if (addr == null) {
188+
throw new BadRequestResponse(jsonError("Invalid address: " + addrParam));
191189
}
192190

193191
Result r = doQuery(Lists.of(Symbols.ACCOUNT, addr));
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 CVMResult {
7+
8+
}
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 QueryAccountResponse {
7+
public String address;
8+
}

convex-restapi/src/main/java/convex/restapi/model/QueryAccountRequest.java renamed to convex-restapi/src/main/java/convex/restapi/model/QueryRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import io.javalin.openapi.OpenApiByFields;
44

55
@OpenApiByFields
6-
public class QueryAccountRequest {
6+
public class QueryRequest {
77
public String address;
88
}

0 commit comments

Comments
 (0)