Skip to content

Commit

Permalink
[Java][Spring] fix EnumConverterConfiguration (#14356)
Browse files Browse the repository at this point in the history
  • Loading branch information
borsch authored Jan 5, 2023
1 parent cce3c96 commit ec9c7bd
Show file tree
Hide file tree
Showing 65 changed files with 7,681 additions and 145 deletions.
1 change: 1 addition & 0 deletions bin/configs/spring-boot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ additionalProperties:
snapshotVersion: "true"
hideGenerationTimestamp: "true"
camelCaseDollarSign: "true"
modelNameSuffix: 'Dto'
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package {{configPackage}};
{{#models}}
{{#model}}
{{#isEnum}}
import {{modelPackage}}.{{name}};
import {{modelPackage}}.{{classname}};
{{/isEnum}}
{{/model}}
{{/models}}
Expand All @@ -19,11 +19,11 @@ public class EnumConverterConfiguration {
{{#model}}
{{#isEnum}}
@Bean
Converter<{{{dataType}}}, {{name}}> {{classVarName}}Converter() {
return new Converter<{{{dataType}}}, {{name}}>() {
Converter<{{{dataType}}}, {{classname}}> {{classVarName}}Converter() {
return new Converter<{{{dataType}}}, {{classname}}>() {
@Override
public {{name}} convert({{{dataType}}} source) {
return {{name}}.fromValue(source);
public {{classname}} convert({{{dataType}}} source) {
return {{classname}}.fromValue(source);
}
};
}
Expand Down
96 changes: 48 additions & 48 deletions samples/server/petstore/springboot/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,54 @@ src/main/java/org/openapitools/api/UserApiController.java
src/main/java/org/openapitools/configuration/EnumConverterConfiguration.java
src/main/java/org/openapitools/configuration/HomeController.java
src/main/java/org/openapitools/configuration/SpringFoxConfiguration.java
src/main/java/org/openapitools/model/AdditionalPropertiesAnyType.java
src/main/java/org/openapitools/model/AdditionalPropertiesArray.java
src/main/java/org/openapitools/model/AdditionalPropertiesBoolean.java
src/main/java/org/openapitools/model/AdditionalPropertiesClass.java
src/main/java/org/openapitools/model/AdditionalPropertiesInteger.java
src/main/java/org/openapitools/model/AdditionalPropertiesNumber.java
src/main/java/org/openapitools/model/AdditionalPropertiesObject.java
src/main/java/org/openapitools/model/AdditionalPropertiesString.java
src/main/java/org/openapitools/model/Animal.java
src/main/java/org/openapitools/model/ArrayOfArrayOfNumberOnly.java
src/main/java/org/openapitools/model/ArrayOfNumberOnly.java
src/main/java/org/openapitools/model/ArrayTest.java
src/main/java/org/openapitools/model/BigCat.java
src/main/java/org/openapitools/model/BigCatAllOf.java
src/main/java/org/openapitools/model/Capitalization.java
src/main/java/org/openapitools/model/Cat.java
src/main/java/org/openapitools/model/CatAllOf.java
src/main/java/org/openapitools/model/Category.java
src/main/java/org/openapitools/model/ClassModel.java
src/main/java/org/openapitools/model/Client.java
src/main/java/org/openapitools/model/Dog.java
src/main/java/org/openapitools/model/DogAllOf.java
src/main/java/org/openapitools/model/EnumArrays.java
src/main/java/org/openapitools/model/EnumClass.java
src/main/java/org/openapitools/model/EnumTest.java
src/main/java/org/openapitools/model/File.java
src/main/java/org/openapitools/model/FileSchemaTestClass.java
src/main/java/org/openapitools/model/FormatTest.java
src/main/java/org/openapitools/model/HasOnlyReadOnly.java
src/main/java/org/openapitools/model/MapTest.java
src/main/java/org/openapitools/model/MixedPropertiesAndAdditionalPropertiesClass.java
src/main/java/org/openapitools/model/Model200Response.java
src/main/java/org/openapitools/model/ModelApiResponse.java
src/main/java/org/openapitools/model/ModelList.java
src/main/java/org/openapitools/model/ModelReturn.java
src/main/java/org/openapitools/model/Name.java
src/main/java/org/openapitools/model/NumberOnly.java
src/main/java/org/openapitools/model/Order.java
src/main/java/org/openapitools/model/OuterComposite.java
src/main/java/org/openapitools/model/OuterEnum.java
src/main/java/org/openapitools/model/Pet.java
src/main/java/org/openapitools/model/ReadOnlyFirst.java
src/main/java/org/openapitools/model/SpecialModelName.java
src/main/java/org/openapitools/model/Tag.java
src/main/java/org/openapitools/model/TypeHolderDefault.java
src/main/java/org/openapitools/model/TypeHolderExample.java
src/main/java/org/openapitools/model/User.java
src/main/java/org/openapitools/model/XmlItem.java
src/main/java/org/openapitools/model/AdditionalPropertiesAnyTypeDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesArrayDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesBooleanDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesClassDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesIntegerDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesNumberDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesObjectDto.java
src/main/java/org/openapitools/model/AdditionalPropertiesStringDto.java
src/main/java/org/openapitools/model/AnimalDto.java
src/main/java/org/openapitools/model/ApiResponseDto.java
src/main/java/org/openapitools/model/ArrayOfArrayOfNumberOnlyDto.java
src/main/java/org/openapitools/model/ArrayOfNumberOnlyDto.java
src/main/java/org/openapitools/model/ArrayTestDto.java
src/main/java/org/openapitools/model/BigCatAllOfDto.java
src/main/java/org/openapitools/model/BigCatDto.java
src/main/java/org/openapitools/model/CapitalizationDto.java
src/main/java/org/openapitools/model/CatAllOfDto.java
src/main/java/org/openapitools/model/CatDto.java
src/main/java/org/openapitools/model/CategoryDto.java
src/main/java/org/openapitools/model/ClassModelDto.java
src/main/java/org/openapitools/model/ClientDto.java
src/main/java/org/openapitools/model/DogAllOfDto.java
src/main/java/org/openapitools/model/DogDto.java
src/main/java/org/openapitools/model/EnumArraysDto.java
src/main/java/org/openapitools/model/EnumClassDto.java
src/main/java/org/openapitools/model/EnumTestDto.java
src/main/java/org/openapitools/model/FileDto.java
src/main/java/org/openapitools/model/FileSchemaTestClassDto.java
src/main/java/org/openapitools/model/FormatTestDto.java
src/main/java/org/openapitools/model/HasOnlyReadOnlyDto.java
src/main/java/org/openapitools/model/ListDto.java
src/main/java/org/openapitools/model/MapTestDto.java
src/main/java/org/openapitools/model/MixedPropertiesAndAdditionalPropertiesClassDto.java
src/main/java/org/openapitools/model/Model200ResponseDto.java
src/main/java/org/openapitools/model/NameDto.java
src/main/java/org/openapitools/model/NumberOnlyDto.java
src/main/java/org/openapitools/model/OrderDto.java
src/main/java/org/openapitools/model/OuterCompositeDto.java
src/main/java/org/openapitools/model/OuterEnumDto.java
src/main/java/org/openapitools/model/PetDto.java
src/main/java/org/openapitools/model/ReadOnlyFirstDto.java
src/main/java/org/openapitools/model/ReturnDto.java
src/main/java/org/openapitools/model/SpecialModelNameDto.java
src/main/java/org/openapitools/model/TagDto.java
src/main/java/org/openapitools/model/TypeHolderDefaultDto.java
src/main/java/org/openapitools/model/TypeHolderExampleDto.java
src/main/java/org/openapitools/model/UserDto.java
src/main/java/org/openapitools/model/XmlItemDto.java
src/main/resources/application.properties
src/main/resources/openapi.yaml
src/main/resources/static/swagger-ui.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
package org.openapitools.api;

import org.openapitools.model.Client;
import org.openapitools.model.ClientDto;
import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -43,19 +43,19 @@ default Optional<NativeWebRequest> getRequest() {
value = "To test special tags",
nickname = "call123testSpecialTags",
notes = "To test special tags and operation ID starting with number",
response = Client.class
response = ClientDto.class
)
@ApiResponses({
@ApiResponse(code = 200, message = "successful operation", response = Client.class)
@ApiResponse(code = 200, message = "successful operation", response = ClientDto.class)
})
@RequestMapping(
method = RequestMethod.PATCH,
value = "/another-fake/dummy",
produces = { "application/json" },
consumes = { "application/json" }
)
default ResponseEntity<Client> call123testSpecialTags(
@ApiParam(value = "client model", required = true) @Valid @RequestBody Client body
default ResponseEntity<ClientDto> call123testSpecialTags(
@ApiParam(value = "client model", required = true) @Valid @RequestBody ClientDto body
) {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.openapitools.api;

import org.openapitools.model.Client;
import org.openapitools.model.ClientDto;


import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
*/
package org.openapitools.api;

import org.openapitools.model.ApiResponseDto;
import java.math.BigDecimal;
import org.openapitools.model.Client;
import org.openapitools.model.ClientDto;
import org.springframework.format.annotation.DateTimeFormat;
import org.openapitools.model.FileSchemaTestClass;
import org.openapitools.model.FileSchemaTestClassDto;
import java.time.LocalDate;
import java.util.Map;
import org.openapitools.model.ModelApiResponse;
import java.time.OffsetDateTime;
import org.openapitools.model.OuterComposite;
import org.openapitools.model.User;
import org.openapitools.model.XmlItem;
import org.openapitools.model.OuterCompositeDto;
import org.openapitools.model.UserDto;
import org.openapitools.model.XmlItemDto;
import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -63,7 +63,7 @@ default Optional<NativeWebRequest> getRequest() {
consumes = { "application/xml", "application/xml; charset=utf-8", "application/xml; charset=utf-16", "text/xml", "text/xml; charset=utf-8", "text/xml; charset=utf-16" }
)
default ResponseEntity<Void> createXmlItem(
@ApiParam(value = "XmlItem Body", required = true) @Valid @RequestBody XmlItem xmlItem
@ApiParam(value = "XmlItem Body", required = true) @Valid @RequestBody XmlItemDto xmlItem
) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

Expand Down Expand Up @@ -112,18 +112,18 @@ default ResponseEntity<Boolean> fakeOuterBooleanSerialize(
value = "",
nickname = "fakeOuterCompositeSerialize",
notes = "Test serialization of object with outer number type",
response = OuterComposite.class
response = OuterCompositeDto.class
)
@ApiResponses({
@ApiResponse(code = 200, message = "Output composite", response = OuterComposite.class)
@ApiResponse(code = 200, message = "Output composite", response = OuterCompositeDto.class)
})
@RequestMapping(
method = RequestMethod.POST,
value = "/fake/outer/composite",
produces = { "*/*" }
)
default ResponseEntity<OuterComposite> fakeOuterCompositeSerialize(
@ApiParam(value = "Input composite as post body") @Valid @RequestBody(required = false) OuterComposite body
default ResponseEntity<OuterCompositeDto> fakeOuterCompositeSerialize(
@ApiParam(value = "Input composite as post body") @Valid @RequestBody(required = false) OuterCompositeDto body
) {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
Expand Down Expand Up @@ -221,7 +221,7 @@ default ResponseEntity<String> fakeOuterStringSerialize(
consumes = { "application/json" }
)
default ResponseEntity<Void> testBodyWithFileSchema(
@ApiParam(value = "", required = true) @Valid @RequestBody FileSchemaTestClass body
@ApiParam(value = "", required = true) @Valid @RequestBody FileSchemaTestClassDto body
) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

Expand Down Expand Up @@ -251,7 +251,7 @@ default ResponseEntity<Void> testBodyWithFileSchema(
)
default ResponseEntity<Void> testBodyWithQueryParams(
@NotNull @ApiParam(value = "", required = true) @Valid @RequestParam(value = "query", required = true) String query,
@ApiParam(value = "", required = true) @Valid @RequestBody User body
@ApiParam(value = "", required = true) @Valid @RequestBody UserDto body
) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

Expand All @@ -270,19 +270,19 @@ default ResponseEntity<Void> testBodyWithQueryParams(
value = "To test \"client\" model",
nickname = "testClientModel",
notes = "To test \"client\" model",
response = Client.class
response = ClientDto.class
)
@ApiResponses({
@ApiResponse(code = 200, message = "successful operation", response = Client.class)
@ApiResponse(code = 200, message = "successful operation", response = ClientDto.class)
})
@RequestMapping(
method = RequestMethod.PATCH,
value = "/fake",
produces = { "application/json" },
consumes = { "application/json" }
)
default ResponseEntity<Client> testClientModel(
@ApiParam(value = "client model", required = true) @Valid @RequestBody Client body
default ResponseEntity<ClientDto> testClientModel(
@ApiParam(value = "client model", required = true) @Valid @RequestBody ClientDto body
) {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
Expand Down Expand Up @@ -548,7 +548,7 @@ default ResponseEntity<Void> testQueryParameterCollectionFormat(
value = "uploads an image (required)",
nickname = "uploadFileWithRequiredFile",
notes = "",
response = ModelApiResponse.class,
response = ApiResponseDto.class,
authorizations = {
@Authorization(value = "petstore_auth", scopes = {
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
Expand All @@ -557,15 +557,15 @@ default ResponseEntity<Void> testQueryParameterCollectionFormat(
}
)
@ApiResponses({
@ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class)
@ApiResponse(code = 200, message = "successful operation", response = ApiResponseDto.class)
})
@RequestMapping(
method = RequestMethod.POST,
value = "/fake/{petId}/uploadImageWithRequiredFile",
produces = { "application/json" },
consumes = { "multipart/form-data" }
)
default ResponseEntity<ModelApiResponse> uploadFileWithRequiredFile(
default ResponseEntity<ApiResponseDto> uploadFileWithRequiredFile(
@ApiParam(value = "ID of pet to update", required = true) @PathVariable("petId") Long petId,
@ApiParam(value = "file to upload", required = true) @RequestPart(value = "requiredFile", required = true) MultipartFile requiredFile,
@ApiParam(value = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) String additionalMetadata
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.openapitools.api;

import org.openapitools.model.ApiResponseDto;
import java.math.BigDecimal;
import org.openapitools.model.Client;
import org.openapitools.model.ClientDto;
import org.springframework.format.annotation.DateTimeFormat;
import org.openapitools.model.FileSchemaTestClass;
import org.openapitools.model.FileSchemaTestClassDto;
import java.time.LocalDate;
import java.util.Map;
import org.openapitools.model.ModelApiResponse;
import java.time.OffsetDateTime;
import org.openapitools.model.OuterComposite;
import org.openapitools.model.User;
import org.openapitools.model.XmlItem;
import org.openapitools.model.OuterCompositeDto;
import org.openapitools.model.UserDto;
import org.openapitools.model.XmlItemDto;


import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
package org.openapitools.api;

import org.openapitools.model.Client;
import org.openapitools.model.ClientDto;
import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -43,22 +43,22 @@ default Optional<NativeWebRequest> getRequest() {
value = "To test class name in snake case",
nickname = "testClassname",
notes = "To test class name in snake case",
response = Client.class,
response = ClientDto.class,
authorizations = {
@Authorization(value = "api_key_query")
}
)
@ApiResponses({
@ApiResponse(code = 200, message = "successful operation", response = Client.class)
@ApiResponse(code = 200, message = "successful operation", response = ClientDto.class)
})
@RequestMapping(
method = RequestMethod.PATCH,
value = "/fake_classname_test",
produces = { "application/json" },
consumes = { "application/json" }
)
default ResponseEntity<Client> testClassname(
@ApiParam(value = "client model", required = true) @Valid @RequestBody Client body
default ResponseEntity<ClientDto> testClassname(
@ApiParam(value = "client model", required = true) @Valid @RequestBody ClientDto body
) {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.openapitools.api;

import org.openapitools.model.Client;
import org.openapitools.model.ClientDto;


import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Loading

0 comments on commit ec9c7bd

Please sign in to comment.