From 3ed59cd5939084dad009b07b9abbb5ea6d03e5aa Mon Sep 17 00:00:00 2001 From: martin-mfg <2026226+martin-mfg@users.noreply.github.com> Date: Tue, 8 Aug 2023 14:52:18 +0200 Subject: [PATCH] [spring] reactive: fix Content-Type (#16228) * don't set content-type to client's value * revert manual sample change * better fix * generate samples * cover 3rd case * add new test endpoint --- .../codegen/examples/ExampleGenerator.java | 6 +++ .../resources/JavaSpring/methodBody.mustache | 2 +- ...ith-fake-endpoints-models-for-testing.yaml | 14 +++++++ .../java/org/openapitools/api/FakeApi.java | 16 ++++++++ .../java/org/openapitools/api/FakeApi.java | 16 ++++++++ .../java/org/openapitools/api/FakeApi.java | 26 +++++++++++++ .../java/org/openapitools/api/FakeApi.java | 28 +++++++++++++ .../org/openapitools/api/FakeApiDelegate.java | 21 ++++++++++ .../src/main/resources/openapi.yaml | 17 ++++++++ .../java/org/openapitools/api/FakeApi.java | 38 ++++++++++++++++++ .../src/main/resources/openapi.yaml | 17 ++++++++ .../java/org/openapitools/api/FakeApi.java | 26 +++++++++++++ .../java/org/openapitools/api/FakeApi.java | 38 ++++++++++++++++++ .../src/main/resources/openapi.yaml | 17 ++++++++ .../java/org/openapitools/api/FakeApi.java | 38 ++++++++++++++++++ .../src/main/resources/openapi.yaml | 17 ++++++++ .../java/org/openapitools/api/FakeApi.java | 28 +++++++++++++ .../org/openapitools/api/FakeApiDelegate.java | 21 ++++++++++ .../src/main/resources/openapi.yaml | 17 ++++++++ .../java/org/openapitools/api/FakeApi.java | 28 +++++++++++++ .../org/openapitools/api/FakeApiDelegate.java | 21 ++++++++++ .../src/main/resources/openapi.yaml | 17 ++++++++ .../java/org/openapitools/api/FakeApi.java | 38 ++++++++++++++++++ .../src/main/resources/openapi.yaml | 17 ++++++++ .../api/AnotherFakeApiDelegate.java | 2 +- .../java/org/openapitools/api/FakeApi.java | 28 +++++++++++++ .../org/openapitools/api/FakeApiDelegate.java | 29 ++++++++++++-- .../api/FakeClassnameTestApiDelegate.java | 2 +- .../org/openapitools/api/PetApiDelegate.java | 14 +++---- .../openapitools/api/StoreApiDelegate.java | 8 ++-- .../org/openapitools/api/UserApiDelegate.java | 4 +- .../src/main/resources/openapi.yaml | 17 ++++++++ .../java/org/openapitools/api/FakeApi.java | 38 ++++++++++++++++++ .../src/main/resources/openapi.yaml | 17 ++++++++ .../openapitools/virtualan/api/FakeApi.java | 39 +++++++++++++++++++ .../src/main/resources/openapi.yaml | 17 ++++++++ .../java/org/openapitools/api/FakeApi.java | 38 ++++++++++++++++++ .../src/main/resources/openapi.yaml | 17 ++++++++ 38 files changed, 774 insertions(+), 20 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/examples/ExampleGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/examples/ExampleGenerator.java index 194d40a47c7c..d34cdd7127a7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/examples/ExampleGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/examples/ExampleGenerator.java @@ -38,6 +38,7 @@ public class ExampleGenerator { private static final String EXAMPLE = "example"; private static final String CONTENT_TYPE = "contentType"; + private static final String GENERATED_CONTENT_TYPE = "generatedContentType"; private static final String OUTPUT = "output"; private static final String NONE = "none"; private static final String URL = "url"; @@ -112,12 +113,14 @@ public class ExampleGenerator { String example = Json.pretty(resolvePropertyToExample("", mediaType, property, processedModels)); if (example != null) { kv.put(EXAMPLE, example); + kv.put(GENERATED_CONTENT_TYPE, MIME_TYPE_JSON); output.add(kv); } } else if (property != null && mediaType.startsWith(MIME_TYPE_XML)) { String example = new XmlExampleGenerator(this.examples).toXml(property); if (example != null) { kv.put(EXAMPLE, example); + kv.put(GENERATED_CONTENT_TYPE, MIME_TYPE_XML); output.add(kv); } } @@ -157,6 +160,7 @@ public class ExampleGenerator { if (example != null) { kv.put(EXAMPLE, example); + kv.put(GENERATED_CONTENT_TYPE, MIME_TYPE_JSON); output.add(kv); } } @@ -165,6 +169,7 @@ public class ExampleGenerator { String example = new XmlExampleGenerator(this.examples).toXml(schema, 0, Collections.emptySet()); if (example != null) { kv.put(EXAMPLE, example); + kv.put(GENERATED_CONTENT_TYPE, MIME_TYPE_XML); output.add(kv); } } else { @@ -201,6 +206,7 @@ public class ExampleGenerator { kv.put(CONTENT_TYPE, mediaType); if ((mediaType.startsWith(MIME_TYPE_JSON) || mediaType.contains("*/*"))) { kv.put(EXAMPLE, Json.pretty(example)); + kv.put(GENERATED_CONTENT_TYPE, MIME_TYPE_JSON); output.add(kv); } else if (mediaType.startsWith(MIME_TYPE_XML)) { // TODO diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/methodBody.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/methodBody.mustache index 0decb2314ba3..1d3aeb0a6f18 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/methodBody.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/methodBody.mustache @@ -39,7 +39,7 @@ Mono result = Mono.empty(); {{/-first}} if (mediaType.isCompatibleWith(MediaType.valueOf("{{{contentType}}}"))) { String exampleString = {{>exampleString}}; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("{{{generatedContentType}}}"), exampleString); break; } {{#-last}} diff --git a/modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml index 27c97636a188..6814753bd2fa 100644 --- a/modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml @@ -1008,6 +1008,20 @@ paths: responses: "200": description: Success + /fake/response-with-example: + get: + tags: + - fake + 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 /fake/test-query-parameters: put: tags: diff --git a/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/api/FakeApi.java b/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/api/FakeApi.java index 33845474de5a..c93fa81931a9 100644 --- a/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/api/FakeApi.java @@ -343,4 +343,20 @@ public interface FakeApi { @RequestParam(value = "context", required = true) List context ); + + /** + * GET /fake/response-with-example + * This endpoint defines an example value for its response schema. + * + * @return Success (status code 200) + */ + @HttpExchange( + method = "GET", + value = "/fake/response-with-example", + accept = "application/json" + ) + Mono> testWithResultExample( + + ); + } diff --git a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/api/FakeApi.java b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/api/FakeApi.java index dd0b7038c748..0de5564f03dc 100644 --- a/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/client/petstore/spring-http-interface/src/main/java/org/openapitools/api/FakeApi.java @@ -339,4 +339,20 @@ public interface FakeApi { @RequestParam(value = "context", required = true) List context ); + + /** + * GET /fake/response-with-example + * This endpoint defines an example value for its response schema. + * + * @return Success (status code 200) + */ + @HttpExchange( + method = "GET", + value = "/fake/response-with-example", + accept = "application/json" + ) + ResponseEntity testWithResultExample( + + ); + } diff --git a/samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/api/FakeApi.java b/samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/api/FakeApi.java index 753b09209960..c59dd996afce 100644 --- a/samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/api/FakeApi.java @@ -480,4 +480,30 @@ public interface FakeApi { @NotNull @Parameter(name = "context", description = "", required = true, in = ParameterIn.QUERY) @Valid @RequestParam(value = "context", required = true) List context ); + + /** + * GET /fake/response-with-example + * This endpoint defines an example value for its response schema. + * + * @return Success (status code 200) + */ + @Operation( + operationId = "testWithResultExample", + description = "This endpoint defines an example value for its response schema.", + tags = { "fake" }, + responses = { + @ApiResponse(responseCode = "200", description = "Success", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = Integer.class)) + }) + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/fake/response-with-example", + produces = "application/json" + ) + ResponseEntity testWithResultExample( + + ); + } diff --git a/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApi.java b/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApi.java index 0217cfdeffcb..7259c4703b89 100644 --- a/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApi.java @@ -538,6 +538,34 @@ public interface FakeApi { } + /** + * GET /fake/response-with-example + * This endpoint defines an example value for its response schema. + * + * @return Success (status code 200) + */ + @Operation( + operationId = "testWithResultExample", + description = "This endpoint defines an example value for its response schema.", + tags = { "fake" }, + responses = { + @ApiResponse(responseCode = "200", description = "Success", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = Integer.class)) + }) + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/fake/response-with-example", + produces = { "application/json" } + ) + default ResponseEntity testWithResultExample( + + ) { + return getDelegate().testWithResultExample(); + } + + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApiDelegate.java b/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApiDelegate.java index 15b5bee3d2bb..c8b380f33c01 100644 --- a/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApiDelegate.java +++ b/samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApiDelegate.java @@ -318,6 +318,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 ResponseEntity testWithResultExample() { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "42"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/openapi3/server/petstore/springboot-delegate/src/main/resources/openapi.yaml b/samples/openapi3/server/petstore/springboot-delegate/src/main/resources/openapi.yaml index 98f0e7e6f9d0..ae88e043d50b 100644 --- a/samples/openapi3/server/petstore/springboot-delegate/src/main/resources/openapi.yaml +++ b/samples/openapi3/server/petstore/springboot-delegate/src/main/resources/openapi.yaml @@ -1088,6 +1088,23 @@ paths: x-accepts: application/json x-tags: - 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: put: description: To test the collection format in query parameters diff --git a/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/FakeApi.java b/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/FakeApi.java index 21a182046500..fc97fae2fd5b 100644 --- a/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/FakeApi.java @@ -584,6 +584,44 @@ public interface FakeApi { } + /** + * GET /fake/response-with-example + * This endpoint defines an example value for its response schema. + * + * @return Success (status code 200) + */ + @Operation( + operationId = "testWithResultExample", + description = "This endpoint defines an example value for its response schema.", + tags = { "fake" }, + responses = { + @ApiResponse(responseCode = "200", description = "Success", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = Integer.class)) + }) + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/fake/response-with-example", + produces = { "application/json" } + ) + default ResponseEntity testWithResultExample( + + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "42"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/resources/openapi.yaml b/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/resources/openapi.yaml index 98f0e7e6f9d0..ae88e043d50b 100644 --- a/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/resources/openapi.yaml +++ b/samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/resources/openapi.yaml @@ -1088,6 +1088,23 @@ paths: x-accepts: application/json x-tags: - 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: put: description: To test the collection format in query parameters diff --git a/samples/server/petstore/spring-boot-defaultInterface-unhandledException/src/main/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/spring-boot-defaultInterface-unhandledException/src/main/java/org/openapitools/api/FakeApi.java index fee1e658c655..7859088fe7d3 100644 --- a/samples/server/petstore/spring-boot-defaultInterface-unhandledException/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/spring-boot-defaultInterface-unhandledException/src/main/java/org/openapitools/api/FakeApi.java @@ -508,6 +508,32 @@ public interface FakeApi { ) throws Exception; + /** + * GET /fake/response-with-example + * This endpoint defines an example value for its response schema. + * + * @return Success (status code 200) + */ + @Operation( + operationId = "testWithResultExample", + description = "This endpoint defines an example value for its response schema.", + tags = { "fake" }, + responses = { + @ApiResponse(responseCode = "200", description = "Success", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = Integer.class)) + }) + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/fake/response-with-example", + produces = { "application/json" } + ) + ResponseEntity testWithResultExample( + + ) throws Exception; + + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/api/FakeApi.java index d4b401888737..4c5fc452c467 100644 --- a/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/api/FakeApi.java @@ -578,6 +578,44 @@ 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" } + ) + default ResponseEntity testWithResultExample( + + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "42"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/resources/openapi.yaml index 98f0e7e6f9d0..ae88e043d50b 100644 --- a/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/resources/openapi.yaml @@ -1088,6 +1088,23 @@ paths: x-accepts: application/json x-tags: - 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: put: description: To test the collection format in query parameters diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/FakeApi.java index d4b401888737..4c5fc452c467 100644 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/api/FakeApi.java @@ -578,6 +578,44 @@ 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" } + ) + default ResponseEntity testWithResultExample( + + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "42"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-beanvalidation/src/main/resources/openapi.yaml index 98f0e7e6f9d0..ae88e043d50b 100644 --- a/samples/server/petstore/springboot-beanvalidation/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-beanvalidation/src/main/resources/openapi.yaml @@ -1088,6 +1088,23 @@ paths: x-accepts: application/json x-tags: - 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: put: description: To test the collection format in query parameters diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeApi.java index 9822c6442256..3332ae0ae990 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeApi.java @@ -532,6 +532,34 @@ 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" } + ) + default ResponseEntity testWithResultExample( + + ) { + return getDelegate().testWithResultExample(); + } + + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeApiDelegate.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeApiDelegate.java index 15b5bee3d2bb..c8b380f33c01 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeApiDelegate.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/api/FakeApiDelegate.java @@ -318,6 +318,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 ResponseEntity testWithResultExample() { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "42"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-delegate-j8/src/main/resources/openapi.yaml index 98f0e7e6f9d0..ae88e043d50b 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-delegate-j8/src/main/resources/openapi.yaml @@ -1088,6 +1088,23 @@ paths: x-accepts: application/json x-tags: - 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: put: description: To test the collection format in query parameters diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApi.java index 9822c6442256..3332ae0ae990 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApi.java @@ -532,6 +532,34 @@ 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" } + ) + default ResponseEntity testWithResultExample( + + ) { + return getDelegate().testWithResultExample(); + } + + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApiDelegate.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApiDelegate.java index 15b5bee3d2bb..c8b380f33c01 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApiDelegate.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/api/FakeApiDelegate.java @@ -318,6 +318,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 ResponseEntity testWithResultExample() { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "42"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/server/petstore/springboot-delegate/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-delegate/src/main/resources/openapi.yaml index 98f0e7e6f9d0..ae88e043d50b 100644 --- a/samples/server/petstore/springboot-delegate/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-delegate/src/main/resources/openapi.yaml @@ -1088,6 +1088,23 @@ paths: x-accepts: application/json x-tags: - 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: put: description: To test the collection format in query parameters diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/FakeApi.java index 8cfd7528defe..45e6b984d09b 100644 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/api/FakeApi.java @@ -578,6 +578,44 @@ 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" } + ) + default ResponseEntity testWithResultExample( + + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "42"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-implicitHeaders/src/main/resources/openapi.yaml index 98f0e7e6f9d0..ae88e043d50b 100644 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-implicitHeaders/src/main/resources/openapi.yaml @@ -1088,6 +1088,23 @@ paths: x-accepts: application/json x-tags: - 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: put: description: To test the collection format in query parameters diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java index 89c3aeba00dc..9bbc62f690e9 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/AnotherFakeApiDelegate.java @@ -45,7 +45,7 @@ public interface AnotherFakeApiDelegate { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { String exampleString = "{ \"client\" : \"client\" }"; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString); break; } } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApi.java index bba9e3516e6d..031996311d57 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApi.java @@ -552,6 +552,34 @@ 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" } + ) + default Mono> testWithResultExample( + @ApiIgnore final ServerWebExchange exchange + ) { + return getDelegate().testWithResultExample(exchange); + } + + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApiDelegate.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApiDelegate.java index 4c5aa7381a1b..8fa3ade10771 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApiDelegate.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeApiDelegate.java @@ -88,7 +88,7 @@ public interface FakeApiDelegate { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { 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; } } @@ -142,7 +142,7 @@ public interface FakeApiDelegate { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { 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\" }"; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString); break; } } @@ -198,7 +198,7 @@ public interface FakeApiDelegate { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { String exampleString = "{ \"client\" : \"client\" }"; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString); break; } } @@ -362,6 +362,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> testWithResultExample(ServerWebExchange exchange) { + Mono 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) * @@ -381,7 +402,7 @@ public interface FakeApiDelegate { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { String exampleString = "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\" }"; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString); break; } } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java index 7d7d23d7a5ec..a22825a889f3 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/FakeClassnameTestApiDelegate.java @@ -45,7 +45,7 @@ public interface FakeClassnameTestApiDelegate { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { String exampleString = "{ \"client\" : \"client\" }"; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString); break; } } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApiDelegate.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApiDelegate.java index 4ec9c651dbe2..229023eaf285 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApiDelegate.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/PetApiDelegate.java @@ -84,12 +84,12 @@ public interface PetApiDelegate { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { 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\" } ]"; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString); break; } if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/xml"), exampleString); break; } } @@ -115,12 +115,12 @@ public interface PetApiDelegate { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { 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\" } ]"; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString); break; } if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/xml"), exampleString); break; } } @@ -145,12 +145,12 @@ public interface PetApiDelegate { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { 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\" }"; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString); break; } if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/xml"), exampleString); break; } } @@ -216,7 +216,7 @@ public interface PetApiDelegate { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { String exampleString = "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\" }"; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString); break; } } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApiDelegate.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApiDelegate.java index f35054a58867..c0164da1b0d1 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApiDelegate.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/StoreApiDelegate.java @@ -79,12 +79,12 @@ public interface StoreApiDelegate { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { 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\" }"; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString); break; } if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { String exampleString = " 123456789 123456789 123 2000-01-23T04:56:07.000Z aeiou true "; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/xml"), exampleString); break; } } @@ -108,12 +108,12 @@ public interface StoreApiDelegate { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { 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\" }"; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString); break; } if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { String exampleString = " 123456789 123456789 123 2000-01-23T04:56:07.000Z aeiou true "; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/xml"), exampleString); break; } } diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApiDelegate.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApiDelegate.java index 7b7a543c38af..f97dd8f3d9d3 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApiDelegate.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/api/UserApiDelegate.java @@ -113,12 +113,12 @@ public interface UserApiDelegate { for (MediaType mediaType : exchange.getRequest().getHeaders().getAccept()) { 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\" }"; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/json"), exampleString); break; } if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { String exampleString = " 123456789 aeiou aeiou aeiou aeiou aeiou aeiou 123 "; - result = ApiUtil.getExampleResponse(exchange, mediaType, exampleString); + result = ApiUtil.getExampleResponse(exchange, MediaType.valueOf("application/xml"), exampleString); break; } } diff --git a/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml index 98f0e7e6f9d0..ae88e043d50b 100644 --- a/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml @@ -1088,6 +1088,23 @@ paths: x-accepts: application/json x-tags: - 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: put: description: To test the collection format in query parameters diff --git a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/FakeApi.java index df8e4d9ab890..d85ccbd41334 100644 --- a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/api/FakeApi.java @@ -578,6 +578,44 @@ 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" } + ) + default ResponseEntity testWithResultExample( + + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "42"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/server/petstore/springboot-useoptional/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-useoptional/src/main/resources/openapi.yaml index 98f0e7e6f9d0..ae88e043d50b 100644 --- a/samples/server/petstore/springboot-useoptional/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-useoptional/src/main/resources/openapi.yaml @@ -1088,6 +1088,23 @@ paths: x-accepts: application/json x-tags: - 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: put: description: To test the collection format in query parameters diff --git a/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/api/FakeApi.java b/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/api/FakeApi.java index 2b6321ac51b3..bc983a82d151 100644 --- a/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/api/FakeApi.java +++ b/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/api/FakeApi.java @@ -602,6 +602,45 @@ public interface FakeApi { } + /** + * GET /fake/response-with-example + * This endpoint defines an example value for its response schema. + * + * @return Success (status code 200) + */ + @ApiVirtual + @Operation( + operationId = "testWithResultExample", + description = "This endpoint defines an example value for its response schema.", + tags = { "fake" }, + responses = { + @ApiResponse(responseCode = "200", description = "Success", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = Integer.class)) + }) + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/fake/response-with-example", + produces = { "application/json" } + ) + default ResponseEntity testWithResultExample( + + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "42"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/server/petstore/springboot-virtualan/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-virtualan/src/main/resources/openapi.yaml index 98f0e7e6f9d0..ae88e043d50b 100644 --- a/samples/server/petstore/springboot-virtualan/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-virtualan/src/main/resources/openapi.yaml @@ -1088,6 +1088,23 @@ paths: x-accepts: application/json x-tags: - 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: put: description: To test the collection format in query parameters diff --git a/samples/server/petstore/springboot/src/main/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/springboot/src/main/java/org/openapitools/api/FakeApi.java index 46d738f47b19..a536e7cadc27 100644 --- a/samples/server/petstore/springboot/src/main/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/springboot/src/main/java/org/openapitools/api/FakeApi.java @@ -578,6 +578,44 @@ 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" } + ) + default ResponseEntity testWithResultExample( + + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "42"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** * POST /fake/{petId}/uploadImageWithRequiredFile : uploads an image (required) * diff --git a/samples/server/petstore/springboot/src/main/resources/openapi.yaml b/samples/server/petstore/springboot/src/main/resources/openapi.yaml index 713de1249937..9d672d873dda 100644 --- a/samples/server/petstore/springboot/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot/src/main/resources/openapi.yaml @@ -1088,6 +1088,23 @@ paths: x-accepts: application/json x-tags: - 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: put: description: To test the collection format in query parameters