diff --git a/docs/generators/groovy.md b/docs/generators/groovy.md index 0fd5f1222443..32699d5a12c1 100644 --- a/docs/generators/groovy.md +++ b/docs/generators/groovy.md @@ -18,6 +18,7 @@ sidebar_label: groovy |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |groupId|groupId in generated pom.xml| |org.openapitools| diff --git a/docs/generators/java-inflector.md b/docs/generators/java-inflector.md index 2201f355bd7c..f34df4d7a136 100644 --- a/docs/generators/java-inflector.md +++ b/docs/generators/java-inflector.md @@ -20,6 +20,7 @@ sidebar_label: java-inflector |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |groupId|groupId in generated pom.xml| |org.openapitools| diff --git a/docs/generators/java-msf4j.md b/docs/generators/java-msf4j.md index 054bf625590f..27017264e1c8 100644 --- a/docs/generators/java-msf4j.md +++ b/docs/generators/java-msf4j.md @@ -20,6 +20,7 @@ sidebar_label: java-msf4j |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |groupId|groupId in generated pom.xml| |org.openapitools| diff --git a/docs/generators/java-pkmst.md b/docs/generators/java-pkmst.md index 5b547df3b052..c8df6eb88723 100644 --- a/docs/generators/java-pkmst.md +++ b/docs/generators/java-pkmst.md @@ -21,6 +21,7 @@ sidebar_label: java-pkmst |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |eurekaUri|Eureka URI| |null| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| diff --git a/docs/generators/java-play-framework.md b/docs/generators/java-play-framework.md index 923d2a16afaf..3066a14a7224 100644 --- a/docs/generators/java-play-framework.md +++ b/docs/generators/java-play-framework.md @@ -23,6 +23,7 @@ sidebar_label: java-play-framework |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |groupId|groupId in generated pom.xml| |org.openapitools| diff --git a/docs/generators/java-undertow-server.md b/docs/generators/java-undertow-server.md index 188cea719fc5..34544a236c38 100644 --- a/docs/generators/java-undertow-server.md +++ b/docs/generators/java-undertow-server.md @@ -20,6 +20,7 @@ sidebar_label: java-undertow-server |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |groupId|groupId in generated pom.xml| |org.openapitools| diff --git a/docs/generators/java-vertx-web.md b/docs/generators/java-vertx-web.md index b3896623ab1b..cd6c3ee4e9e6 100644 --- a/docs/generators/java-vertx-web.md +++ b/docs/generators/java-vertx-web.md @@ -20,6 +20,7 @@ sidebar_label: java-vertx-web |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |groupId|groupId in generated pom.xml| |org.openapitools| diff --git a/docs/generators/java-vertx.md b/docs/generators/java-vertx.md index a6cd8ed7b85b..58c68915ade5 100644 --- a/docs/generators/java-vertx.md +++ b/docs/generators/java-vertx.md @@ -20,6 +20,7 @@ sidebar_label: java-vertx |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |groupId|groupId in generated pom.xml| |org.openapitools| diff --git a/docs/generators/java.md b/docs/generators/java.md index c97d5e24d4e3..cb5d65eb1573 100644 --- a/docs/generators/java.md +++ b/docs/generators/java.md @@ -21,6 +21,7 @@ sidebar_label: java |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |feignVersion|Version of OpenFeign: '10.x' (default), '9.x' (deprecated)| |false| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| diff --git a/docs/generators/jaxrs-cxf-cdi.md b/docs/generators/jaxrs-cxf-cdi.md index 501f8ced3cbb..ed9a477094f3 100644 --- a/docs/generators/jaxrs-cxf-cdi.md +++ b/docs/generators/jaxrs-cxf-cdi.md @@ -20,6 +20,7 @@ sidebar_label: jaxrs-cxf-cdi |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |generatePom|Whether to generate pom.xml if the file does not already exist.| |true| diff --git a/docs/generators/jaxrs-cxf-client.md b/docs/generators/jaxrs-cxf-client.md index e816515ab192..0d1c841f153d 100644 --- a/docs/generators/jaxrs-cxf-client.md +++ b/docs/generators/jaxrs-cxf-client.md @@ -20,6 +20,7 @@ sidebar_label: jaxrs-cxf-client |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |groupId|groupId in generated pom.xml| |org.openapitools| diff --git a/docs/generators/jaxrs-cxf-extended.md b/docs/generators/jaxrs-cxf-extended.md index 6fa651a36e1e..b83a1d55e4f9 100644 --- a/docs/generators/jaxrs-cxf-extended.md +++ b/docs/generators/jaxrs-cxf-extended.md @@ -21,6 +21,7 @@ sidebar_label: jaxrs-cxf-extended |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |generateJbossDeploymentDescriptor|Generate Jboss Deployment Descriptor| |false| diff --git a/docs/generators/jaxrs-cxf.md b/docs/generators/jaxrs-cxf.md index 7c1f0333da44..d3dd5e448267 100644 --- a/docs/generators/jaxrs-cxf.md +++ b/docs/generators/jaxrs-cxf.md @@ -21,6 +21,7 @@ sidebar_label: jaxrs-cxf |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |generateJbossDeploymentDescriptor|Generate Jboss Deployment Descriptor| |false| diff --git a/docs/generators/jaxrs-jersey.md b/docs/generators/jaxrs-jersey.md index 253f52217084..9183a75d65f7 100644 --- a/docs/generators/jaxrs-jersey.md +++ b/docs/generators/jaxrs-jersey.md @@ -20,6 +20,7 @@ sidebar_label: jaxrs-jersey |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |groupId|groupId in generated pom.xml| |org.openapitools| diff --git a/docs/generators/jaxrs-resteasy-eap.md b/docs/generators/jaxrs-resteasy-eap.md index b21e40893590..3a7623db6796 100644 --- a/docs/generators/jaxrs-resteasy-eap.md +++ b/docs/generators/jaxrs-resteasy-eap.md @@ -20,6 +20,7 @@ sidebar_label: jaxrs-resteasy-eap |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |generateJbossDeploymentDescriptor|Generate Jboss Deployment Descriptor| |true| diff --git a/docs/generators/jaxrs-resteasy.md b/docs/generators/jaxrs-resteasy.md index 0967238e18e7..724c15e9289d 100644 --- a/docs/generators/jaxrs-resteasy.md +++ b/docs/generators/jaxrs-resteasy.md @@ -20,6 +20,7 @@ sidebar_label: jaxrs-resteasy |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |generateJbossDeploymentDescriptor|Generate Jboss Deployment Descriptor| |false| diff --git a/docs/generators/jaxrs-spec.md b/docs/generators/jaxrs-spec.md index efa6474297ba..d8cea1c79a3e 100644 --- a/docs/generators/jaxrs-spec.md +++ b/docs/generators/jaxrs-spec.md @@ -20,6 +20,7 @@ sidebar_label: jaxrs-spec |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |generatePom|Whether to generate pom.xml if the file does not already exist.| |true| diff --git a/docs/generators/spring.md b/docs/generators/spring.md index e981672bff32..98b896d8f262 100644 --- a/docs/generators/spring.md +++ b/docs/generators/spring.md @@ -25,6 +25,7 @@ sidebar_label: spring |developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |groupId|groupId in generated pom.xml| |org.openapitools| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java index 36557914bb1a..c0519355cd5f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java @@ -46,7 +46,13 @@ public class CodegenModel implements IJsonSchemaValidationProperties { public Set oneOf = new TreeSet(); public Set allOf = new TreeSet(); - public String name, classname, title, description, classVarName, modelJson, dataType, xmlPrefix, xmlNamespace, xmlName; + public String name; + // The language-specific name of the class that implements this schema. + // The name of the class is derived from the OpenAPI schema name with formatting rules applied. + public String classname; + // The value of the 'title' attribute in the OpenAPI document. + public String title; + public String description, classVarName, modelJson, dataType, xmlPrefix, xmlNamespace, xmlName; public String classFilename; // store the class file name, mainly used for import public String unescapedDescription; public CodegenDiscriminator discriminator; 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 e93197b37f46..5d9c5be398ec 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 @@ -59,6 +59,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code public static final String DISABLE_HTML_ESCAPING = "disableHtmlEscaping"; public static final String BOOLEAN_GETTER_PREFIX = "booleanGetterPrefix"; public static final String ADDITIONAL_MODEL_TYPE_ANNOTATIONS = "additionalModelTypeAnnotations"; + public static final String DISCRIMINATOR_CASE_SENSITIVE = "discriminatorCaseSensitive"; protected String dateLibrary = "threetenbp"; protected boolean supportAsync = false; @@ -84,6 +85,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code protected String sourceFolder = projectFolder + "/java"; protected String testFolder = projectTestFolder + "/java"; protected boolean fullJavaUtil; + protected boolean discriminatorCaseSensitive = true; // True if the discriminator value lookup should be case-sensitive. protected String javaUtilPrefix = ""; protected Boolean serializableModel = false; protected boolean serializeBigDecimalAsString = false; @@ -189,6 +191,7 @@ public AbstractJavaCodegen() { cliOptions.add(CliOption.newBoolean(CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC, this.getSerializableModel())); cliOptions.add(CliOption.newBoolean(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING_DESC, serializeBigDecimalAsString)); cliOptions.add(CliOption.newBoolean(FULL_JAVA_UTIL, "whether to use fully qualified name for classes under java.util. This option only works for Java API client", fullJavaUtil)); + cliOptions.add(CliOption.newBoolean(DISCRIMINATOR_CASE_SENSITIVE, "Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client", discriminatorCaseSensitive)); cliOptions.add(CliOption.newBoolean(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC, this.isHideGenerationTimestamp())); cliOptions.add(CliOption.newBoolean(WITH_XML, "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)")); @@ -385,6 +388,15 @@ public void processOpts() { if (additionalProperties.containsKey(FULL_JAVA_UTIL)) { this.setFullJavaUtil(Boolean.valueOf(additionalProperties.get(FULL_JAVA_UTIL).toString())); } + if (additionalProperties.containsKey(DISCRIMINATOR_CASE_SENSITIVE)) { + this.setDiscriminatorCaseSensitive(Boolean.valueOf(additionalProperties.get(DISCRIMINATOR_CASE_SENSITIVE).toString())); + } else { + // By default, the discriminator lookup should be case sensitive. There is nothing in the OpenAPI specification + // that indicates the lookup should be case insensitive. However, some implementations perform + // a case-insensitive lookup. + this.setDiscriminatorCaseSensitive(Boolean.TRUE); + } + additionalProperties.put(DISCRIMINATOR_CASE_SENSITIVE, this.discriminatorCaseSensitive); if (fullJavaUtil) { javaUtilPrefix = "java.util."; @@ -1431,6 +1443,15 @@ public void setFullJavaUtil(boolean fullJavaUtil) { this.fullJavaUtil = fullJavaUtil; } + /** + * Set whether discriminator value lookup is case-sensitive or not. + * + * @param discriminatorCaseSensitive true if the discriminator value lookup should be case sensitive. + */ + public void setDiscriminatorCaseSensitive(boolean discriminatorCaseSensitive) { + this.discriminatorCaseSensitive = discriminatorCaseSensitive; + } + public void setWithXml(boolean withXml) { this.withXml = withXml; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 9ea7c3fbe34a..8d2544c6af7f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -369,7 +369,7 @@ public Map postProcessAllModels(Map objs) { for (Map mo : models) { CodegenModel cm = (CodegenModel) mo.get("model"); - // make sure discrimonator models are included in imports + // make sure discriminator models are included in imports CodegenDiscriminator discriminator = cm.discriminator; if (discriminator != null) { Set mappedModels = discriminator.getMappedModels(); diff --git a/modules/openapi-generator/src/main/resources/Java/JSON.mustache b/modules/openapi-generator/src/main/resources/Java/JSON.mustache index 723ea79f16e4..590ba386ea29 100644 --- a/modules/openapi-generator/src/main/resources/Java/JSON.mustache +++ b/modules/openapi-generator/src/main/resources/Java/JSON.mustache @@ -71,9 +71,9 @@ public class JSON { public Class getClassForElement(JsonElement readElement) { Map classByDiscriminatorValue = new HashMap(); {{#mappedModels}} - classByDiscriminatorValue.put("{{mappingName}}".toUpperCase(Locale.ROOT), {{modelName}}.class); + classByDiscriminatorValue.put("{{mappingName}}"{{^discriminatorCaseSensitive}}.toUpperCase(Locale.ROOT){{/discriminatorCaseSensitive}}, {{modelName}}.class); {{/mappedModels}} - classByDiscriminatorValue.put("{{classname}}".toUpperCase(Locale.ROOT), {{classname}}.class); + classByDiscriminatorValue.put("{{name}}"{{^discriminatorCaseSensitive}}.toUpperCase(Locale.ROOT){{/discriminatorCaseSensitive}}, {{classname}}.class); return getClassByDiscriminator(classByDiscriminatorValue, getDiscriminatorValue(readElement, "{{{propertyBaseName}}}")); } @@ -97,8 +97,15 @@ public class JSON { return element.getAsString(); } + /** + * Returns the Java class that implements the OpenAPI schema for the specified discriminator value. + * + * @param classByDiscriminatorValue The map of discriminator values to Java classes. + * @param discriminatorValue The value of the OpenAPI discriminator in the input data. + * @return The Java class that implements the OpenAPI schema + */ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, String discriminatorValue) { - Class clazz = (Class) classByDiscriminatorValue.get(discriminatorValue.toUpperCase(Locale.ROOT)); + Class clazz = (Class) classByDiscriminatorValue.get(discriminatorValue{{^discriminatorCaseSensitive}}.toUpperCase(Locale.ROOT){{/discriminatorCaseSensitive}}); if (null == clazz) { throw new IllegalArgumentException("cannot determine model class of name: <" + discriminatorValue + ">"); } diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/JSON.java index a745ed9fd89a..bd6ffa0b7a43 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/JSON.java @@ -56,10 +56,10 @@ public static GsonBuilder createGson() { @Override public Class getClassForElement(JsonElement readElement) { Map classByDiscriminatorValue = new HashMap(); - classByDiscriminatorValue.put("Dog".toUpperCase(Locale.ROOT), Dog.class); - classByDiscriminatorValue.put("Cat".toUpperCase(Locale.ROOT), Cat.class); - classByDiscriminatorValue.put("BigCat".toUpperCase(Locale.ROOT), BigCat.class); - classByDiscriminatorValue.put("Animal".toUpperCase(Locale.ROOT), Animal.class); + classByDiscriminatorValue.put("Dog", Dog.class); + classByDiscriminatorValue.put("Cat", Cat.class); + classByDiscriminatorValue.put("BigCat", BigCat.class); + classByDiscriminatorValue.put("Animal", Animal.class); return getClassByDiscriminator(classByDiscriminatorValue, getDiscriminatorValue(readElement, "className")); } @@ -77,8 +77,15 @@ private static String getDiscriminatorValue(JsonElement readElement, String disc return element.getAsString(); } + /** + * Returns the Java class that implements the OpenAPI schema for the specified discriminator value. + * + * @param classByDiscriminatorValue The map of discriminator values to Java classes. + * @param discriminatorValue The value of the OpenAPI discriminator in the input data. + * @return The Java class that implements the OpenAPI schema + */ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, String discriminatorValue) { - Class clazz = (Class) classByDiscriminatorValue.get(discriminatorValue.toUpperCase(Locale.ROOT)); + Class clazz = (Class) classByDiscriminatorValue.get(discriminatorValue); if (null == clazz) { throw new IllegalArgumentException("cannot determine model class of name: <" + discriminatorValue + ">"); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java index a745ed9fd89a..bd6ffa0b7a43 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/JSON.java @@ -56,10 +56,10 @@ public static GsonBuilder createGson() { @Override public Class getClassForElement(JsonElement readElement) { Map classByDiscriminatorValue = new HashMap(); - classByDiscriminatorValue.put("Dog".toUpperCase(Locale.ROOT), Dog.class); - classByDiscriminatorValue.put("Cat".toUpperCase(Locale.ROOT), Cat.class); - classByDiscriminatorValue.put("BigCat".toUpperCase(Locale.ROOT), BigCat.class); - classByDiscriminatorValue.put("Animal".toUpperCase(Locale.ROOT), Animal.class); + classByDiscriminatorValue.put("Dog", Dog.class); + classByDiscriminatorValue.put("Cat", Cat.class); + classByDiscriminatorValue.put("BigCat", BigCat.class); + classByDiscriminatorValue.put("Animal", Animal.class); return getClassByDiscriminator(classByDiscriminatorValue, getDiscriminatorValue(readElement, "className")); } @@ -77,8 +77,15 @@ private static String getDiscriminatorValue(JsonElement readElement, String disc return element.getAsString(); } + /** + * Returns the Java class that implements the OpenAPI schema for the specified discriminator value. + * + * @param classByDiscriminatorValue The map of discriminator values to Java classes. + * @param discriminatorValue The value of the OpenAPI discriminator in the input data. + * @return The Java class that implements the OpenAPI schema + */ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, String discriminatorValue) { - Class clazz = (Class) classByDiscriminatorValue.get(discriminatorValue.toUpperCase(Locale.ROOT)); + Class clazz = (Class) classByDiscriminatorValue.get(discriminatorValue); if (null == clazz) { throw new IllegalArgumentException("cannot determine model class of name: <" + discriminatorValue + ">"); } diff --git a/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/JSON.java b/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/JSON.java index a745ed9fd89a..bd6ffa0b7a43 100644 --- a/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/JSON.java +++ b/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/JSON.java @@ -56,10 +56,10 @@ public static GsonBuilder createGson() { @Override public Class getClassForElement(JsonElement readElement) { Map classByDiscriminatorValue = new HashMap(); - classByDiscriminatorValue.put("Dog".toUpperCase(Locale.ROOT), Dog.class); - classByDiscriminatorValue.put("Cat".toUpperCase(Locale.ROOT), Cat.class); - classByDiscriminatorValue.put("BigCat".toUpperCase(Locale.ROOT), BigCat.class); - classByDiscriminatorValue.put("Animal".toUpperCase(Locale.ROOT), Animal.class); + classByDiscriminatorValue.put("Dog", Dog.class); + classByDiscriminatorValue.put("Cat", Cat.class); + classByDiscriminatorValue.put("BigCat", BigCat.class); + classByDiscriminatorValue.put("Animal", Animal.class); return getClassByDiscriminator(classByDiscriminatorValue, getDiscriminatorValue(readElement, "className")); } @@ -77,8 +77,15 @@ private static String getDiscriminatorValue(JsonElement readElement, String disc return element.getAsString(); } + /** + * Returns the Java class that implements the OpenAPI schema for the specified discriminator value. + * + * @param classByDiscriminatorValue The map of discriminator values to Java classes. + * @param discriminatorValue The value of the OpenAPI discriminator in the input data. + * @return The Java class that implements the OpenAPI schema + */ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, String discriminatorValue) { - Class clazz = (Class) classByDiscriminatorValue.get(discriminatorValue.toUpperCase(Locale.ROOT)); + Class clazz = (Class) classByDiscriminatorValue.get(discriminatorValue); if (null == clazz) { throw new IllegalArgumentException("cannot determine model class of name: <" + discriminatorValue + ">"); }