Skip to content

Commit 1b55779

Browse files
authored
[kotlin-spring][server] Feat: Return from controllers without ResponseEntity wrapper. (#22377)
* remove "async" and "responseWrapper" from template as these are not supported by kotlin-spring generator * try to force pipelines rerun * force pipelines rerun * fix mustache to keep generated code identical * Revert "fix mustache to keep generated code identical" This reverts commit c573b43. * Reapply "fix mustache to keep generated code identical" This reverts commit 2c3b065. * Add support for 'useResponseEntity' in kotlin-spring. Consolidate with the separate flag 'declarativeInterfaceWrapResponses' as these can now be controlled both by one flag. Default to true. * fix status annotation and add compile-test samples * satisfy samples-up-to-date check * add unit tests covering both reactive and non-reactive * fix template to avoid unnecessary empty line * fix template to avoid unnecessary empty line * put method params (if present) on separate lines to improve readability * put method params (if present) on separate lines to improve readability; fix double spaces, spaces before comma, incorrect spaces * fix test * store PATHs as accesible strings in companion objects. * fix missing import * fix incorrect import * fix fallback to nested placeholders.
1 parent 3d6e9d5 commit 1b55779

File tree

202 files changed

+9390
-1271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+9390
-1271
lines changed

.github/workflows/samples-kotlin-server-jdk17.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
# server
3737
- samples/server/petstore/kotlin-server-required-and-nullable-properties
3838
- samples/server/petstore/kotlin-springboot-3
39+
- samples/server/petstore/kotlin-springboot-3-no-response-entity
3940
- samples/server/petstore/kotlin-springboot-additionalproperties
4041
- samples/server/petstore/kotlin-springboot-delegate-nodefaults
4142
- samples/server/petstore/kotlin-springboot-request-cookie

.github/workflows/samples-kotlin-server.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
sample:
3030
# server
3131
- samples/server/petstore/kotlin-springboot
32+
- samples/server/petstore/kotlin-springboot-no-response-entity
33+
- samples/server/petstore/kotlin-springboot-no-response-entity-delegate
3234
- samples/server/petstore/kotlin-springboot-multipart-request-model
3335
- samples/server/petstore/kotlin-springboot-bigdecimal-default
3436
- samples/server/petstore/kotlin-springboot-delegate
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
generatorName: kotlin-spring
2+
outputDir: samples/server/petstore/kotlin-springboot-3-no-response-entity
3+
library: spring-boot
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
6+
additionalProperties:
7+
documentationProvider: none
8+
annotationLibrary: none
9+
useSwaggerUI: "false"
10+
serviceImplementation: "true"
11+
serializableModel: "true"
12+
beanValidations: "true"
13+
useSpringBoot3: "true"
14+
requestMappingMode: api_interface
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
generatorName: kotlin-spring
2+
outputDir: samples/server/petstore/kotlin-springboot-no-response-entity-delegate
3+
library: spring-boot
4+
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
6+
additionalProperties:
7+
documentationProvider: none
8+
annotationLibrary: none
9+
useSwaggerUI: "false"
10+
serviceImplementation: "true"
11+
serializableModel: "true"
12+
beanValidations: "true"
13+
useResponseEntity: "false"
14+
delegatePattern: true
15+
requestMappingMode: controller
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
generatorName: kotlin-spring
2+
outputDir: samples/server/petstore/kotlin-springboot-no-response-entity
3+
library: spring-boot
4+
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
6+
additionalProperties:
7+
documentationProvider: none
8+
annotationLibrary: none
9+
useSwaggerUI: "false"
10+
serviceImplementation: "true"
11+
serializableModel: "true"
12+
beanValidations: "true"
13+
useResponseEntity: "false"
14+
requestMappingMode: controller

bin/configs/kotlin-spring-declarative-interface-reactive-coroutines.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ additionalProperties:
1111
beanValidations: "true"
1212
interfaceOnly: true
1313
reactive: true
14-
declarativeInterfaceWrapResponses: false
14+
useResponseEntity: false
1515
useFlowForArrayReturnType: false
1616
declarativeInterfaceReactiveMode: "coroutines"

bin/configs/kotlin-spring-declarative-interface-reactive-reactor-wrapped.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ additionalProperties:
1111
beanValidations: "true"
1212
interfaceOnly: true
1313
reactive: true
14-
declarativeInterfaceWrapResponses: true
14+
useResponseEntity: true
1515
useFlowForArrayReturnType: false
1616
declarativeInterfaceReactiveMode: "reactor"

bin/configs/kotlin-spring-declarative-interface-wrapped.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ additionalProperties:
1111
beanValidations: "true"
1212
interfaceOnly: true
1313
reactive: false
14-
declarativeInterfaceWrapResponses: true
14+
useResponseEntity: true
1515
useFlowForArrayReturnType: false

bin/configs/kotlin-spring-declarative-interface.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ additionalProperties:
1111
beanValidations: "true"
1212
interfaceOnly: true
1313
reactive: false
14-
declarativeInterfaceWrapResponses: true
14+
useResponseEntity: true
1515
useFlowForArrayReturnType: false

docs/generators/kotlin-spring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2828
|beanQualifiers|Whether to add fully-qualifier class names as bean qualifiers in @Component and @RestController annotations. May be used to prevent bean names clash if multiple generated libraries (contexts) added to single project.| |false|
2929
|configPackage|configuration package for generated code| |org.openapitools.configuration|
3030
|declarativeInterfaceReactiveMode|What type of reactive style to use in Spring Http declarative interface|<dl><dt>**coroutines**</dt><dd>Use kotlin-idiomatic 'suspend' functions</dd><dt>**reactor**</dt><dd>Use reactor return wrappers 'Mono' and 'Flux'</dd></dl>|coroutines|
31-
|declarativeInterfaceWrapResponses|Whether (when false) to return actual type (e.g. List&lt;Fruit&gt;) and handle non 2xx responses via exceptions or (when true) return entire ResponseEntity (e.g. ResponseEntity&lt;List&lt;Fruit&gt;&gt;)| |false|
3231
|delegatePattern|Whether to generate the server files using the delegate pattern| |false|
3332
|documentationProvider|Select the OpenAPI documentation provider.|<dl><dt>**none**</dt><dd>Do not publish an OpenAPI specification.</dd><dt>**source**</dt><dd>Publish the original input OpenAPI specification.</dd><dt>**springfox**</dt><dd>Generate an OpenAPI 2 (fka Swagger RESTful API Documentation Specification) specification using SpringFox 2.x. Deprecated (for removal); use springdoc instead.</dd><dt>**springdoc**</dt><dd>Generate an OpenAPI 3 specification using SpringDoc.</dd></dl>|springdoc|
3433
|enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |original|
@@ -56,6 +55,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5655
|useBeanValidation|Use BeanValidation API annotations to validate data types| |true|
5756
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
5857
|useFlowForArrayReturnType|Whether to use Flow for array/collection return types when reactive is enabled. If false, will use List instead.| |true|
58+
|useResponseEntity|Whether (when false) to return actual type (e.g. List&lt;Fruit&gt;) and handle non-happy path responses via exceptions flow or (when true) return entire ResponseEntity (e.g. ResponseEntity&lt;List&lt;Fruit&gt;&gt;). If disabled, method are annotated using a @ResponseStatus annotation, which has the status of the first response declared in the Api definition| |true|
5959
|useSpringBoot3|Generate code and provide dependencies for use with Spring Boot 3.x. (Use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.| |false|
6060
|useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true|
6161
|useTags|Whether to use tags for creating interface and controller class names| |false|

0 commit comments

Comments
 (0)