diff --git a/docs/generators/groovy.md b/docs/generators/groovy.md index e2f1314c4bb1..4c3951b997a5 100644 --- a/docs/generators/groovy.md +++ b/docs/generators/groovy.md @@ -69,6 +69,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| |useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| + ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-camel.md b/docs/generators/java-camel.md index b50d9b4728c1..b51c1cb4a312 100644 --- a/docs/generators/java-camel.md +++ b/docs/generators/java-camel.md @@ -116,6 +116,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useTags|use tags for creating interface and controller classnames| |false| |virtualService|Generates the virtual service. For more details refer - https://github.com/virtualansoftware/virtualan/wiki| |false| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-dubbo.md b/docs/generators/java-dubbo.md index fa64f3d35955..f4bf3fdadba7 100644 --- a/docs/generators/java-dubbo.md +++ b/docs/generators/java-dubbo.md @@ -82,6 +82,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false| |useTags|use tags for creating interface and controller classnames| |true| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-helidon-client.md b/docs/generators/java-helidon-client.md index 5f309c81ce6b..261c45b629e6 100644 --- a/docs/generators/java-helidon-client.md +++ b/docs/generators/java-helidon-client.md @@ -68,6 +68,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| |x-helidon-groupBy|Selects how to group operations into APIs|
**tags**
Use the 'tags' settings on each operation
**first-path-segment**
Use the first segment of the path
|tags| |x-helidon-useOptional|Wrap optional parameters in an Optional (Helidon 4 and later)| |true| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-helidon-server.md b/docs/generators/java-helidon-server.md index b4d8db132743..fb08abb6065c 100644 --- a/docs/generators/java-helidon-server.md +++ b/docs/generators/java-helidon-server.md @@ -71,6 +71,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| |x-helidon-groupBy|Selects how to group operations into APIs|
**tags**
Use the 'tags' settings on each operation
**first-path-segment**
Use the first segment of the path
|tags| |x-helidon-useOptional|Wrap optional parameters in an Optional (Helidon 4 and later)| |true| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-inflector.md b/docs/generators/java-inflector.md index 3adfffad38df..b62f77b35b48 100644 --- a/docs/generators/java-inflector.md +++ b/docs/generators/java-inflector.md @@ -71,6 +71,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| |useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-micronaut-client.md b/docs/generators/java-micronaut-client.md index 37a2d8907ee1..963e6a1214a1 100644 --- a/docs/generators/java-micronaut-client.md +++ b/docs/generators/java-micronaut-client.md @@ -92,6 +92,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |visitable|Generate visitor for subtypes with a discriminator| |false| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| |wrapInHttpResponse|Wrap the response in HttpResponse object| |false| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-micronaut-server.md b/docs/generators/java-micronaut-server.md index 4a21268afbd5..16cf16a74ae6 100644 --- a/docs/generators/java-micronaut-server.md +++ b/docs/generators/java-micronaut-server.md @@ -91,6 +91,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |visitable|Generate visitor for subtypes with a discriminator| |false| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| |wrapInHttpResponse|Wrap the response in HttpResponse object| |false| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-microprofile.md b/docs/generators/java-microprofile.md index 9e02b37145ef..203016f8a240 100644 --- a/docs/generators/java-microprofile.md +++ b/docs/generators/java-microprofile.md @@ -109,6 +109,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |webclientBlockingOperations|Making all WebClient operations blocking(sync). Note that if on operation 'x-webclient-blocking: false' then such operation won't be sync| |false| |withAWSV4Signature|whether to include AWS v4 signature support (only available for okhttp-gson library)| |false| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-msf4j.md b/docs/generators/java-msf4j.md index 7251308c1440..bd68b2dff859 100644 --- a/docs/generators/java-msf4j.md +++ b/docs/generators/java-msf4j.md @@ -77,6 +77,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false| |useTags|use tags for creating interface and controller classnames| |false| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-pkmst.md b/docs/generators/java-pkmst.md index e2299587c5f2..13bcf1e96da9 100644 --- a/docs/generators/java-pkmst.md +++ b/docs/generators/java-pkmst.md @@ -78,6 +78,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| |zipkinUri|Zipkin URI| |null| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-play-framework.md b/docs/generators/java-play-framework.md index c5f80ab75d16..6ef4cff72fd0 100644 --- a/docs/generators/java-play-framework.md +++ b/docs/generators/java-play-framework.md @@ -81,6 +81,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useSwaggerUI|Add a route to /api which show your documentation in swagger-ui. Will also import needed dependencies| |true| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| |wrapCalls|Add a wrapper to each controller function to handle things like metrics, response modification, etc..| |true| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-undertow-server.md b/docs/generators/java-undertow-server.md index c258e9aa5df4..5af53c6aa537 100644 --- a/docs/generators/java-undertow-server.md +++ b/docs/generators/java-undertow-server.md @@ -71,6 +71,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| |useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-vertx-web.md b/docs/generators/java-vertx-web.md index 473c40d1af7d..6e2ae124829b 100644 --- a/docs/generators/java-vertx-web.md +++ b/docs/generators/java-vertx-web.md @@ -71,6 +71,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| |useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-vertx.md b/docs/generators/java-vertx.md index dd2722079b63..f39d31a1e4c0 100644 --- a/docs/generators/java-vertx.md +++ b/docs/generators/java-vertx.md @@ -74,6 +74,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false| |vertxSwaggerRouterVersion|Specify the version of the swagger router library| |null| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java-wiremock.md b/docs/generators/java-wiremock.md index 39b0a40d6edf..324f9f6505ea 100644 --- a/docs/generators/java-wiremock.md +++ b/docs/generators/java-wiremock.md @@ -71,6 +71,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| |useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/docs/generators/java.md b/docs/generators/java.md index b98c5386e4e5..2eeb07eeb472 100644 --- a/docs/generators/java.md +++ b/docs/generators/java.md @@ -109,6 +109,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |webclientBlockingOperations|Making all WebClient operations blocking(sync). Note that if on operation 'x-webclient-blocking: false' then such operation won't be sync| |false| |withAWSV4Signature|whether to include AWS v4 signature support (only available for okhttp-gson library)| |false| |withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| +|disableDiscriminatorFieldIgnore| whether to add jackson @JsonIgnoreProperties for discriminator in base class | |false| ## SUPPORTED VENDOR EXTENSIONS diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java index 35280515e6a5..13af9699a15e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java @@ -22,7 +22,6 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.base.Strings; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; import com.samskivert.mustache.Mustache; import io.swagger.v3.oas.models.OpenAPI; @@ -51,7 +50,6 @@ import org.openapitools.codegen.model.ModelsMap; import org.openapitools.codegen.model.OperationMap; import org.openapitools.codegen.model.OperationsMap; -import org.openapitools.codegen.templating.mustache.ReplaceAllLambda; import org.openapitools.codegen.utils.CamelizeOption; import org.openapitools.codegen.utils.ModelUtils; import org.slf4j.Logger; @@ -102,6 +100,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code public static final String JAVAX_PACKAGE = "javaxPackage"; public static final String USE_JAKARTA_EE = "useJakartaEe"; public static final String CONTAINER_DEFAULT_TO_NULL = "containerDefaultToNull"; + public static final String DISABLE_DISCRIMINATOR_FIELD_IGNORE = "disableDiscriminatorFieldIgnore"; public static final String CAMEL_CASE_DOLLAR_SIGN = "camelCaseDollarSign"; public static final String USE_ONE_OF_INTERFACES = "useOneOfInterfaces"; @@ -198,6 +197,8 @@ protected enum ENUM_PROPERTY_NAMING_TYPE {MACRO_CASE, legacy, original} protected boolean jackson = false; @Getter @Setter protected boolean generateBuilders; + @Getter @Setter + protected boolean disableDiscriminatorFieldIgnore = false; /** * useBeanValidation has been moved from child generators to AbstractJavaCodegen. * The reason is that getBeanValidation needs it @@ -345,6 +346,7 @@ public AbstractJavaCodegen() { cliOptions.add(CliOption.newBoolean(CONTAINER_DEFAULT_TO_NULL, "Set containers (array, set, map) default to null")); cliOptions.add(CliOption.newBoolean(GENERATE_CONSTRUCTOR_WITH_ALL_ARGS, "whether to generate a constructor for all arguments").defaultValue(Boolean.FALSE.toString())); cliOptions.add(CliOption.newBoolean(GENERATE_BUILDERS, "Whether to generate builders for models").defaultValue(Boolean.FALSE.toString())); + cliOptions.add(CliOption.newBoolean(DISABLE_DISCRIMINATOR_FIELD_IGNORE, "Ignore discriminator field allOf, oneOf for Jackson serialization", disableDiscriminatorFieldIgnore)); cliOptions.add(CliOption.newString(CodegenConstants.PARENT_GROUP_ID, CodegenConstants.PARENT_GROUP_ID_DESC)); cliOptions.add(CliOption.newString(CodegenConstants.PARENT_ARTIFACT_ID, CodegenConstants.PARENT_ARTIFACT_ID_DESC)); @@ -424,6 +426,7 @@ public void processOpts() { convertPropertyToBooleanAndWriteBack(GENERATE_CONSTRUCTOR_WITH_ALL_ARGS, this::setGenerateConstructorWithAllArgs); convertPropertyToBooleanAndWriteBack(GENERATE_BUILDERS, this::setGenerateBuilders); + convertPropertyToBooleanAndWriteBack(DISABLE_DISCRIMINATOR_FIELD_IGNORE, this::setDisableDiscriminatorFieldIgnore); if (StringUtils.isEmpty(System.getenv("JAVA_POST_PROCESS_FILE"))) { LOGGER.info("Environment variable JAVA_POST_PROCESS_FILE not defined so the Java code may not be properly formatted. To define it, try 'export JAVA_POST_PROCESS_FILE=\"/usr/local/bin/clang-format -i\"' (Linux/Mac)"); LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI)."); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index c532d93fa99b..ff9b975d1ec1 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -151,6 +151,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen @Setter protected boolean supportVertxFuture = false; @Setter protected boolean useSealedOneOfInterfaces = false; @Setter protected boolean useUnaryInterceptor = false; + protected String authFolder; /** * Serialization library. diff --git a/modules/openapi-generator/src/main/resources/Java/typeInfoAnnotation.mustache b/modules/openapi-generator/src/main/resources/Java/typeInfoAnnotation.mustache index 58bfed9c45b3..a1c9eff3eb91 100644 --- a/modules/openapi-generator/src/main/resources/Java/typeInfoAnnotation.mustache +++ b/modules/openapi-generator/src/main/resources/Java/typeInfoAnnotation.mustache @@ -1,9 +1,11 @@ {{#jackson}} +{{^disableDiscriminatorFieldIgnore}} @JsonIgnoreProperties( value = "{{{discriminator.propertyBaseName}}}", // ignore manually set {{{discriminator.propertyBaseName}}}, it will be automatically generated by Jackson during serialization allowSetters = true // allows the {{{discriminator.propertyBaseName}}} to be set during deserialization ) +{{/disableDiscriminatorFieldIgnore}} @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminator.propertyBaseName}}}", visible = true) {{#discriminator.mappedModels}} {{#-first}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java index d0b39ffe9a35..9effcaf1cb74 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/AbstractJavaCodegenTest.java @@ -46,6 +46,7 @@ import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; +import static org.openapitools.codegen.languages.AbstractJavaCodegen.DISABLE_DISCRIMINATOR_FIELD_IGNORE; public class AbstractJavaCodegenTest { @@ -968,6 +969,15 @@ public void AnnotationsContainerTest() { Assert.assertEquals(defaultValue, "List<@Max(10)Integer>"); } + @Test + public void disableDiscriminatorFieldIgnoreFlagTest() { + codegen.additionalProperties().put(DISABLE_DISCRIMINATOR_FIELD_IGNORE, true); + + codegen.preprocessOpenAPI(FLATTENED_SPEC.get("3_0/petstore")); + + Assert.assertTrue((boolean) codegen.additionalProperties().get(DISABLE_DISCRIMINATOR_FIELD_IGNORE)); + } + @Test public void removeAnnotationsTest() { Assert.assertEquals(codegen.removeAnnotations("@Min(0) @Max(10)Integer"), "Integer"); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java index 25403631be91..174a95e7627e 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java @@ -3241,7 +3241,7 @@ public void testRestTemplateWithCustomUserAgent() { .setOutputDir(output.toString().replace("\\", "/")); final Map files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate() - .stream().collect(Collectors.toMap(File::getName, Function.identity()));; + .stream().collect(Collectors.toMap(File::getName, Function.identity())); final JavaFileAssert apiClient = JavaFileAssert.assertThat(files.get("ApiClient.java")) .printFileContent(); @@ -3553,23 +3553,23 @@ public void annotationLibraryDoesNotCauseImportConflicts() throws IOException { output.deleteOnExit(); final CodegenConfigurator configurator = new CodegenConfigurator() - .setGeneratorName(JAVA_GENERATOR) - .setLibrary(JavaClientCodegen.NATIVE) - .setAdditionalProperties(properties) - .setInputSpec("src/test/resources/3_0/java/native/issue21991.yaml") - .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + .setGeneratorName(JAVA_GENERATOR) + .setLibrary(JavaClientCodegen.NATIVE) + .setAdditionalProperties(properties) + .setInputSpec("src/test/resources/3_0/java/native/issue21991.yaml") + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); final ClientOptInput clientOptInput = configurator.toClientOptInput(); DefaultGenerator generator = new DefaultGenerator(); Map files = generator.opts(clientOptInput).generate().stream() - .collect(Collectors.toMap(File::getName, Function.identity())); + .collect(Collectors.toMap(File::getName, Function.identity())); File apiFile = files.get("Schema.java"); assertNotNull(apiFile); JavaFileAssert.assertThat(apiFile).fileDoesNotContain( - "import io.swagger.v3.oas.annotations.media.Schema;" + "import io.swagger.v3.oas.annotations.media.Schema;" ); } @@ -3582,23 +3582,23 @@ public void annotationLibraryGeneratesCorrectImports() throws IOException { output.deleteOnExit(); final CodegenConfigurator configurator = new CodegenConfigurator() - .setGeneratorName(JAVA_GENERATOR) - .setLibrary(JavaClientCodegen.NATIVE) - .setAdditionalProperties(properties) - .setInputSpec("src/test/resources/3_0/java/native/issue21991.yaml") - .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + .setGeneratorName(JAVA_GENERATOR) + .setLibrary(JavaClientCodegen.NATIVE) + .setAdditionalProperties(properties) + .setInputSpec("src/test/resources/3_0/java/native/issue21991.yaml") + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); final ClientOptInput clientOptInput = configurator.toClientOptInput(); DefaultGenerator generator = new DefaultGenerator(); Map files = generator.opts(clientOptInput).generate().stream() - .collect(Collectors.toMap(File::getName, Function.identity())); + .collect(Collectors.toMap(File::getName, Function.identity())); File apiFile = files.get("Schema.java"); assertNotNull(apiFile); JavaFileAssert.assertThat(apiFile).fileContains( - "import io.swagger.v3.oas.annotations.media.Schema;" + "import io.swagger.v3.oas.annotations.media.Schema;" ); } @@ -3753,7 +3753,7 @@ public void testClassesAreValidJavaOkHttpGson() { JavaFileAssert.assertThat(oneOfFile).fileContains( "final TypeAdapter adaptersomepkgA = gson.getDelegateAdapter(this, TypeToken.get(some.pkg.A.class));", - "final TypeAdapter adaptersomepkgB = gson.getDelegateAdapter(this, TypeToken.get(some.pkg.B.class));", + "final TypeAdapter adaptersomepkgB = gson.getDelegateAdapter(this, TypeToken.get(some.pkg.B.class));", "public some.pkg.A getsomepkgA() throws ClassCastException {", "public some.pkg.B getsomepkgB() throws ClassCastException {" ); @@ -3803,10 +3803,11 @@ public void givenComplexObjectHasDefaultValueWhenGenerateThenDefaultAssignmentsA //chain method calls for object initialization class MethodCallVisitor extends VoidVisitorAdapter { Map expressionMap = new HashMap<>(); + @Override public void visit(MethodCallExpr n, Void arg) { expressionMap.put(n.getNameAsString(), n.getArgument(0)); - if(n.getScope().isPresent()) { + if (n.getScope().isPresent()) { n.getScope().get().accept(this, arg); } } @@ -3993,7 +3994,7 @@ public void queryParameterJsonSerialization(String library) { assertFileContains( output.resolve("src/main/java/org/openapitools/client/api/QueryApi.java"), "queryParams.putAll(apiClient.parameterToMultiValueMapJson(ApiClient.CollectionFormat" + - ".valueOf(\"csv\".toUpperCase(Locale.ROOT)), \"json_serialized_object_array_ref_string_query\", jsonSerializedObjectArrayRefStringQuery));" + ".valueOf(\"csv\".toUpperCase(Locale.ROOT)), \"json_serialized_object_array_ref_string_query\", jsonSerializedObjectArrayRefStringQuery));" ); } @@ -4063,4 +4064,21 @@ public void testOneOfInterfaceWithAnnotation() { .isInterface() .assertTypeAnnotations().containsWithName("SuppressWarnings"); } + + @Test + public void disableDiscriminatorFieldIgnoreIsTrueThenJsonIgnorePropertiesShouldBeNotAdded() { + final Map files = generateFromContract("src/test/resources/3_0/java/issue12777.yaml", RESTCLIENT, + Map.of(DISABLE_DISCRIMINATOR_FIELD_IGNORE, "true")); + JavaFileAssert.assertThat(files.get("BaseConfiguration.java")) + .assertTypeAnnotations().doesNotContainWithName("JsonIgnoreProperties"); + } + + @Test + public void disableDiscriminatorFieldIgnoreIsTrueThenJsonIgnorePropertiesShouldBeAdded() { + final Map files = generateFromContract("src/test/resources/3_0/java/issue12777.yaml", RESTCLIENT, + Map.of(DISABLE_DISCRIMINATOR_FIELD_IGNORE, "false")); + JavaFileAssert.assertThat(files.get("BaseConfiguration.java")) + .assertTypeAnnotations().containsWithName("JsonIgnoreProperties"); + } + } diff --git a/modules/openapi-generator/src/test/resources/3_0/java/issue12777.yaml b/modules/openapi-generator/src/test/resources/3_0/java/issue12777.yaml new file mode 100644 index 000000000000..6f2299858873 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/java/issue12777.yaml @@ -0,0 +1,64 @@ +openapi: 3.0.1 +info: + title: Example - Polymorphic Config + version: 1.0.0 +paths: { } +components: + schemas: + # ------------------------- + # Base type with discriminator + # ------------------------- + BaseConfiguration: + type: object + properties: + id: + type: integer + format: int64 + type: + $ref: '#/components/schemas/ConfigurationType' + required: + - type + discriminator: + propertyName: type + mapping: + CHILD_ONE: '#/components/schemas/ChildOneConfiguration' + CHILD_TWO: '#/components/schemas/ChildTwoConfiguration' + + ConfigurationType: + type: string + description: Example discriminator enum + enum: + - CHILD_ONE + - CHILD_TWO + + # ------------------------- + # Child 1 + # ------------------------- + ChildOneConfiguration: + allOf: + - $ref: '#/components/schemas/BaseConfiguration' + - type: object + required: + - type + properties: + type: + $ref: '#/components/schemas/ConfigurationType' + additionalFieldOne: + type: string + additionalProperties: true + + # ------------------------- + # Child 2 + # ------------------------- + ChildTwoConfiguration: + allOf: + - $ref: '#/components/schemas/BaseConfiguration' + - type: object + required: + - type + properties: + type: + $ref: '#/components/schemas/ConfigurationType' + additionalFieldTwo: + type: integer + additionalProperties: true