Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions .github/workflows/samples-spring-jdk17.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ name: Samples Java Spring (JDK17)
on:
push:
paths:
- samples/openapi3/client/petstore/spring-cloud-3-with-optional
- samples/openapi3/client/petstore/spring-cloud-4-with-optional
- samples/client/petstore/spring-http-interface-springboot-4
- samples/openapi3/server/petstore/springboot-3
- samples/openapi3/server/petstore/springboot-4
- samples/server/petstore/springboot-api-response-examples
- samples/server/petstore/springboot-lombok-data
- samples/server/petstore/springboot-lombok-tostring
- samples/server/petstore/springboot-file-delegate-optional
- samples/server/petstore/springboot-petstore-with-api-response-examples
- samples/server/petstore/spring-boot-oneof-sealed
- samples/openapi3/server/petstore/spring-boot-oneof-interface
- samples/openapi3/client/petstore/spring-cloud-3-with-optional/**
- samples/openapi3/client/petstore/spring-cloud-4-with-optional/**
- samples/client/petstore/spring-http-interface-springboot-4/**
- samples/openapi3/server/petstore/springboot-3/**
- samples/openapi3/server/petstore/springboot-4/**
- samples/server/petstore/springboot-api-response-examples/**
- samples/server/petstore/springboot-lombok-data/**
- samples/server/petstore/springboot-lombok-tostring/**
- samples/server/petstore/springboot-file-delegate-optional/**
- samples/server/petstore/springboot-petstore-with-api-response-examples/**
- samples/openapi3/server/petstore/spring-boot-oneof-sealed/**
- samples/openapi3/server/petstore/spring-boot-oneof-interface/**
pull_request:
paths:
- samples/openapi3/client/petstore/spring-cloud-3-with-optional
- samples/openapi3/client/petstore/spring-cloud-4-with-optional
- samples/client/petstore/spring-http-interface-springboot-4
- samples/openapi3/server/petstore/springboot-3
- samples/openapi3/server/petstore/springboot-4
- samples/server/petstore/springboot-api-response-examples
- samples/server/petstore/springboot-lombok-data
- samples/server/petstore/springboot-lombok-tostring
- samples/server/petstore/springboot-file-delegate-optional
- samples/server/petstore/springboot-petstore-with-api-response-examples
- samples/server/petstore/spring-boot-oneof-sealed
- samples/openapi3/server/petstore/spring-boot-oneof-interface
- samples/openapi3/client/petstore/spring-cloud-3-with-optional/**
- samples/openapi3/client/petstore/spring-cloud-4-with-optional/**
- samples/client/petstore/spring-http-interface-springboot-4/**
- samples/openapi3/server/petstore/springboot-3/**
- samples/openapi3/server/petstore/springboot-4/**
- samples/server/petstore/springboot-api-response-examples/**
- samples/server/petstore/springboot-lombok-data/**
- samples/server/petstore/springboot-lombok-tostring/**
- samples/server/petstore/springboot-file-delegate-optional/**
- samples/server/petstore/springboot-petstore-with-api-response-examples/**
- samples/openapi3/server/petstore/spring-boot-oneof-sealed/**
- samples/openapi3/server/petstore/spring-boot-oneof-interface/**
jobs:
build:
name: Build Java Spring (JDK17)
Expand All @@ -49,7 +49,7 @@ jobs:
- samples/server/petstore/springboot-lombok-tostring
- samples/server/petstore/springboot-file-delegate-optional
- samples/server/petstore/springboot-petstore-with-api-response-examples
- samples/server/petstore/spring-boot-oneof-sealed
- samples/openapi3/server/petstore/spring-boot-oneof-sealed
- samples/openapi3/server/petstore/spring-boot-oneof-interface
steps:
- uses: actions/checkout@v5
Expand Down
3 changes: 2 additions & 1 deletion bin/configs/spring-boot-x-implements-skip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ outputDir: samples/server/petstore/springboot-x-implements-skip
inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing-x-implements.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
additionalNotNullAnnotations: true
documentationProvider: springfox
artifactId: springboot
snapshotVersion: "true"
Expand All @@ -12,4 +13,4 @@ additionalProperties:
xImplementsSkip: [ com.custompackage.InterfaceToSkip ]
schemaImplements:
Foo: [ com.custompackage.WithBar, com.custompackage.WithDefaultMethod ]
Animal: com.custompackage.WithColor
Animal: com.custompackage.WithColor
1 change: 1 addition & 0 deletions docs/generators/java-camel.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| ------ | ----------- | ------ | ------- |
|additionalEnumTypeAnnotations|Additional annotations for enum type(class level annotations)| |null|
|additionalModelTypeAnnotations|Additional annotations for model type(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null|
|additionalNotNullAnnotations|Add @NotNull to path variables (required by default) and requestBody.| |false|
|additionalOneOfTypeAnnotations|Additional annotations for oneOf interfaces(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null|
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|annotationLibrary|Select the complementary documentation annotation library.|<dl><dt>**none**</dt><dd>Do not annotate Model and Api with complementary annotations.</dd><dt>**swagger1**</dt><dd>Annotate Model and Api using the Swagger Annotations 1.x library.</dd><dt>**swagger2**</dt><dd>Annotate Model and Api using the Swagger Annotations 2.x library.</dd></dl>|swagger2|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| ------ | ----------- | ------ | ------- |
|additionalEnumTypeAnnotations|Additional annotations for enum type(class level annotations)| |null|
|additionalModelTypeAnnotations|Additional annotations for model type(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null|
|additionalNotNullAnnotations|Add @NotNull to path variables (required by default) and requestBody.| |false|
|additionalOneOfTypeAnnotations|Additional annotations for oneOf interfaces(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null|
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|annotationLibrary|Select the complementary documentation annotation library.|<dl><dt>**none**</dt><dd>Do not annotate Model and Api with complementary annotations.</dd><dt>**swagger1**</dt><dd>Annotate Model and Api using the Swagger Annotations 1.x library.</dd><dt>**swagger2**</dt><dd>Annotate Model and Api using the Swagger Annotations 2.x library.</dd></dl>|swagger2|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class SpringCodegen extends AbstractJavaCodegen
public static final String JACKSON2_PACKAGE = "com.fasterxml.jackson";
public static final String JACKSON3_PACKAGE = "tools.jackson";
public static final String JACKSON_PACKAGE = "jacksonPackage";
public static final String ADDITIONAL_NOT_NULL_ANNOTATIONS = "additionalNotNullAnnotations";

@Getter
public enum RequestMappingMode {
Expand Down Expand Up @@ -180,6 +181,8 @@ public enum RequestMappingMode {
protected boolean useDeductionForOneOfInterfaces = false;
@Getter @Setter
protected boolean useJackson3 = false;
@Getter @Setter
protected boolean additionalNotNullAnnotations = false;

public SpringCodegen() {
super();
Expand Down Expand Up @@ -269,7 +272,6 @@ public SpringCodegen() {
cliOptions.add(CliOption.newString(X_IMPLEMENTS_SKIP, "Ability to choose interfaces that should NOT be implemented in the models despite their presence in vendor extension `x-implements`. Takes a list of fully qualified interface names. Example: yaml `xImplementsSkip: [com.some.pack.WithPhotoUrls]` skips implementing the interface `com.some.pack.WithPhotoUrls` in any schema", "empty list"));
cliOptions.add(CliOption.newString(SCHEMA_IMPLEMENTS, "Ability to supply interfaces per schema that should be implemented (serves similar purpose as vendor extension `x-implements`, but is fully decoupled from the api spec). Example: yaml `schemaImplements: {Pet: com.some.pack.WithId, Category: [com.some.pack.CategoryInterface], Dog: [com.some.pack.Canine, com.some.pack.OtherInterface]}` implements interfaces in schemas `Pet` (interface `com.some.pack.WithId`), `Category` (interface `com.some.pack.CategoryInterface`), `Dog`(interfaces `com.some.pack.Canine`, `com.some.pack.OtherInterface`)", "empty map"));


CliOption requestMappingOpt = new CliOption(REQUEST_MAPPING_OPTION,
"Where to generate the class level @RequestMapping annotation.")
.defaultValue(requestMappingMode.name());
Expand Down Expand Up @@ -325,6 +327,10 @@ public SpringCodegen() {
library.setEnum(supportedLibraries);
cliOptions.add(library);

cliOptions.add(CliOption.newBoolean(ADDITIONAL_NOT_NULL_ANNOTATIONS,
"Add @NotNull to path variables (required by default) and requestBody.",
additionalNotNullAnnotations));

}

@Override
Expand Down Expand Up @@ -532,6 +538,7 @@ public void processOpts() {
}
convertPropertyToStringAndWriteBack(RESOURCE_FOLDER, this::setResourceFolder);

convertPropertyToBooleanAndWriteBack(ADDITIONAL_NOT_NULL_ANNOTATIONS, this::setAdditionalNotNullAnnotations);

// override parent one
importMapping.put("JsonDeserialize", (useJackson3 ? JACKSON3_PACKAGE : JACKSON2_PACKAGE) + ".databind.annotation.JsonDeserialize");
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{^useOptional}}{{#required}}@NotNull {{/required}}{{>beanValidationCore}}{{/useOptional}}{{#useOptional}}{{#required}}{{>beanValidationCore}}{{/required}}{{/useOptional}}
{{^useOptional}}{{#additionalNotNullAnnotations}}{{#required}}@NotNull {{/required}}{{/additionalNotNullAnnotations}}{{>beanValidationCore}}{{/useOptional}}{{#useOptional}}{{#required}}{{>beanValidationCore}}{{/required}}{{/useOptional}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{! PathParam is always required }}@NotNull {{>beanValidationCore}}
{{! PathParam is always required }}{{#additionalNotNullAnnotations}}@NotNull {{/additionalNotNullAnnotations}}{{>beanValidationCore}}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public interface DefaultApi {
value = DefaultApi.PATH_GET
)
ResponseEntity<Void> get(
@NotNull @ApiParam(value = "A date path parameter", required = true, defaultValue = "1972-01-01") @PathVariable("date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date,
@ApiParam(value = "A date path parameter", required = true, defaultValue = "1972-01-01") @PathVariable("date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date,
@NotNull @ApiParam(value = "A date-time query parameter", required = true, defaultValue = "1973-12-19T03:39:57-08:00") @Valid @RequestParam(value = "dateTime", required = true, defaultValue = "1973-12-19T03:39:57-08:00") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime dateTime,
@NotNull @ApiParam(value = "A date header parameter", required = true, defaultValue = "1974-01-01") @RequestHeader(value = "X-Order-Date", required = true, defaultValue = "1974-01-01") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate xOrderDate,
@ApiParam(value = "A date cookie parameter", defaultValue = "1975-01-01") @CookieValue(name = "loginDate", required = false, defaultValue = "1975-01-01") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate loginDate
Expand Down Expand Up @@ -80,7 +80,7 @@ ResponseEntity<Void> get(
consumes = "application/x-www-form-urlencoded"
)
ResponseEntity<Void> updatePetWithForm(
@NotNull @ApiParam(value = "A date path parameter", required = true, defaultValue = "1970-01-01") @PathVariable("date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date,
@ApiParam(value = "A date path parameter", required = true, defaultValue = "1970-01-01") @PathVariable("date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date,
@ApiParam(value = "Updated last visit timestamp", defaultValue = "1971-12-19T03:39:57-08:00") @Valid @RequestParam(value = "visitDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime visitDate
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface PetApi {
consumes = "application/json"
)
ResponseEntity<Void> addPet(
@Parameter(name = "Pet", description = "Pet object that needs to be added to the store", required = true) @NotNull @Valid @RequestBody Pet pet
@Parameter(name = "Pet", description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody Pet pet
);


Expand Down Expand Up @@ -93,7 +93,7 @@ ResponseEntity<Void> addPet(
value = PetApi.PATH_DELETE_PET
)
ResponseEntity<Void> deletePet(
@NotNull @Parameter(name = "petId", description = "Pet id to delete", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId,
@Parameter(name = "petId", description = "Pet id to delete", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId,
@Parameter(name = "api_key", description = "", in = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) @Nullable String apiKey
);

Expand Down Expand Up @@ -204,7 +204,7 @@ ResponseEntity<List<Pet>> findPetsByTags(
produces = { "application/json", "application/xml" }
)
ResponseEntity<Pet> getPetById(
@NotNull @Parameter(name = "petId", deprecated = true, description = "ID of pet to return", required = true, in = ParameterIn.PATH) @PathVariable("petId") @Deprecated Long petId
@Parameter(name = "petId", deprecated = true, description = "ID of pet to return", required = true, in = ParameterIn.PATH) @PathVariable("petId") @Deprecated Long petId
);


Expand Down Expand Up @@ -238,7 +238,7 @@ ResponseEntity<Pet> getPetById(
consumes = "application/json"
)
ResponseEntity<Void> updatePet(
@Parameter(name = "Pet", description = "Pet object that needs to be added to the store", required = true) @NotNull @Valid @RequestBody Pet pet
@Parameter(name = "Pet", description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody Pet pet
);


Expand Down Expand Up @@ -270,7 +270,7 @@ ResponseEntity<Void> updatePet(
consumes = "application/x-www-form-urlencoded"
)
ResponseEntity<Void> updatePetWithForm(
@NotNull @Parameter(name = "petId", description = "ID of pet that needs to be updated", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId,
@Parameter(name = "petId", description = "ID of pet that needs to be updated", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId,
@Parameter(name = "name", description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) String name,
@Parameter(name = "status", description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) String status
);
Expand Down Expand Up @@ -307,7 +307,7 @@ ResponseEntity<Void> updatePetWithForm(
consumes = "multipart/form-data"
)
ResponseEntity<ModelApiResponse> uploadFile(
@NotNull @Parameter(name = "petId", description = "ID of pet to update", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId,
@Parameter(name = "petId", description = "ID of pet to update", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId,
@Parameter(name = "additionalMetadata", description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) String additionalMetadata,
@Parameter(name = "file", description = "file to upload") @RequestPart(value = "file", required = false) MultipartFile file
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public interface StoreApi {
value = StoreApi.PATH_DELETE_ORDER
)
ResponseEntity<Void> deleteOrder(
@NotNull @Parameter(name = "orderId", description = "ID of the order that needs to be deleted", required = true, in = ParameterIn.PATH) @PathVariable("orderId") String orderId
@Parameter(name = "orderId", description = "ID of the order that needs to be deleted", required = true, in = ParameterIn.PATH) @PathVariable("orderId") String orderId
);


Expand Down Expand Up @@ -125,7 +125,7 @@ ResponseEntity<Map<String, Integer>> getInventory(
produces = { "application/json", "application/xml" }
)
ResponseEntity<Order> getOrderById(
@NotNull @Min(value = 1L) @Max(value = 5L) @Parameter(name = "orderId", description = "ID of pet that needs to be fetched", required = true, in = ParameterIn.PATH) @PathVariable("orderId") Long orderId
@Min(value = 1L) @Max(value = 5L) @Parameter(name = "orderId", description = "ID of pet that needs to be fetched", required = true, in = ParameterIn.PATH) @PathVariable("orderId") Long orderId
);


Expand Down Expand Up @@ -158,7 +158,7 @@ ResponseEntity<Order> getOrderById(
consumes = "application/json"
)
ResponseEntity<Order> placeOrder(
@Parameter(name = "Order", description = "order placed for purchasing the pet", required = true) @NotNull @Valid @RequestBody Order order
@Parameter(name = "Order", description = "order placed for purchasing the pet", required = true) @Valid @RequestBody Order order
);

}
Loading
Loading