update samples

This commit is contained in:
William Cheng 2023-08-09 14:27:57 +08:00
parent 3ed59cd593
commit 3f8bce6695
8 changed files with 86 additions and 19 deletions

View File

@ -44,7 +44,7 @@ public interface AnotherFakeApiDelegate {
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"client\" : \"client\" }"; String exampleString = "{ \"client\" : \"client\" }";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break; break;
} }
} }

View File

@ -567,6 +567,35 @@ public interface FakeApi {
} }
/**
* GET /fake/response-with-example
* This endpoint defines an example value for its response schema.
*
* @return Success (status code 200)
*/
@ApiOperation(
tags = { "fake" },
value = "",
nickname = "testWithResultExample",
notes = "This endpoint defines an example value for its response schema.",
response = Integer.class
)
@ApiResponses({
@ApiResponse(code = 200, message = "Success", response = Integer.class)
})
@RequestMapping(
method = RequestMethod.GET,
value = "/fake/response-with-example",
produces = { "application/json" }
)
@ResponseStatus(HttpStatus.OK)
default Mono<Integer> testWithResultExample(
@ApiIgnore final ServerWebExchange exchange
) {
return getDelegate().testWithResultExample(exchange);
}
/** /**
* POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required)
* *

View File

@ -87,7 +87,7 @@ public interface FakeApiDelegate {
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) {
String exampleString = "{ \"my_string\" : \"my_string\", \"my_number\" : 0.8008281904610115, \"my_boolean\" : true }"; String exampleString = "{ \"my_string\" : \"my_string\", \"my_number\" : 0.8008281904610115, \"my_boolean\" : true }";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break; break;
} }
} }
@ -141,7 +141,7 @@ public interface FakeApiDelegate {
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"UPPER_CASE_PROPERTY_SNAKE\" : \"UPPER_CASE_PROPERTY_SNAKE\", \"lower-case-property-dashes\" : \"lower-case-property-dashes\", \"property name with spaces\" : \"property name with spaces\", \"normalPropertyName\" : \"normalPropertyName\" }"; String exampleString = "{ \"UPPER_CASE_PROPERTY_SNAKE\" : \"UPPER_CASE_PROPERTY_SNAKE\", \"lower-case-property-dashes\" : \"lower-case-property-dashes\", \"property name with spaces\" : \"property name with spaces\", \"normalPropertyName\" : \"normalPropertyName\" }";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break; break;
} }
} }
@ -197,7 +197,7 @@ public interface FakeApiDelegate {
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"client\" : \"client\" }"; String exampleString = "{ \"client\" : \"client\" }";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break; break;
} }
} }
@ -361,6 +361,27 @@ public interface FakeApiDelegate {
} }
/**
* GET /fake/response-with-example
* This endpoint defines an example value for its response schema.
*
* @return Success (status code 200)
* @see FakeApi#testWithResultExample
*/
default Mono<Integer> testWithResultExample(ServerWebExchange exchange) {
Mono<Void> result = Mono.empty();
exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "42";
result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break;
}
}
return result.then(Mono.empty());
}
/** /**
* POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required)
* *
@ -380,7 +401,7 @@ public interface FakeApiDelegate {
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\" }"; String exampleString = "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\" }";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break; break;
} }
} }

View File

@ -44,7 +44,7 @@ public interface FakeClassnameTestApiDelegate {
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"client\" : \"client\" }"; String exampleString = "{ \"client\" : \"client\" }";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break; break;
} }
} }

View File

@ -83,12 +83,12 @@ public interface PetApiDelegate {
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" } ]"; String exampleString = "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" } ]";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break; break;
} }
if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) {
String exampleString = "<Pet> <id>123456789</id> <Category> <id>123456789</id> <name>aeiou</name> </Category> <name>doggie</name> <photoUrls> <photoUrls>aeiou</photoUrls> </photoUrls> <tags> <Tag> <id>123456789</id> <name>aeiou</name> </Tag> </tags> <status>aeiou</status> </Pet>"; String exampleString = "<Pet> <id>123456789</id> <Category> <id>123456789</id> <name>aeiou</name> </Category> <name>doggie</name> <photoUrls> <photoUrls>aeiou</photoUrls> </photoUrls> <tags> <Tag> <id>123456789</id> <name>aeiou</name> </Tag> </tags> <status>aeiou</status> </Pet>";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/xml"), exampleString);
break; break;
} }
} }
@ -114,12 +114,12 @@ public interface PetApiDelegate {
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" } ]"; String exampleString = "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" } ]";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break; break;
} }
if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) {
String exampleString = "<Pet> <id>123456789</id> <Category> <id>123456789</id> <name>aeiou</name> </Category> <name>doggie</name> <photoUrls> <photoUrls>aeiou</photoUrls> </photoUrls> <tags> <Tag> <id>123456789</id> <name>aeiou</name> </Tag> </tags> <status>aeiou</status> </Pet>"; String exampleString = "<Pet> <id>123456789</id> <Category> <id>123456789</id> <name>aeiou</name> </Category> <name>doggie</name> <photoUrls> <photoUrls>aeiou</photoUrls> </photoUrls> <tags> <Tag> <id>123456789</id> <name>aeiou</name> </Tag> </tags> <status>aeiou</status> </Pet>";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/xml"), exampleString);
break; break;
} }
} }
@ -144,12 +144,12 @@ public interface PetApiDelegate {
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }"; String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"default-name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break; break;
} }
if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) {
String exampleString = "<Pet> <id>123456789</id> <Category> <id>123456789</id> <name>aeiou</name> </Category> <name>doggie</name> <photoUrls> <photoUrls>aeiou</photoUrls> </photoUrls> <tags> <Tag> <id>123456789</id> <name>aeiou</name> </Tag> </tags> <status>aeiou</status> </Pet>"; String exampleString = "<Pet> <id>123456789</id> <Category> <id>123456789</id> <name>aeiou</name> </Category> <name>doggie</name> <photoUrls> <photoUrls>aeiou</photoUrls> </photoUrls> <tags> <Tag> <id>123456789</id> <name>aeiou</name> </Tag> </tags> <status>aeiou</status> </Pet>";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/xml"), exampleString);
break; break;
} }
} }
@ -215,7 +215,7 @@ public interface PetApiDelegate {
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\" }"; String exampleString = "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\" }";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break; break;
} }
} }

View File

@ -78,12 +78,12 @@ public interface StoreApiDelegate {
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\" }"; String exampleString = "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\" }";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break; break;
} }
if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) {
String exampleString = "<Order> <id>123456789</id> <petId>123456789</petId> <quantity>123</quantity> <shipDate>2000-01-23T04:56:07.000Z</shipDate> <status>aeiou</status> <complete>true</complete> </Order>"; String exampleString = "<Order> <id>123456789</id> <petId>123456789</petId> <quantity>123</quantity> <shipDate>2000-01-23T04:56:07.000Z</shipDate> <status>aeiou</status> <complete>true</complete> </Order>";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/xml"), exampleString);
break; break;
} }
} }
@ -107,12 +107,12 @@ public interface StoreApiDelegate {
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\" }"; String exampleString = "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\" }";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break; break;
} }
if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) {
String exampleString = "<Order> <id>123456789</id> <petId>123456789</petId> <quantity>123</quantity> <shipDate>2000-01-23T04:56:07.000Z</shipDate> <status>aeiou</status> <complete>true</complete> </Order>"; String exampleString = "<Order> <id>123456789</id> <petId>123456789</petId> <quantity>123</quantity> <shipDate>2000-01-23T04:56:07.000Z</shipDate> <status>aeiou</status> <complete>true</complete> </Order>";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/xml"), exampleString);
break; break;
} }
} }

View File

@ -112,12 +112,12 @@ public interface UserApiDelegate {
for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"firstName\" : \"firstName\", \"lastName\" : \"lastName\", \"password\" : \"password\", \"userStatus\" : 6, \"phone\" : \"phone\", \"id\" : 0, \"email\" : \"email\", \"username\" : \"username\" }"; String exampleString = "{ \"firstName\" : \"firstName\", \"lastName\" : \"lastName\", \"password\" : \"password\", \"userStatus\" : 6, \"phone\" : \"phone\", \"id\" : 0, \"email\" : \"email\", \"username\" : \"username\" }";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString);
break; break;
} }
if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) {
String exampleString = "<User> <id>123456789</id> <username>aeiou</username> <firstName>aeiou</firstName> <lastName>aeiou</lastName> <email>aeiou</email> <password>aeiou</password> <phone>aeiou</phone> <userStatus>123</userStatus> </User>"; String exampleString = "<User> <id>123456789</id> <username>aeiou</username> <firstName>aeiou</firstName> <lastName>aeiou</lastName> <email>aeiou</email> <password>aeiou</password> <phone>aeiou</phone> <userStatus>123</userStatus> </User>";
result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/xml"), exampleString);
break; break;
} }
} }

View File

@ -1088,6 +1088,23 @@ paths:
x-accepts: application/json x-accepts: application/json
x-tags: x-tags:
- tag: fake - tag: fake
/fake/response-with-example:
get:
description: This endpoint defines an example value for its response schema.
operationId: testWithResultExample
responses:
"200":
content:
application/json:
schema:
example: 42
type: integer
description: Success
tags:
- fake
x-accepts: application/json
x-tags:
- tag: fake
/fake/test-query-parameters: /fake/test-query-parameters:
put: put:
description: To test the collection format in query parameters description: To test the collection format in query parameters