Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .github/workflows/samples-jdk17.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
- samples/client/petstore/java-helidon-client/v3/mp/**
- samples/client/petstore/java-helidon-client/v3/se/**
- samples/client/petstore/spring-http-interface-reactive/**
- samples/client/petstore/spring-http-interface-reactive-bean-validation/**
- samples/client/petstore/spring-http-interface-bean-validation/**
- samples/client/petstore/spring-http-interface/**
- samples/client/petstore/spring-http-interface-reactive-noResponseEntity/**
- samples/client/petstore/spring-http-interface-noResponseEntity/**
Expand All @@ -27,6 +29,8 @@ on:
- samples/client/petstore/java-helidon-client/v3/mp/**
- samples/client/petstore/java-helidon-client/v3/se/**
- samples/client/petstore/spring-http-interface-reactive/**
- samples/client/petstore/spring-http-interface-reactive-bean-validation/**
- samples/client/petstore/spring-http-interface-bean-validation/**
- samples/client/petstore/spring-http-interface/**
- samples/client/petstore/spring-http-interface-reactive-noResponseEntity/**
- samples/client/petstore/spring-http-interface-noResponseEntity/**
Expand All @@ -53,6 +57,8 @@ jobs:
- samples/client/petstore/java-helidon-client/v3/mp/
- samples/client/petstore/java-helidon-client/v3/se
- samples/client/petstore/spring-http-interface-reactive
- samples/client/petstore/spring-http-interface-reactive-bean-validation
- samples/client/petstore/spring-http-interface-bean-validation
- samples/client/petstore/spring-http-interface
- samples/client/petstore/spring-http-interface-reactive-noResponseEntity
- samples/client/petstore/spring-http-interface-noResponseEntity
Expand Down
18 changes: 18 additions & 0 deletions bin/configs/spring-http-interface-bean-validation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
generatorName: spring
library: spring-http-interface
outputDir: samples/client/petstore/spring-http-interface-bean-validation
inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
artifactId: spring-http-interface
snapshotVersion: "true"
hideGenerationTimestamp: "true"
modelNameSuffix: 'Dto'
generatedConstructorWithRequiredArgs: "false"
# validation should be respected
useBeanValidation: "true"
# documentation provider should be ignored
documentationProvider: "springdoc"
# annotation provider should be ignored
annotationLibrary: "swagger2"
useSpringBoot3: "true"
5 changes: 2 additions & 3 deletions bin/configs/spring-http-interface-noResponseEntity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ additionalProperties:
documentationProvider: "springdoc"
# annotation provider should be ignored
annotationLibrary: "swagger2"
# validation should be ignored
useBeanValidation: "true"
performBeanValidation: "true"
# useBeanValidation should default to "false" when not specified
# performBeanValidation should default to "false" when not specified
useResponseEntity: "false"
useSpringBoot3: "true"
17 changes: 17 additions & 0 deletions bin/configs/spring-http-interface-reactive-bean-validation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
generatorName: spring
library: spring-http-interface
outputDir: samples/client/petstore/spring-http-interface-reactive-bean-validation
inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
additionalProperties:
artifactId: spring-http-interface-reactive
snapshotVersion: "true"
hideGenerationTimestamp: "true"
reactive: "true"
# validation should be respected
useBeanValidation: "true"
# documentation provider should be ignored
documentationProvider: "springfox"
# annotation provider should be ignored
annotationLibrary: "swagger1"
useSpringBoot3: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ additionalProperties:
documentationProvider: "springfox"
# annotation provider should be ignored
annotationLibrary: "swagger1"
# validation should be ignored
useBeanValidation: "true"
performBeanValidation: "true"
# useBeanValidation should default to "false" when not specified
# performBeanValidation should default to "false" when not specified
useResponseEntity: "false"
useSpringBoot3: "true"

5 changes: 2 additions & 3 deletions bin/configs/spring-http-interface-reactive.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ additionalProperties:
documentationProvider: "springfox"
# annotation provider should be ignored
annotationLibrary: "swagger1"
# validation should be ignored
useBeanValidation: "true"
performBeanValidation: "true"
# useBeanValidation should default to "false" when not specified
# performBeanValidation should default to "false" when not specified
useSpringBoot3: "true"

1 change: 0 additions & 1 deletion bin/configs/spring-http-interface-springboot-4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ additionalProperties:
documentationProvider: "springdoc"
# annotation provider should be ignored
annotationLibrary: "swagger2"
# validation should be ignored
useBeanValidation: "true"
performBeanValidation: "true"
useSpringBoot4: "true"
Expand Down
5 changes: 2 additions & 3 deletions bin/configs/spring-http-interface.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ additionalProperties:
documentationProvider: "springdoc"
# annotation provider should be ignored
annotationLibrary: "swagger2"
# validation should be ignored
useBeanValidation: "true"
performBeanValidation: "true"
# useBeanValidation should default to "false" when not specified
# performBeanValidation should default to "false" when not specified
useSpringBoot3: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import static org.openapitools.codegen.CodegenConstants.X_DISCRIMINATOR_VALUE;
import static org.openapitools.codegen.CodegenConstants.X_IMPLEMENTS;
import static org.openapitools.codegen.utils.CamelizeOption.*;
import static org.openapitools.codegen.utils.ModelUtils.getSchemaItems;
Expand Down Expand Up @@ -802,6 +803,23 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
}
}

// Propagate the parent's discriminator mapping key to each child model's vendorExtensions
// as x-discriminator-value, so that @JsonTypeName on the child matches the parent's
// @JsonSubTypes name when an explicit discriminator mapping renames the key
// (e.g. "child_a" instead of the schema name "ChildWithMappingA").
// putIfAbsent preserves any value the user has already set explicitly in the spec.
for (CodegenModel cm : allModels.values()) {
if (cm.getParentModel() == null || cm.getParentModel().getDiscriminator() == null) {
continue;
}
for (CodegenDiscriminator.MappedModel mm : cm.getParentModel().getDiscriminator().getMappedModels()) {
if (mm.getModelName().equals(cm.classname)) {
cm.vendorExtensions.putIfAbsent(X_DISCRIMINATOR_VALUE, mm.getMappingName());
break;
}
}
}

return objs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,18 @@ public void processOpts() {
documentationProvider = DocumentationProvider.NONE;
annotationLibrary = AnnotationLibrary.NONE;
useJakartaEe = true;
useBeanValidation = false;
performBeanValidation = false;
if(additionalProperties.containsKey(USE_BEANVALIDATION)) {
useBeanValidation = convertPropertyToBoolean(USE_BEANVALIDATION);
} else {
//default to false if not specified
useBeanValidation = false;
}
if(additionalProperties.containsKey(PERFORM_BEANVALIDATION)) {
performBeanValidation = convertPropertyToBoolean(PERFORM_BEANVALIDATION);
} else {
//default to false if not specified
performBeanValidation = false;
}

additionalProperties.put(USE_JAKARTA_EE, useJakartaEe);
additionalProperties.put(USE_BEANVALIDATION, useBeanValidation);
Expand All @@ -443,8 +453,7 @@ public void processOpts() {

applyJakartaPackage();

LOGGER.warn("For Spring HTTP Interface following options are disabled: documentProvider, annotationLibrary, useBeanValidation, performBeanValidation. "
+ "useJakartaEe defaulted to 'true'");
LOGGER.warn("For Spring HTTP Interface following options are disabled: documentProvider, annotationLibrary. useJakartaEe defaulted to 'true'");
}

if (DocumentationProvider.SPRINGFOX.equals(getDocumentationProvider())) {
Expand Down Expand Up @@ -654,7 +663,6 @@ public void processOpts() {

supportingFiles.add(new SupportingFile(httpInterfacesAbstractConfiguratorFile,
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HttpInterfacesAbstractConfigurator.java"));
writePropertyBack(USE_BEANVALIDATION, false);

writePropertyBack(HTTP_INTERFACES_CONFIGURATOR_DEPENDENCY,
useHttpServiceProxyFactoryInterfacesConfigurator ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.service.annotation.*;
import org.springframework.web.multipart.MultipartFile;
{{#useBeanValidation}}
import {{javaxPackage}}.validation.Valid;
import {{javaxPackage}}.validation.constraints.*;
{{^useSpringBuiltInValidation}}import org.springframework.validation.annotation.Validated;{{/useSpringBuiltInValidation}}
{{/useBeanValidation}}
{{#reactive}}

import org.springframework.http.codec.multipart.Part;
Expand All @@ -29,6 +34,7 @@ import java.util.Optional;
import {{javaxPackage}}.annotation.Generated;


{{#useBeanValidation}}{{^useSpringBuiltInValidation}}@Validated{{/useSpringBuiltInValidation}}{{/useBeanValidation}}
{{>generatedAnnotation}}

{{#operations}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@
<optional>true</optional>
</dependency>
{{/lombok}}
{{#useBeanValidation}}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
{{/useBeanValidation}}
{{^useBeanValidation}}{{#performBeanValidation}}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
{{/performBeanValidation}}{{/useBeanValidation}}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@
<optional>true</optional>
</dependency>
{{/lombok}}
{{#useBeanValidation}}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
{{/useBeanValidation}}
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
{{^useBeanValidation}}{{#performBeanValidation}}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
{{/performBeanValidation}}{{/useBeanValidation}}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-{{#reactive}}web{{/reactive}}{{^reactive}}rest{{/reactive}}client-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
{{/discriminator}}
{{#jackson}}
{{#isClassnameSanitized}}
{{#parent}}
@JsonTypeName("{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}")
{{/parent}}
{{^parent}}
{{^hasDiscriminatorWithNonEmptyMapping}}
@JsonTypeName("{{name}}")
{{/hasDiscriminatorWithNonEmptyMapping}}
{{/parent}}
{{/isClassnameSanitized}}
{{/jackson}}
{{#withXml}}
Expand Down Expand Up @@ -65,7 +70,6 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
@Deprecated
{{/deprecated}}
{{#isContainer}}
{{#useBeanValidation}}@Valid{{/useBeanValidation}}
{{#openApiNullable}}
private {{>nullableAnnotation}}{{#isNullable}}{{>nullableDataTypeBeanValidation}} {{name}} = JsonNullable.<{{{datatypeWithEnum}}}>undefined();{{/isNullable}}{{^required}}{{^isNullable}}{{>nullableDataTypeBeanValidation}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};{{/isNullable}}{{/required}}{{#required}}{{^isNullable}}{{>nullableDataTypeBeanValidation}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};{{/isNullable}}{{/required}}
{{/openApiNullable}}
Expand Down Expand Up @@ -157,7 +161,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}

public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
{{#openApiNullable}}
if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent(){{/isNullable}}) {
if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent() || this.{{name}}.get() == null{{/isNullable}}) {
this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}{{#isNullable}}){{/isNullable}};
}
this.{{name}}{{#isNullable}}.get(){{/isNullable}}.add({{name}}Item);
Expand All @@ -175,7 +179,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}

public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
{{#openApiNullable}}
if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent(){{/isNullable}}) {
if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent() || this.{{name}}.get() == null{{/isNullable}}) {
this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}HashMap{{/uniqueItems}}<>(){{/defaultValue}}{{#isNullable}}){{/isNullable}};
}
this.{{name}}{{#isNullable}}.get(){{/isNullable}}.put(key, {{name}}Item);
Expand Down
Loading
Loading