diff --git a/.gitignore b/.gitignore index edc045c83c8..19e2a4cad2d 100644 --- a/.gitignore +++ b/.gitignore @@ -184,6 +184,9 @@ samples/server/petstore/kotlin-server/ktor/build .stack-work .cabal-sandbox cabal.project.local +samples/client/petstore/haskell-http-client/docs/haddock-bundle.min.js +samples/client/petstore/haskell-http-client/docs/meta.json +samples/client/petstore/haskell-http-client/docs/quick-jump.css # R .Rproj.user diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenDiscriminator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenDiscriminator.java index 79c2c40874b..10f42ad98c8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenDiscriminator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenDiscriminator.java @@ -1,5 +1,7 @@ package org.openapitools.codegen; +import org.apache.commons.lang3.builder.ToStringBuilder; + import java.util.*; public class CodegenDiscriminator { @@ -85,4 +87,13 @@ public class CodegenDiscriminator { public int hashCode() { return Objects.hash(propertyName, mapping, mappedModels); } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("propertyName", propertyName) + .append("mapping", mapping) + .append("mappedModels", mappedModels) + .toString(); + } } 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 8251bb22316..77e73cc098b 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 @@ -19,14 +19,7 @@ package org.openapitools.codegen; import io.swagger.v3.oas.models.ExternalDocumentation; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.TreeSet; +import java.util.*; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -40,6 +33,11 @@ public class CodegenModel { public List interfaceModels; public List children; + // anyOf, oneOf, allOf + public Set anyOf = new TreeSet(); + public Set oneOf = new TreeSet(); + public Set allOf = new TreeSet(); + public String name, classname, title, description, classVarName, modelJson, dataType, xmlPrefix, xmlNamespace, xmlName; public String classFilename; // store the class file name, mainly used for import public String unescapedDescription; @@ -53,8 +51,8 @@ public class CodegenModel { public List optionalVars = new ArrayList(); // a list of optional properties public List readOnlyVars = new ArrayList(); // a list of read-only properties public List readWriteVars = new ArrayList(); // a list of properties for read, write - public List allVars; - public List parentVars = new ArrayList<>(); + public List allVars = new ArrayList(); + public List parentVars = new ArrayList(); public Map allowableValues; // Sorted sets of required parameters. @@ -195,11 +193,11 @@ public class CodegenModel { result = 31 * result + (mandatory != null ? mandatory.hashCode() : 0); result = 31 * result + (allMandatory != null ? allMandatory.hashCode() : 0); result = 31 * result + (imports != null ? imports.hashCode() : 0); - result = 31 * result + (hasVars ? 13:31); - result = 31 * result + (emptyVars ? 13:31); - result = 31 * result + (hasMoreModels ? 13:31); - result = 31 * result + (hasEnums ? 13:31); - result = 31 * result + (isEnum ? 13:31); + result = 31 * result + (hasVars ? 13 : 31); + result = 31 * result + (emptyVars ? 13 : 31); + result = 31 * result + (hasMoreModels ? 13 : 31); + result = 31 * result + (hasEnums ? 13 : 31); + result = 31 * result + (isEnum ? 13 : 31); result = 31 * result + (externalDocumentation != null ? externalDocumentation.hashCode() : 0); result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0); result = 31 * result + Objects.hash(hasOnlyReadOnly); @@ -499,4 +497,67 @@ public class CodegenModel { public void setAdditionalPropertiesType(String additionalPropertiesType) { this.additionalPropertiesType = additionalPropertiesType; } + + /** + * Remove duplicated properties in all variable list and update "hasMore" + */ + public void removeAllDuplicatedProperty() { + // remove duplicated properties + vars = removeDuplicatedProperty(vars); + optionalVars = removeDuplicatedProperty(optionalVars); + requiredVars = removeDuplicatedProperty(requiredVars); + parentVars = removeDuplicatedProperty(parentVars); + allVars = removeDuplicatedProperty(allVars); + readOnlyVars = removeDuplicatedProperty(readOnlyVars); + readWriteVars = removeDuplicatedProperty(readWriteVars); + + // update property list's "hasMore" + updatePropertyListHasMore(vars); + updatePropertyListHasMore(optionalVars); + updatePropertyListHasMore(requiredVars); + updatePropertyListHasMore(parentVars); + updatePropertyListHasMore(allVars); + updatePropertyListHasMore(readOnlyVars); + updatePropertyListHasMore(readWriteVars); + } + + private List removeDuplicatedProperty(List vars) { + // clone the list first + List newList = new ArrayList(); + for (CodegenProperty cp : vars) { + newList.add(cp.clone()); + } + + Set propertyNames = new TreeSet(); + Set duplicatedNames = new TreeSet(); + + ListIterator iterator = newList.listIterator(); + while (iterator.hasNext()) { + CodegenProperty element = iterator.next(); + + if (propertyNames.contains(element.baseName)) { + duplicatedNames.add(element.baseName); + iterator.remove(); + } else { + propertyNames.add(element.baseName); + } + } + + return newList; + } + + /** + * Clone the element and update "hasMore" in the list of codegen properties + */ + private void updatePropertyListHasMore(List vars) { + if (vars != null) { + for (int i = 0; i < vars.size(); i++) { + if (i < vars.size() - 1) { + vars.get(i).hasMore = true; + } else { // last element + vars.get(i).hasMore = false; + } + } + } + } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java index 7f6688c134e..ccf838d54cd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java @@ -17,11 +17,7 @@ package org.openapitools.codegen; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; public class CodegenProperty implements Cloneable { public String baseName, complexType, getter, setter, description, dataType, @@ -733,6 +729,7 @@ public class CodegenProperty implements Cloneable { if (this.vendorExtensions != null) { cp.vendorExtensions = new HashMap(this.vendorExtensions); } + return cp; } catch (CloneNotSupportedException e) { throw new IllegalStateException(e); @@ -817,4 +814,6 @@ public class CodegenProperty implements Cloneable { ", isXmlWrapped=" + isXmlWrapped + '}'; } + + } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index f66fb7e7e59..b5e7566e99a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -70,6 +70,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; +import java.util.ListIterator; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; @@ -1312,16 +1313,53 @@ public class DefaultCodegen implements CodegenConfig { **/ @SuppressWarnings("static-method") public String getSchemaType(Schema schema) { - // TODO better logic to handle compose schema if (schema instanceof ComposedSchema) { // composed schema ComposedSchema cs = (ComposedSchema) schema; + List schemas = ModelUtils.getInterfaces(cs); if (cs.getAllOf() != null) { for (Schema s : cs.getAllOf()) { if (s != null) { - // using the first schema defined in allOf - schema = s; - break; + //schema = s; } + //LOGGER.info("ALL OF SCHEMA: {}", s); + } + + LOGGER.info("Composed schema not yet supported: {}", cs); + // get the model (allOf) + return getAlias("UNKNOWN_COMPOSED_SCHMEA"); + } else if (cs.getAnyOf() != null) { // anyOf + List names = new ArrayList(); + for (Schema s : schemas) { + if (StringUtils.isNotBlank(s.get$ref())) { // reference to another definition/schema + String schemaName = ModelUtils.getSimpleRef(s.get$ref()); + if (StringUtils.isNotEmpty(schemaName)) { + names.add(getAlias(schemaName)); + } else { + LOGGER.warn("Error obtaining the datatype from ref:" + schema.get$ref() + ". Default to 'object'"); + return "object"; + } + } else { + // primitive type or model + names.add(getAlias(getPrimitiveType(s))); + } + return "anyOf<" + String.join(",", names) + ">"; + } + } else if (cs.getOneOf() != null) { // oneOf + List names = new ArrayList(); + for (Schema s : schemas) { + if (StringUtils.isNotBlank(s.get$ref())) { // reference to another definition/schema + String schemaName = ModelUtils.getSimpleRef(s.get$ref()); + if (StringUtils.isNotEmpty(schemaName)) { + names.add(getAlias(schemaName)); + } else { + LOGGER.warn("Error obtaining the datatype from ref:" + schema.get$ref() + ". Default to 'object'"); + return "object"; + } + } else { + // primitive type or model + names.add(getAlias(getPrimitiveType(s))); + } + return "oneOf<" + String.join(",", names) + ">"; } } } @@ -1575,42 +1613,43 @@ public class DefaultCodegen implements CodegenConfig { final ComposedSchema composed = (ComposedSchema) schema; Map properties = new LinkedHashMap(); List required = new ArrayList(); - Map allProperties; - List allRequired; + Map allProperties = new LinkedHashMap(); + List allRequired = new ArrayList(); + // parent model + final String parentName = ModelUtils.getParentName(composed, allDefinitions); + final Schema parent = StringUtils.isBlank(parentName) || allDefinitions == null ? null : allDefinitions.get(parentName); + final boolean hasParent = StringUtils.isNotBlank(parentName); + + // TODO revise the logic below to set dicriminator, xml attributes if (supportsInheritance || supportsMixins) { - allProperties = new LinkedHashMap(); - allRequired = new ArrayList(); m.allVars = new ArrayList(); if (composed.getAllOf() != null) { int modelImplCnt = 0; // only one inline object allowed in a ComposedModel - for (Schema innerModel : composed.getAllOf()) { + for (Schema innerSchema : composed.getAllOf()) { // TOOD need to work with anyOf, oneOf as well if (m.discriminator == null) { + LOGGER.debug("discriminator is set to null (not correctly set earlier): {}", name); m.discriminator = createDiscriminator(name, schema, allDefinitions); } - if (innerModel.getXml() != null) { - m.xmlPrefix = innerModel.getXml().getPrefix(); - m.xmlNamespace = innerModel.getXml().getNamespace(); - m.xmlName = innerModel.getXml().getName(); + + if (innerSchema.getXml() != null) { + m.xmlPrefix = innerSchema.getXml().getPrefix(); + m.xmlNamespace = innerSchema.getXml().getNamespace(); + m.xmlName = innerSchema.getXml().getName(); } + if (modelImplCnt++ > 1) { LOGGER.warn("More than one inline schema specified in allOf:. Only the first one is recognized. All others are ignored."); - break; // only one ModelImpl with discriminator allowed in allOf + break; // only one schema with discriminator allowed in allOf } } } - } else { - allProperties = null; - allRequired = null; } - // parent model - final String parentName = getParentName(composed, allDefinitions); - final Schema parent = StringUtils.isBlank(parentName) || allDefinitions == null ? null : allDefinitions.get(parentName); - List interfaces = getInterfaces(composed); - - // interfaces (intermediate models) - if (interfaces != null) { + // interfaces (schemas defined in allOf, anyOf, oneOf) + List interfaces = ModelUtils.getInterfaces(composed); + if (!interfaces.isEmpty()) { + // m.interfaces is for backward compatibility if (m.interfaces == null) m.interfaces = new ArrayList(); @@ -1627,12 +1666,29 @@ public class DefaultCodegen implements CodegenConfig { m.interfaces.add(modelName); addImport(m, modelName); if (allDefinitions != null && refSchema != null) { - if (!supportsMixins && !supportsInheritance) { + if (hasParent || supportsInheritance) { + if (supportsInheritance || parentName.equals(modelName)) { + // inheritance + addProperties(allProperties, allRequired, refSchema, allDefinitions); + } else { + // composition + //LOGGER.debug("Parent {} not set to model name {}", parentName, modelName); + addProperties(properties, required, refSchema, allDefinitions); + } + } else if (!supportsMixins && !supportsInheritance) { addProperties(properties, required, refSchema, allDefinitions); } - if (supportsInheritance) { - addProperties(allProperties, allRequired, refSchema, allDefinitions); - } + + } + + if (composed.getAnyOf() != null) { + m.anyOf.add(modelName); + } else if (composed.getOneOf() != null) { + m.oneOf.add(modelName); + } else if (composed.getAllOf() != null) { + m.allOf.add(modelName); + } else { + LOGGER.error("Composed schema has incorrect anyOf, allOf, oneOf defined: {}", composed); } } } @@ -1642,7 +1698,7 @@ public class DefaultCodegen implements CodegenConfig { m.parent = toModelName(parentName); addImport(m, m.parent); if (allDefinitions != null && !allDefinitions.isEmpty()) { - if (supportsInheritance) { + if (hasParent || supportsInheritance) { addProperties(allProperties, allRequired, parent, allDefinitions); } else { addProperties(properties, required, parent, allDefinitions); @@ -1650,23 +1706,24 @@ public class DefaultCodegen implements CodegenConfig { } } - // child model (properties owned by the model itself) - Schema child = null; - if (composed.getAllOf() != null && !composed.getAllOf().isEmpty()) { - for (Schema component : composed.getAllOf()) { - if (component.get$ref() == null) { - child = component; + // child schema (properties owned by the schema itself) + for (Schema component : interfaces) { + if (component.get$ref() == null) { + if (component != null) { + // component is the child schema + addProperties(properties, required, component, allDefinitions); + + if (hasParent || supportsInheritance) { + addProperties(allProperties, allRequired, component, allDefinitions); + } } + break; // at most one schema not using $ref } } - if (child != null) { - addProperties(properties, required, child, allDefinitions); - if (supportsInheritance) { - addProperties(allProperties, allRequired, child, allDefinitions); - } - } + addVars(m, unaliasPropertySchema(allDefinitions, properties), required, allProperties, allRequired); + // end of code block for composed schema } else { m.dataType = getSchemaType(schema); if (schema.getEnum() != null && !schema.getEnum().isEmpty()) { @@ -1691,12 +1748,15 @@ public class DefaultCodegen implements CodegenConfig { addVars(m, unaliasPropertySchema(allDefinitions, schema.getProperties()), schema.getRequired()); } + // remove duplicated properties + m.removeAllDuplicatedProperty(); + + // post process model properties if (m.vars != null) { for (CodegenProperty prop : m.vars) { postProcessModelProperty(m, prop); } } - LOGGER.debug("debugging fromModel return: " + m); return m; } @@ -1711,7 +1771,10 @@ public class DefaultCodegen implements CodegenConfig { discriminator.setMapping(schema.getDiscriminator().getMapping()); if (schema.getDiscriminator().getMapping() != null && !schema.getDiscriminator().getMapping().isEmpty()) { for (Entry e : schema.getDiscriminator().getMapping().entrySet()) { - String name = ModelUtils.getSimpleRef(e.getValue()); + String name = toModelName(ModelUtils.getSimpleRef(e.getValue())); // e.g e.getValue => #/components/schemas/Dog + if (allDefinitions.get(name) == null) { + LOGGER.warn("Discriminator's mapping: model {} (mapped to {}) couldn't be found", name, e.getKey()); + } discriminator.getMappedModels().add(new MappedModel(e.getKey(), name)); } } else { @@ -4070,19 +4133,6 @@ public class DefaultCodegen implements CodegenConfig { } } - private List getInterfaces(ComposedSchema composed) { - List interfaces; - if (composed.getAllOf() != null && !composed.getAllOf().isEmpty()) { - return composed.getAllOf(); - } else if (composed.getAnyOf() != null && !composed.getAnyOf().isEmpty()) { - return composed.getAnyOf(); - } else if (composed.getOneOf() != null && !composed.getOneOf().isEmpty()) { - return composed.getOneOf(); - } else { - return null; - } - } - private void addConsumesInfo(OpenAPI openAPI, Operation operation, CodegenOperation codegenOperation) { RequestBody requestBody = ModelUtils.getReferencedRequestBody(openAPI, operation.getRequestBody()); if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) { @@ -4219,18 +4269,6 @@ public class DefaultCodegen implements CodegenConfig { return produces; } - protected String getParentName(ComposedSchema composedSchema, Map allSchemas) { - if (composedSchema.getAllOf() != null && !composedSchema.getAllOf().isEmpty()) { - for (Schema schema : composedSchema.getAllOf()) { - String ref = schema.get$ref(); - if (!StringUtils.isBlank(ref)) { - return ModelUtils.getSimpleRef(ref); - } - } - } - return null; - } - protected String getCollectionFormat(Parameter parameter) { if (Parameter.StyleEnum.FORM.equals(parameter.getStyle())) { // Ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#style-values diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java index 4c0ab9c54a8..b9f0acbf92f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java @@ -22,6 +22,7 @@ import io.swagger.v3.oas.models.parameters.Parameter; import io.swagger.v3.oas.models.examples.Example; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.*; +import org.openapitools.codegen.utils.ModelUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -93,7 +94,6 @@ public class RubyClientCodegen extends AbstractRubyCodegen { reservedWords.add(word.toLowerCase(Locale.ROOT)); } - // primitives in ruby lang languageSpecificPrimitives.add("int"); languageSpecificPrimitives.add("array"); @@ -616,4 +616,13 @@ public class RubyClientCodegen extends AbstractRubyCodegen { // //return super.shouldOverwrite(filename) && !filename.endsWith("_spec.rb"); } + + @Override + protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) { + final Schema additionalProperties = ModelUtils.getAdditionalProperties(schema); + + if (additionalProperties != null) { + codegenModel.additionalPropertiesType = getSchemaType(additionalProperties); + } + } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java index 8f72c1e50cd..6beb9a7616f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java @@ -292,7 +292,9 @@ public class ModelUtils { ref = ref.substring(ref.lastIndexOf("/") + 1); } else { LOGGER.warn("Failed to get the schema name: {}", ref); + //throw new RuntimeException("Failed to get the schema: " + ref); return null; + } return ref; @@ -741,7 +743,7 @@ public class ModelUtils { return null; } if (content.size() > 1) { - LOGGER.warn("Multiple schemas found, returning only the first one"); + LOGGER.warn("Multiple schemas found in content, returning only the first one"); } MediaType mediaType = content.values().iterator().next(); return mediaType.getSchema(); @@ -823,6 +825,59 @@ public class ModelUtils { return null; } + /** + * Get the interfaces from the schema (composed) + * + * @param composed schema (alias or direct reference) + * @return a list of schema defined in allOf, anyOf or oneOf + */ + public static List getInterfaces(ComposedSchema composed) { + if (composed.getAllOf() != null && !composed.getAllOf().isEmpty()) { + return composed.getAllOf(); + } else if (composed.getAnyOf() != null && !composed.getAnyOf().isEmpty()) { + return composed.getAnyOf(); + } else if (composed.getOneOf() != null && !composed.getOneOf().isEmpty()) { + return composed.getOneOf(); + } else { + return Collections.emptyList(); + } + } + + /** + * Get the the parent model name from the schemas (allOf, anyOf, oneOf) + * + * @param composedSchema schema (alias or direct reference) + * @param allSchemas all schemas + * @return the name of the parent model + */ + public static String getParentName(ComposedSchema composedSchema, Map allSchemas) { + List interfaces = getInterfaces(composedSchema); + + if (interfaces != null && !interfaces.isEmpty()) { + for (Schema schema : interfaces) { + // get the actual schema + if (StringUtils.isNotEmpty(schema.get$ref())) { + String parentName = getSimpleRef(schema.get$ref()); + Schema s = allSchemas.get(parentName); + if (s == null) { + LOGGER.error("Failed to obtain schema from {}", parentName); + return "UNKNOWN_PARENT_NAME"; + } else if (s.getDiscriminator() != null && StringUtils.isNotEmpty(s.getDiscriminator().getPropertyName())) { + // discriminator.propertyName is used + return parentName; + } else { + LOGGER.debug("Not a parent since discriminator.propertyName is not set {}", s.get$ref()); + // not a parent since discriminator.propertyName is not set + } + } else { + // not a ref, doing nothing + } + } + } + + return null; + } + public static boolean isNullable(Schema schema) { if (schema == null) { return false; diff --git a/modules/openapi-generator/src/main/resources/haskell-http-client/Model.mustache b/modules/openapi-generator/src/main/resources/haskell-http-client/Model.mustache index 056ba0383cb..dbfd338b8fb 100644 --- a/modules/openapi-generator/src/main/resources/haskell-http-client/Model.mustache +++ b/modules/openapi-generator/src/main/resources/haskell-http-client/Model.mustache @@ -114,9 +114,9 @@ instance WH.ToForm {{classname}} where {{#generateModelConstructors}} -- | Construct a value of type '{{classname}}' (by applying it's required fields, if any) mk{{classname}} - :: {{#requiredVars}}{{{vendorExtensions.x-dataType}}} -- ^ '{{name}}'{{#description}}:{{/description}} {{{description}}} - -> {{/requiredVars}}{{classname}} -mk{{classname}} {{#requiredVars}}{{name}} {{/requiredVars}}= + :: {{#vars}}{{#required}}{{{vendorExtensions.x-dataType}}} -- ^ '{{name}}'{{#description}}:{{/description}} {{{description}}} + -> {{/required}}{{/vars}}{{classname}} +mk{{classname}} {{#vars}}{{#required}}{{name}} {{/required}}{{/vars}}= {{classname}} { {{#vars}}{{#required}}{{name}}{{/required}}{{^required}}{{name}} = {{#isListContainer}}Nothing{{/isListContainer}}{{#isMapContainer}}Nothing{{/isMapContainer}}{{^isContainer}}Nothing{{/isContainer}}{{/required}}{{#hasMore}} , {{/hasMore}}{{/vars}} @@ -194,4 +194,4 @@ instance AuthMethod {{name}} where & L.over rAuthTypesL (P.filter (/= P.typeOf a)) else req -{{/isOAuth}}{{/authMethods}} \ No newline at end of file +{{/isOAuth}}{{/authMethods}} diff --git a/modules/openapi-generator/src/main/resources/ruby-client/base_object.mustache b/modules/openapi-generator/src/main/resources/ruby-client/base_object.mustache index 815f5078fc7..faef2ae199e 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/base_object.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/base_object.mustache @@ -3,6 +3,9 @@ # @return [Object] Returns the model itself def build_from_hash(attributes) return nil unless attributes.is_a?(Hash) + {{#parent}} + super(attributes) + {{/parent}} self.class.openapi_types.each_pair do |key, type| if type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the the attribute @@ -75,7 +78,7 @@ # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = {} + hash = {{^parent}}{}{{/parent}}{{#parent}}super{{/parent}} self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) next if value.nil? @@ -100,4 +103,4 @@ else value end - end \ No newline at end of file + end diff --git a/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache b/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache index 576a8444f02..f6082b111ab 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache @@ -1,7 +1,7 @@ {{#description}} # {{{description}}} {{/description}} - class {{classname}} + class {{classname}}{{#parent}} < {{{.}}}{{/parent}} {{#vars}} {{#description}} # {{{description}}} @@ -51,6 +51,54 @@ } end + {{#anyOf}} + {{#-first}} + # List of class defined in anyOf (OpenAPI v3) + def self.openapi_any_of + [ + {{/-first}} + :'{{{.}}}'{{^-last}},{{/-last}} + {{#-last}} + ] + end + + {{/-last}} + {{/anyOf}} + {{#oneOf}} + {{#-first}} + # List of class defined in oneOf (OpenAPI v3) + def self.openapi_one_of + [ + {{/-first}} + :'{{{.}}}'{{^-last}},{{/-last}} + {{#-last}} + ] + end + + {{/-last}} + {{/oneOf}} + {{#allOf}} + {{#-first}} + # List of class defined in allOf (OpenAPI v3) + def self.openapi_all_of + [ + {{/-first}} + :'{{{.}}}'{{^-last}},{{/-last}} + {{#-last}} + ] + end + + {{/-last}} + {{/allOf}} + {{#discriminator}} + {{#propertyName}} + # discriminator's property name in OpenAPI v3 + def self.openapi_discriminator_name + :'{{{.}}}' + end + + {{/propertyName}} + {{/discriminator}} # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -58,6 +106,11 @@ # convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } + {{#parent}} + + # call parent's initialize + super(attributes) + {{/parent}} {{#vars}} if attributes.has_key?(:'{{{baseName}}}') @@ -85,7 +138,7 @@ # Show invalid properties with the reasons. Usually used together with valid? # @return Array for valid properties with the reasons def list_invalid_properties - invalid_properties = Array.new + invalid_properties = {{^parent}}Array.new{{/parent}}{{#parent}}super{{/parent}} {{#vars}} {{^isNullable}} {{#required}} @@ -182,7 +235,45 @@ {{/minItems}} {{/hasValidation}} {{/vars}} - true + {{#anyOf}} + {{#-first}} + _any_of_found = false + openapi_any_of.each do |_class| + _any_of = {{moduleName}}.const_get(_class).new + _any_of.build_from_hash(self.to_hash) + if _any_of.valid? + _any_of_found = true + end + end + + if !_any_of_found? + return false + end + + {{/-first}} + {{/anyOf}} + {{#oneOf}} + {{#-first}} + _one_of_found = false + openapi_one_of.each do |_class| + _one_of = {{moduleName}}.const_get(_class).new + _one_of.build_from_hash(self.to_hash) + if _one_of.valid? + if _one_of_found? + return false + else + _one_of_found = true + end + end + end + + if !_one_of_found? + return false + end + + {{/-first}} + {{/oneOf}} + true{{#parent}} && super{{/parent}} end {{#vars}} @@ -266,7 +357,7 @@ def ==(o) return true if self.equal?(o) self.class == o.class{{#vars}} && - {{name}} == o.{{name}}{{/vars}} + {{name}} == o.{{name}}{{/vars}}{{#parent}} && super(o){{/parent}} end # @see the `==` method @@ -282,4 +373,4 @@ end {{> base_object}} - end \ No newline at end of file + end diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index 2dfe69565e2..79e0f3ca17e 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -60,7 +60,7 @@ public class DefaultCodegenTest { .description("Ok response"))); Operation createOperation = new Operation() .requestBody(new RequestBody() - .content(new Content().addMediaType("application/json", + .content(new Content().addMediaType("application/json", new MediaType().schema(refSchema)))) .responses( new ApiResponses().addApiResponse("201", new ApiResponse() @@ -83,11 +83,11 @@ public class DefaultCodegenTest { openAPI.setComponents(new Components()); openAPI.getComponents().addSchemas("Pet", new ObjectSchema()); openAPI.getComponents().addRequestBodies("MyRequestBody", new RequestBody() - .content(new Content().addMediaType("application/json", + .content(new Content().addMediaType("application/json", new MediaType().schema(refSchema)))); openAPI.getComponents().addResponses("MyResponse", new ApiResponse() - .description("Ok response") - .content(new Content().addMediaType("application/xml", + .description("Ok response") + .content(new Content().addMediaType("application/xml", new MediaType().schema(refSchema)))); Operation createOperation = new Operation() @@ -172,7 +172,7 @@ public class DefaultCodegenTest { codegen.processOpts(); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE); - Assert.assertEquals(codegen.isHideGenerationTimestamp(), false ); + Assert.assertEquals(codegen.isHideGenerationTimestamp(), false); } @Test @@ -221,14 +221,14 @@ public class DefaultCodegenTest { Assert.assertEquals(co.produces.size(), 1); Assert.assertEquals(co.produces.get(0).get("mediaType"), "application/json"); } - + @Test public void testConsistentParameterNameAfterUniquenessRename() throws Exception { Operation operation = new Operation() - .operationId("opId") - .addParametersItem(new QueryParameter().name("myparam").schema(new StringSchema())) - .addParametersItem(new QueryParameter().name("myparam").schema(new StringSchema())) - .responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("OK"))); + .operationId("opId") + .addParametersItem(new QueryParameter().name("myparam").schema(new StringSchema())) + .addParametersItem(new QueryParameter().name("myparam").schema(new StringSchema())) + .responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("OK"))); DefaultCodegen codegen = new DefaultCodegen(); CodegenOperation co = codegen.fromOperation("/some/path", "get", operation, Collections.emptyMap()); @@ -292,7 +292,7 @@ public class DefaultCodegenTest { Assert.assertNotNull(enumVars); Map testedEnumVar = enumVars.get(0); Assert.assertNotNull(testedEnumVar); - Assert.assertEquals(testedEnumVar.getOrDefault("name", ""),"_1"); + Assert.assertEquals(testedEnumVar.getOrDefault("name", ""), "_1"); Assert.assertEquals(testedEnumVar.getOrDefault("value", ""), "\"1\""); Assert.assertEquals(testedEnumVar.getOrDefault("isString", ""), false); } @@ -503,16 +503,16 @@ public class DefaultCodegenTest { Assert.assertEquals(req.responses.size(), 2); switch (req.httpMethod.toLowerCase(Locale.getDefault())) { - case "post": - Assert.assertEquals(req.operationId, "onDataDataPost"); - Assert.assertEquals(req.bodyParam.dataType, "NewNotificationData"); - break; - case "delete": - Assert.assertEquals(req.operationId, "onDataDataDelete"); - Assert.assertEquals(req.bodyParam.dataType, "DeleteNotificationData"); - break; - default: - Assert.fail(String.format(Locale.getDefault(), "invalid callback request http method '%s'", req.httpMethod)); + case "post": + Assert.assertEquals(req.operationId, "onDataDataPost"); + Assert.assertEquals(req.bodyParam.dataType, "NewNotificationData"); + break; + case "delete": + Assert.assertEquals(req.operationId, "onDataDataDelete"); + Assert.assertEquals(req.bodyParam.dataType, "DeleteNotificationData"); + break; + default: + Assert.fail(String.format(Locale.getDefault(), "invalid callback request http method '%s'", req.httpMethod)); } }); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaInheritanceTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaInheritanceTest.java index 27f89509124..51717f8cb55 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaInheritanceTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaInheritanceTest.java @@ -33,16 +33,16 @@ import java.util.Map; public class JavaInheritanceTest { - @Test(description = "convert a composed model with parent") + @Test(description = "convert a composed model without discriminator") public void javaInheritanceTest() { - final Schema parentModel = new Schema().name("Base"); + final Schema allOfModel = new Schema().name("Base"); final Schema schema = new ComposedSchema() .addAllOfItem(new Schema().$ref("Base")) .name("composed"); final Map allSchemas = new HashMap<>(); - allSchemas.put(parentModel.getName(), parentModel); + allSchemas.put(allOfModel.getName(), allOfModel); allSchemas.put(schema.getName(), schema); final JavaClientCodegen codegen = new JavaClientCodegen(); @@ -50,14 +50,16 @@ public class JavaInheritanceTest { Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); - Assert.assertEquals(cm.parent, "Base"); + Assert.assertEquals(cm.parent, null); Assert.assertEquals(cm.imports, Sets.newHashSet("Base")); } @Test(description = "convert a composed model with discriminator") public void javaInheritanceWithDiscriminatorTest() { final Schema base = new Schema().name("Base"); - base.setDiscriminator(new Discriminator().mapping("name", StringUtils.EMPTY)); + Discriminator discriminator = new Discriminator().mapping("name", StringUtils.EMPTY); + discriminator.setPropertyName("model_type"); + base.setDiscriminator(discriminator); final Schema schema = new ComposedSchema() .addAllOfItem(new Schema().$ref("Base")); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelEnumTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelEnumTest.java index 2244bfd208d..8cbdf7ade29 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelEnumTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelEnumTest.java @@ -17,11 +17,9 @@ package org.openapitools.codegen.java; -import io.swagger.v3.oas.models.media.ArraySchema; -import io.swagger.v3.oas.models.media.ComposedSchema; -import io.swagger.v3.oas.models.media.Schema; -import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.*; +import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenProperty; import org.openapitools.codegen.DefaultCodegen; @@ -59,7 +57,7 @@ public class JavaModelEnumTest { @Test(description = "convert a java model with an enum inside a list") public void converterInArrayTest() { final ArraySchema enumSchema = new ArraySchema().items( - new StringSchema().addEnumItem("Aaaa").addEnumItem("Bbbb")); + new StringSchema().addEnumItem("Aaaa").addEnumItem("Bbbb")); final Schema model = new Schema().type("object").addProperties("name", enumSchema); final DefaultCodegen codegen = new JavaClientCodegen(); @@ -137,6 +135,10 @@ public class JavaModelEnumTest { parentModel.setProperties(parentProperties); parentModel.name("parentModel"); + Discriminator discriminator = new Discriminator().mapping("name", StringUtils.EMPTY); + discriminator.setPropertyName("model_type"); + parentModel.setDiscriminator(discriminator); + final ComposedSchema composedSchema = new ComposedSchema() .addAllOfItem(new Schema().$ref(parentModel.getName())); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/objc/ObjcModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/objc/ObjcModelTest.java index 99279bd2f10..54d85ed5d81 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/objc/ObjcModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/objc/ObjcModelTest.java @@ -80,8 +80,7 @@ public class ObjcModelTest { .addProperties("name", new StringSchema()) .addProperties("createdAt", new DateTimeSchema()) .addRequiredItem("id") - .addRequiredItem("name") - .discriminator(new Discriminator().mapping("test", "test")); + .addRequiredItem("name"); final DefaultCodegen codegen = new ObjcClientCodegen(); final CodegenModel cm = codegen.fromModel("sample", model, Collections.singletonMap("sample", model)); @@ -89,7 +88,6 @@ public class ObjcModelTest { Assert.assertEquals(cm.classname, "OAISample"); Assert.assertEquals(cm.description, "a sample model"); Assert.assertEquals(cm.vars.size(), 3); - Assert.assertEquals(cm.discriminator.getMapping().get("test"),"test"); final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "id"); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java index 5d025c098f0..2512812d774 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java @@ -35,7 +35,7 @@ import org.testng.annotations.Test; import java.io.File; import java.nio.charset.StandardCharsets; -import java.util.List; +import java.util.*; import static org.testng.Assert.*; @@ -272,6 +272,113 @@ public class RubyClientCodegenTest { //Assert.assertTrue(status.isNullable); } + @Test(description = "test anyOf (OAS3)") + public void anyOfTest() { + final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/anyOf.yaml", null, new ParseOptions()).getOpenAPI(); + final RubyClientCodegen codegen = new RubyClientCodegen(); + codegen.setModuleName("OnlinePetstore"); + + final Schema schema = openAPI.getComponents().getSchemas().get("fruit"); + CodegenModel fruit = codegen.fromModel("Fruit", schema, openAPI.getComponents().getSchemas()); + + Set anyOf = new TreeSet(); + anyOf.add("Apple"); + anyOf.add("Banana"); + Assert.assertEquals(fruit.anyOf, anyOf); + } + + @Test(description = "test oneOf (OAS3)") + public void oneOfTest() { + final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/oneOf.yaml", null, new ParseOptions()).getOpenAPI(); + final RubyClientCodegen codegen = new RubyClientCodegen(); + codegen.setModuleName("OnlinePetstore"); + + final Schema schema = openAPI.getComponents().getSchemas().get("fruit"); + CodegenModel fruit = codegen.fromModel("Fruit", schema, openAPI.getComponents().getSchemas()); + + Set oneOf = new TreeSet(); + oneOf.add("Apple"); + oneOf.add("Banana"); + Assert.assertEquals(fruit.oneOf, oneOf); + } + + @Test(description = "test allOf (OAS3)") + public void allOfTest() { + final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/allOf.yaml", null, new ParseOptions()).getOpenAPI(); + final RubyClientCodegen codegen = new RubyClientCodegen(); + codegen.setModuleName("OnlinePetstore"); + + final Schema schema = openAPI.getComponents().getSchemas().get("Person"); + CodegenModel person = codegen.fromModel("Person", schema, openAPI.getComponents().getSchemas()); + Assert.assertNotNull(person); + + CodegenDiscriminator codegenDiscriminator = person.getDiscriminator(); + Set mappedModels = new LinkedHashSet(); + CodegenDiscriminator.MappedModel adult = new CodegenDiscriminator.MappedModel("a", "Adult"); + mappedModels.add(adult); + CodegenDiscriminator.MappedModel child = new CodegenDiscriminator.MappedModel("c", "Child"); + mappedModels.add(child); + Assert.assertEquals(codegenDiscriminator.getMappedModels(), mappedModels); + } + + @Test(description = "test allOf with only allOf and duplicated properties(OAS3)") + public void allOfDuplicatedPropertiesTest() { + final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/allOfDuplicatedProperties.yaml", null, new ParseOptions()).getOpenAPI(); + final RubyClientCodegen codegen = new RubyClientCodegen(); + codegen.setModuleName("OnlinePetstore"); + + final Schema schema = openAPI.getComponents().getSchemas().get("ModelC"); + CodegenModel modelC = codegen.fromModel("ModelC", schema, openAPI.getComponents().getSchemas()); + Assert.assertNotNull(modelC); + Assert.assertEquals(modelC.getVars().size(), 5); + + CodegenProperty cp0 = modelC.getVars().get(0); + Assert.assertEquals(cp0.name, "foo"); + + CodegenProperty cp1 = modelC.getVars().get(1); + Assert.assertEquals(cp1.name, "duplicated_optional"); + + CodegenProperty cp2 = modelC.getVars().get(2); + Assert.assertEquals(cp2.name, "duplicated_required"); + + CodegenProperty cp3 = modelC.getVars().get(3); + Assert.assertEquals(cp3.name, "bar"); + + CodegenProperty cp4 = modelC.getVars().get(4); + Assert.assertEquals(cp4.name, "baz"); + } + + + @Test(description = "test allOf with discriminator and duplicated properties(OAS3)") + public void allOfMappingDuplicatedPropertiesTest() { + final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/allOfMappingDuplicatedProperties.yaml", null, new ParseOptions()).getOpenAPI(); + final RubyClientCodegen codegen = new RubyClientCodegen(); + codegen.setModuleName("OnlinePetstore"); + + final Schema schema = openAPI.getComponents().getSchemas().get("Child"); + CodegenModel child = codegen.fromModel("Child", schema, openAPI.getComponents().getSchemas()); + Assert.assertNotNull(child); + Assert.assertEquals(child.getVars().size(), 6); + + CodegenProperty cp0 = child.getVars().get(0); + Assert.assertEquals(cp0.name, "age"); + + CodegenProperty cp1 = child.getVars().get(1); + Assert.assertEquals(cp1.name, "first_name"); + + CodegenProperty cp2 = child.getVars().get(2); + Assert.assertEquals(cp2.name, "_type"); + + CodegenProperty cp3 = child.getVars().get(3); + Assert.assertEquals(cp3.name, "last_name"); + + CodegenProperty cp4 = child.getVars().get(4); + Assert.assertEquals(cp4.name, "duplicated_optional"); + + CodegenProperty cp5 = child.getVars().get(5); + Assert.assertEquals(cp5.name, "duplicated_required"); + } + @Test(description = "test example string imported from x-example parameterr (OAS2)") public void exampleStringFromExampleParameterOAS2Test() { final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/2_0/petstore-nullable.yaml", null, new ParseOptions()).getOpenAPI(); diff --git a/modules/openapi-generator/src/test/resources/3_0/allOfDuplicatedProperties.yaml b/modules/openapi-generator/src/test/resources/3_0/allOfDuplicatedProperties.yaml new file mode 100644 index 00000000000..636f82a4a04 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/allOfDuplicatedProperties.yaml @@ -0,0 +1,47 @@ +openapi: 3.0.0 +info: + title: TestApi + version: 1.0.0 +paths: + /test: + get: + summary: Test + operationId: testApi + responses: + "200": + description: Ok + content: + application/json: + schema: + $ref: "#/components/schemas/ModelC" +components: + schemas: + ModelA: + required: + - duplicated_required + properties: + foo: + type: string + duplicated_optional: + type: string + duplicated_required: + type: string + ModelB: + required: + - duplicated_required + properties: + bar: + type: string + duplicated_optional: + type: integer + duplicated_required: + type: integer + ModelC: + allOf: + - $ref: "#/components/schemas/ModelA" + - $ref: "#/components/schemas/ModelB" + - type: object + properties: + baz: + type: string + diff --git a/modules/openapi-generator/src/test/resources/3_0/allOfMappingDuplicatedProperties.yaml b/modules/openapi-generator/src/test/resources/3_0/allOfMappingDuplicatedProperties.yaml new file mode 100644 index 00000000000..2e1ec994bb0 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/allOfMappingDuplicatedProperties.yaml @@ -0,0 +1,84 @@ +openapi: 3.0.1 +info: + version: 1.0.0 + title: Example + license: + name: MIT +servers: + - url: http://api.example.xyz/v1 +paths: + /person/display/{personId}: + get: + parameters: + - name: personId + in: path + required: true + description: The id of the person to retrieve + schema: + type: string + operationId: list + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/Person" +components: + schemas: + Person: + required: + - duplicated_required + type: object + discriminator: + propertyName: $_type + mapping: + a: '#/components/schemas/Adult' + c: '#/components/schemas/Child' + properties: + $_type: + type: string + lastName: + type: string + firstName: + type: string + duplicated_optional: + type: string + duplicated_required: + type: string + Adult: + description: A representation of an adult + allOf: + - $ref: '#/components/schemas/Person' + - type: object + required: + - duplicated_required + properties: + duplicated_optional: + type: integer + duplicated_required: + type: integer + children: + type: array + items: + $ref: "#/components/schemas/Child" + Child: + description: A representation of a child + allOf: + - type: object + properties: + age: + type: integer + format: int32 + firstName: + type: string + - $ref: '#/components/schemas/Person' + MapOnly: + additionalProperties: + type: string + MapOnlyWithProperties: + additionalProperties: + type: string + properties: + firstName: + type: string \ No newline at end of file diff --git a/modules/openapi-generator/src/test/resources/3_0/anyOf.yaml b/modules/openapi-generator/src/test/resources/3_0/anyOf.yaml new file mode 100644 index 00000000000..64b32c1196d --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/anyOf.yaml @@ -0,0 +1,64 @@ +{ + "openapi":"3.0.1", + "info":{ + "title":"fruity", + "version":"0.0.1" + }, + "paths":{ + "/":{ + "get":{ + "responses":{ + "200":{ + "description":"desc", + "content":{ + "application/json":{ + "schema":{ + "$ref":"#/components/schemas/fruit" + } + } + } + } + } + } + } + }, + "components":{ + "schemas":{ + "fruit":{ + "title":"fruit", + "type":"object", + "properties":{ + "color":{ + "type":"string" + } + }, + "anyOf":[ + { + "$ref":"#/components/schemas/apple" + }, + { + "$ref":"#/components/schemas/banana" + } + ] + }, + "apple":{ + "title":"apple", + "type":"object", + "properties":{ + "kind":{ + "type":"string" + } + } + }, + "banana":{ + "title":"banana", + "type":"object", + "properties":{ + "count":{ + "type":"number" + } + } + } + } + } +} diff --git a/modules/openapi-generator/src/test/resources/3_0/oneOf.yaml b/modules/openapi-generator/src/test/resources/3_0/oneOf.yaml new file mode 100644 index 00000000000..4da439e5f3b --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/oneOf.yaml @@ -0,0 +1,64 @@ +{ + "openapi":"3.0.1", + "info":{ + "title":"fruity", + "version":"0.0.1" + }, + "paths":{ + "/":{ + "get":{ + "responses":{ + "200":{ + "description":"desc", + "content":{ + "application/json":{ + "schema":{ + "$ref":"#/components/schemas/fruit" + } + } + } + } + } + } + } + }, + "components":{ + "schemas":{ + "fruit":{ + "title":"fruit", + "type":"object", + "properties":{ + "color":{ + "type":"string" + } + }, + "oneOf":[ + { + "$ref":"#/components/schemas/apple" + }, + { + "$ref":"#/components/schemas/banana" + } + ] + }, + "apple":{ + "title":"apple", + "type":"object", + "properties":{ + "kind":{ + "type":"string" + } + } + }, + "banana":{ + "title":"banana", + "type":"object", + "properties":{ + "count":{ + "type":"number" + } + } + } + } + } +} diff --git a/samples/client/petstore/csharp/OpenAPIClient/docs/EnumTest.md b/samples/client/petstore/csharp/OpenAPIClient/docs/EnumTest.md index 65bc4d2cb04..0e1666d4fea 100644 --- a/samples/client/petstore/csharp/OpenAPIClient/docs/EnumTest.md +++ b/samples/client/petstore/csharp/OpenAPIClient/docs/EnumTest.md @@ -7,7 +7,7 @@ Name | Type | Description | Notes **EnumStringRequired** | **string** | | **EnumInteger** | **int?** | | [optional] **EnumNumber** | **double?** | | [optional] -**OuterEnum** | **OuterEnum** | | [optional] +**OuterEnum** | [**OuterEnum**](OuterEnum.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/EnumTest.cs b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/EnumTest.cs index 7099a980016..707ab1fb39e 100644 --- a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/EnumTest.cs +++ b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/EnumTest.cs @@ -140,11 +140,6 @@ namespace Org.OpenAPITools.Model [DataMember(Name="enum_number", EmitDefaultValue=false)] public EnumNumberEnum? EnumNumber { get; set; } /// - /// Gets or Sets OuterEnum - /// - [DataMember(Name="outerEnum", EmitDefaultValue=false)] - public OuterEnum? OuterEnum { get; set; } - /// /// Initializes a new instance of the class. /// [JsonConstructorAttribute] @@ -157,7 +152,7 @@ namespace Org.OpenAPITools.Model /// enumInteger. /// enumNumber. /// outerEnum. - public EnumTest(EnumStringEnum? enumString = default(EnumStringEnum?), EnumStringRequiredEnum enumStringRequired = default(EnumStringRequiredEnum), EnumIntegerEnum? enumInteger = default(EnumIntegerEnum?), EnumNumberEnum? enumNumber = default(EnumNumberEnum?), OuterEnum? outerEnum = default(OuterEnum?)) + public EnumTest(EnumStringEnum? enumString = default(EnumStringEnum?), EnumStringRequiredEnum enumStringRequired = default(EnumStringRequiredEnum), EnumIntegerEnum? enumInteger = default(EnumIntegerEnum?), EnumNumberEnum? enumNumber = default(EnumNumberEnum?), OuterEnum outerEnum = default(OuterEnum)) { // to ensure "enumStringRequired" is required (not null) if (enumStringRequired == null) @@ -178,6 +173,11 @@ namespace Org.OpenAPITools.Model + /// + /// Gets or Sets OuterEnum + /// + [DataMember(Name="outerEnum", EmitDefaultValue=false)] + public OuterEnum OuterEnum { get; set; } /// /// Returns the string presentation of the object diff --git a/samples/client/petstore/go/go-petstore/docs/Cat.md b/samples/client/petstore/go/go-petstore/docs/Cat.md index b51d5fd2b95..8b39bdf028d 100644 --- a/samples/client/petstore/go/go-petstore/docs/Cat.md +++ b/samples/client/petstore/go/go-petstore/docs/Cat.md @@ -3,9 +3,9 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**Declawed** | **bool** | | [optional] **ClassName** | **string** | | **Color** | **string** | | [optional] [default to red] -**Declawed** | **bool** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/go/go-petstore/docs/Dog.md b/samples/client/petstore/go/go-petstore/docs/Dog.md index 13c0aa28e6b..2107e83ede5 100644 --- a/samples/client/petstore/go/go-petstore/docs/Dog.md +++ b/samples/client/petstore/go/go-petstore/docs/Dog.md @@ -3,9 +3,9 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**Breed** | **string** | | [optional] **ClassName** | **string** | | **Color** | **string** | | [optional] [default to red] -**Breed** | **string** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/go/go-petstore/model_cat.go b/samples/client/petstore/go/go-petstore/model_cat.go index 58b3deeb938..4c8b1bfe599 100644 --- a/samples/client/petstore/go/go-petstore/model_cat.go +++ b/samples/client/petstore/go/go-petstore/model_cat.go @@ -10,7 +10,7 @@ package petstore type Cat struct { + Declawed bool `json:"declawed,omitempty"` ClassName string `json:"className"` Color string `json:"color,omitempty"` - Declawed bool `json:"declawed,omitempty"` } diff --git a/samples/client/petstore/go/go-petstore/model_dog.go b/samples/client/petstore/go/go-petstore/model_dog.go index 3f791ca1947..dcd7d1d6353 100644 --- a/samples/client/petstore/go/go-petstore/model_dog.go +++ b/samples/client/petstore/go/go-petstore/model_dog.go @@ -10,7 +10,7 @@ package petstore type Dog struct { + Breed string `json:"breed,omitempty"` ClassName string `json:"className"` Color string `json:"color,omitempty"` - Breed string `json:"breed,omitempty"` } diff --git a/samples/client/petstore/haskell-http-client/lib/OpenAPIPetstore/Model.hs b/samples/client/petstore/haskell-http-client/lib/OpenAPIPetstore/Model.hs index 010abaab453..e8cb861e188 100644 --- a/samples/client/petstore/haskell-http-client/lib/OpenAPIPetstore/Model.hs +++ b/samples/client/petstore/haskell-http-client/lib/OpenAPIPetstore/Model.hs @@ -457,26 +457,26 @@ mkCapitalization = -- ** Cat -- | Cat data Cat = Cat - { catClassName :: !(Text) -- ^ /Required/ "className" + { catDeclawed :: !(Maybe Bool) -- ^ "declawed" + , catClassName :: !(Text) -- ^ /Required/ "className" , catColor :: !(Maybe Text) -- ^ "color" - , catDeclawed :: !(Maybe Bool) -- ^ "declawed" } deriving (P.Show, P.Eq, P.Typeable) -- | FromJSON Cat instance A.FromJSON Cat where parseJSON = A.withObject "Cat" $ \o -> Cat - <$> (o .: "className") + <$> (o .:? "declawed") + <*> (o .: "className") <*> (o .:? "color") - <*> (o .:? "declawed") -- | ToJSON Cat instance A.ToJSON Cat where toJSON Cat {..} = _omitNulls - [ "className" .= catClassName + [ "declawed" .= catDeclawed + , "className" .= catClassName , "color" .= catColor - , "declawed" .= catDeclawed ] @@ -486,9 +486,9 @@ mkCat -> Cat mkCat catClassName = Cat - { catClassName + { catDeclawed = Nothing + , catClassName , catColor = Nothing - , catDeclawed = Nothing } -- ** Category @@ -584,26 +584,26 @@ mkClient = -- ** Dog -- | Dog data Dog = Dog - { dogClassName :: !(Text) -- ^ /Required/ "className" + { dogBreed :: !(Maybe Text) -- ^ "breed" + , dogClassName :: !(Text) -- ^ /Required/ "className" , dogColor :: !(Maybe Text) -- ^ "color" - , dogBreed :: !(Maybe Text) -- ^ "breed" } deriving (P.Show, P.Eq, P.Typeable) -- | FromJSON Dog instance A.FromJSON Dog where parseJSON = A.withObject "Dog" $ \o -> Dog - <$> (o .: "className") + <$> (o .:? "breed") + <*> (o .: "className") <*> (o .:? "color") - <*> (o .:? "breed") -- | ToJSON Dog instance A.ToJSON Dog where toJSON Dog {..} = _omitNulls - [ "className" .= dogClassName + [ "breed" .= dogBreed + , "className" .= dogClassName , "color" .= dogColor - , "breed" .= dogBreed ] @@ -613,9 +613,9 @@ mkDog -> Dog mkDog dogClassName = Dog - { dogClassName + { dogBreed = Nothing + , dogClassName , dogColor = Nothing - , dogBreed = Nothing } -- ** EnumArrays @@ -1830,3 +1830,4 @@ instance AuthMethod AuthOAuthPetstoreAuth where & L.over rAuthTypesL (P.filter (/= P.typeOf a)) else req + diff --git a/samples/client/petstore/haskell-http-client/lib/OpenAPIPetstore/ModelLens.hs b/samples/client/petstore/haskell-http-client/lib/OpenAPIPetstore/ModelLens.hs index 0b8a2a84813..d1d6eb09dd9 100644 --- a/samples/client/petstore/haskell-http-client/lib/OpenAPIPetstore/ModelLens.hs +++ b/samples/client/petstore/haskell-http-client/lib/OpenAPIPetstore/ModelLens.hs @@ -156,6 +156,11 @@ capitalizationAttNameL f Capitalization{..} = (\capitalizationAttName -> Capital -- * Cat +-- | 'catDeclawed' Lens +catDeclawedL :: Lens_' Cat (Maybe Bool) +catDeclawedL f Cat{..} = (\catDeclawed -> Cat { catDeclawed, ..} ) <$> f catDeclawed +{-# INLINE catDeclawedL #-} + -- | 'catClassName' Lens catClassNameL :: Lens_' Cat (Text) catClassNameL f Cat{..} = (\catClassName -> Cat { catClassName, ..} ) <$> f catClassName @@ -166,11 +171,6 @@ catColorL :: Lens_' Cat (Maybe Text) catColorL f Cat{..} = (\catColor -> Cat { catColor, ..} ) <$> f catColor {-# INLINE catColorL #-} --- | 'catDeclawed' Lens -catDeclawedL :: Lens_' Cat (Maybe Bool) -catDeclawedL f Cat{..} = (\catDeclawed -> Cat { catDeclawed, ..} ) <$> f catDeclawed -{-# INLINE catDeclawedL #-} - -- * Category @@ -207,6 +207,11 @@ clientClientL f Client{..} = (\clientClient -> Client { clientClient, ..} ) <$> -- * Dog +-- | 'dogBreed' Lens +dogBreedL :: Lens_' Dog (Maybe Text) +dogBreedL f Dog{..} = (\dogBreed -> Dog { dogBreed, ..} ) <$> f dogBreed +{-# INLINE dogBreedL #-} + -- | 'dogClassName' Lens dogClassNameL :: Lens_' Dog (Text) dogClassNameL f Dog{..} = (\dogClassName -> Dog { dogClassName, ..} ) <$> f dogClassName @@ -217,11 +222,6 @@ dogColorL :: Lens_' Dog (Maybe Text) dogColorL f Dog{..} = (\dogColor -> Dog { dogColor, ..} ) <$> f dogColor {-# INLINE dogColorL #-} --- | 'dogBreed' Lens -dogBreedL :: Lens_' Dog (Maybe Text) -dogBreedL f Dog{..} = (\dogBreed -> Dog { dogBreed, ..} ) <$> f dogBreed -{-# INLINE dogBreedL #-} - -- * EnumArrays diff --git a/samples/client/petstore/haskell-http-client/tests/Instances.hs b/samples/client/petstore/haskell-http-client/tests/Instances.hs index 74830f44ba2..7e70cf71a95 100644 --- a/samples/client/petstore/haskell-http-client/tests/Instances.hs +++ b/samples/client/petstore/haskell-http-client/tests/Instances.hs @@ -138,9 +138,9 @@ instance Arbitrary Capitalization where instance Arbitrary Cat where arbitrary = Cat - <$> arbitrary -- catClassName :: Text + <$> arbitrary -- catDeclawed :: Maybe Bool + <*> arbitrary -- catClassName :: Text <*> arbitrary -- catColor :: Maybe Text - <*> arbitrary -- catDeclawed :: Maybe Bool instance Arbitrary Category where arbitrary = @@ -161,9 +161,9 @@ instance Arbitrary Client where instance Arbitrary Dog where arbitrary = Dog - <$> arbitrary -- dogClassName :: Text + <$> arbitrary -- dogBreed :: Maybe Text + <*> arbitrary -- dogClassName :: Text <*> arbitrary -- dogColor :: Maybe Text - <*> arbitrary -- dogBreed :: Maybe Text instance Arbitrary EnumArrays where arbitrary = diff --git a/samples/client/petstore/java/google-api-client/docs/MapTest.md b/samples/client/petstore/java/google-api-client/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/google-api-client/docs/MapTest.md +++ b/samples/client/petstore/java/google-api-client/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/jersey1/docs/MapTest.md b/samples/client/petstore/java/jersey1/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/jersey1/docs/MapTest.md +++ b/samples/client/petstore/java/jersey1/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/jersey2-java6/docs/MapTest.md b/samples/client/petstore/java/jersey2-java6/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/jersey2-java6/docs/MapTest.md +++ b/samples/client/petstore/java/jersey2-java6/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/jersey2-java8/docs/MapTest.md b/samples/client/petstore/java/jersey2-java8/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/jersey2-java8/docs/MapTest.md +++ b/samples/client/petstore/java/jersey2-java8/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/jersey2/docs/MapTest.md b/samples/client/petstore/java/jersey2/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/jersey2/docs/MapTest.md +++ b/samples/client/petstore/java/jersey2/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/MapTest.md b/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/MapTest.md +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/okhttp-gson/docs/MapTest.md b/samples/client/petstore/java/okhttp-gson/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/okhttp-gson/docs/MapTest.md +++ b/samples/client/petstore/java/okhttp-gson/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/rest-assured/docs/MapTest.md b/samples/client/petstore/java/rest-assured/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/rest-assured/docs/MapTest.md +++ b/samples/client/petstore/java/rest-assured/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/resteasy/docs/MapTest.md b/samples/client/petstore/java/resteasy/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/resteasy/docs/MapTest.md +++ b/samples/client/petstore/java/resteasy/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/resttemplate-withXml/docs/MapTest.md b/samples/client/petstore/java/resttemplate-withXml/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/resttemplate-withXml/docs/MapTest.md +++ b/samples/client/petstore/java/resttemplate-withXml/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/resttemplate/docs/MapTest.md b/samples/client/petstore/java/resttemplate/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/resttemplate/docs/MapTest.md +++ b/samples/client/petstore/java/resttemplate/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/retrofit2-play24/docs/MapTest.md b/samples/client/petstore/java/retrofit2-play24/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/retrofit2-play24/docs/MapTest.md +++ b/samples/client/petstore/java/retrofit2-play24/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/retrofit2-play25/docs/MapTest.md b/samples/client/petstore/java/retrofit2-play25/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/retrofit2-play25/docs/MapTest.md +++ b/samples/client/petstore/java/retrofit2-play25/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/retrofit2-play26/docs/MapTest.md b/samples/client/petstore/java/retrofit2-play26/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/retrofit2-play26/docs/MapTest.md +++ b/samples/client/petstore/java/retrofit2-play26/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/retrofit2/docs/MapTest.md b/samples/client/petstore/java/retrofit2/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/retrofit2/docs/MapTest.md +++ b/samples/client/petstore/java/retrofit2/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/retrofit2rx/docs/MapTest.md b/samples/client/petstore/java/retrofit2rx/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/retrofit2rx/docs/MapTest.md +++ b/samples/client/petstore/java/retrofit2rx/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/retrofit2rx2/docs/MapTest.md b/samples/client/petstore/java/retrofit2rx2/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/retrofit2rx2/docs/MapTest.md +++ b/samples/client/petstore/java/retrofit2rx2/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/vertx/docs/MapTest.md b/samples/client/petstore/java/vertx/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/vertx/docs/MapTest.md +++ b/samples/client/petstore/java/vertx/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/java/webclient/docs/MapTest.md b/samples/client/petstore/java/webclient/docs/MapTest.md index c8387ad9af2..19f3e2993c7 100644 --- a/samples/client/petstore/java/webclient/docs/MapTest.md +++ b/samples/client/petstore/java/webclient/docs/MapTest.md @@ -14,8 +14,6 @@ Name | Type | Description | Notes ## Enum: Map<String, InnerEnum> Name | Value ---- | ----- -UPPER | "UPPER" -LOWER | "lower" diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/MapTest.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/MapTest.php index 4f24eb7b46f..7b3c55958f8 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/MapTest.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/MapTest.php @@ -173,8 +173,6 @@ class MapTest implements ModelInterface, ArrayAccess return self::$openAPIModelName; } - const MAP_OF_ENUM_STRING_UPPER = 'UPPER'; - const MAP_OF_ENUM_STRING_LOWER = 'lower'; @@ -186,8 +184,7 @@ class MapTest implements ModelInterface, ArrayAccess public function getMapOfEnumStringAllowableValues() { return [ - self::MAP_OF_ENUM_STRING_UPPER, - self::MAP_OF_ENUM_STRING_LOWER, + ]; } diff --git a/samples/client/petstore/ruby/docs/Cat.md b/samples/client/petstore/ruby/docs/Cat.md index d0fc50e4da8..d41bb3660ce 100644 --- a/samples/client/petstore/ruby/docs/Cat.md +++ b/samples/client/petstore/ruby/docs/Cat.md @@ -3,8 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**declawed** | **BOOLEAN** | | [optional] **class_name** | **String** | | **color** | **String** | | [optional] [default to 'red'] -**declawed** | **BOOLEAN** | | [optional] diff --git a/samples/client/petstore/ruby/docs/Dog.md b/samples/client/petstore/ruby/docs/Dog.md index 1e66990d593..0c73ff3baff 100644 --- a/samples/client/petstore/ruby/docs/Dog.md +++ b/samples/client/petstore/ruby/docs/Dog.md @@ -3,8 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**breed** | **String** | | [optional] **class_name** | **String** | | **color** | **String** | | [optional] [default to 'red'] -**breed** | **String** | | [optional] diff --git a/samples/client/petstore/ruby/lib/petstore/models/additional_properties_class.rb b/samples/client/petstore/ruby/lib/petstore/models/additional_properties_class.rb index 14bbd6ce1bb..6b716e0fa3d 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/additional_properties_class.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/additional_properties_class.rb @@ -192,5 +192,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/animal.rb b/samples/client/petstore/ruby/lib/petstore/models/animal.rb index bf0434c32f6..b82f4d6de05 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/animal.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/animal.rb @@ -34,6 +34,11 @@ module Petstore } end + # discriminator's property name in OpenAPI v3 + def self.openapi_discriminator_name + :'className' + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -195,5 +200,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/api_response.rb b/samples/client/petstore/ruby/lib/petstore/models/api_response.rb index 98cd00426ec..7b3e9eeae23 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/api_response.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/api_response.rb @@ -197,5 +197,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/array_of_array_of_number_only.rb b/samples/client/petstore/ruby/lib/petstore/models/array_of_array_of_number_only.rb index 997b7d76013..75605c56bd5 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/array_of_array_of_number_only.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/array_of_array_of_number_only.rb @@ -181,5 +181,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/array_of_number_only.rb b/samples/client/petstore/ruby/lib/petstore/models/array_of_number_only.rb index c5305f99ed9..22f04b5b925 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/array_of_number_only.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/array_of_number_only.rb @@ -181,5 +181,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/array_test.rb b/samples/client/petstore/ruby/lib/petstore/models/array_test.rb index 064ba67475d..e37a54fdecc 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/array_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/array_test.rb @@ -203,5 +203,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/capitalization.rb b/samples/client/petstore/ruby/lib/petstore/models/capitalization.rb index 67131328f2d..9be52e89ff0 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/capitalization.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/capitalization.rb @@ -225,5 +225,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/cat.rb b/samples/client/petstore/ruby/lib/petstore/models/cat.rb index d2cb1452eef..300da74d361 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/cat.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/cat.rb @@ -13,31 +13,38 @@ OpenAPI Generator version: 4.0.0-SNAPSHOT require 'date' module Petstore - class Cat + class Cat < Animal + attr_accessor :declawed + attr_accessor :class_name attr_accessor :color - attr_accessor :declawed - # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { + :'declawed' => :'declawed', :'class_name' => :'className', - :'color' => :'color', - :'declawed' => :'declawed' + :'color' => :'color' } end # Attribute type mapping. def self.openapi_types { + :'declawed' => :'BOOLEAN', :'class_name' => :'String', - :'color' => :'String', - :'declawed' => :'BOOLEAN' + :'color' => :'String' } end + # List of class defined in allOf (OpenAPI v3) + def self.openapi_all_of + [ + :'Animal' + ] + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -46,6 +53,13 @@ module Petstore # convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } + # call parent's initialize + super(attributes) + + if attributes.has_key?(:'declawed') + self.declawed = attributes[:'declawed'] + end + if attributes.has_key?(:'className') self.class_name = attributes[:'className'] end @@ -55,16 +69,12 @@ module Petstore else self.color = 'red' end - - if attributes.has_key?(:'declawed') - self.declawed = attributes[:'declawed'] - end end # Show invalid properties with the reasons. Usually used together with valid? # @return Array for valid properties with the reasons def list_invalid_properties - invalid_properties = Array.new + invalid_properties = super if @class_name.nil? invalid_properties.push('invalid value for "class_name", class_name cannot be nil.') end @@ -76,7 +86,7 @@ module Petstore # @return true if the model is valid def valid? return false if @class_name.nil? - true + true && super end # Checks equality by comparing each attribute. @@ -84,9 +94,9 @@ module Petstore def ==(o) return true if self.equal?(o) self.class == o.class && + declawed == o.declawed && class_name == o.class_name && - color == o.color && - declawed == o.declawed + color == o.color && super(o) end # @see the `==` method @@ -98,7 +108,7 @@ module Petstore # Calculates hash code according to all attributes. # @return [Fixnum] Hash code def hash - [class_name, color, declawed].hash + [declawed, class_name, color].hash end # Builds the object from hash @@ -106,6 +116,7 @@ module Petstore # @return [Object] Returns the model itself def build_from_hash(attributes) return nil unless attributes.is_a?(Hash) + super(attributes) self.class.openapi_types.each_pair do |key, type| if type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the the attribute @@ -178,7 +189,7 @@ module Petstore # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = {} + hash = super self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) next if value.nil? @@ -204,5 +215,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/category.rb b/samples/client/petstore/ruby/lib/petstore/models/category.rb index 11638f01077..a00d2e34927 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/category.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/category.rb @@ -195,5 +195,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/class_model.rb b/samples/client/petstore/ruby/lib/petstore/models/class_model.rb index f946ed55be0..013dfc01e5b 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/class_model.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/class_model.rb @@ -180,5 +180,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/client.rb b/samples/client/petstore/ruby/lib/petstore/models/client.rb index eb11c6e587e..e3e84e1d86c 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/client.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/client.rb @@ -179,5 +179,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/dog.rb b/samples/client/petstore/ruby/lib/petstore/models/dog.rb index 49a8866a3b9..ea62445687e 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/dog.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/dog.rb @@ -13,31 +13,38 @@ OpenAPI Generator version: 4.0.0-SNAPSHOT require 'date' module Petstore - class Dog + class Dog < Animal + attr_accessor :breed + attr_accessor :class_name attr_accessor :color - attr_accessor :breed - # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { + :'breed' => :'breed', :'class_name' => :'className', - :'color' => :'color', - :'breed' => :'breed' + :'color' => :'color' } end # Attribute type mapping. def self.openapi_types { + :'breed' => :'String', :'class_name' => :'String', - :'color' => :'String', - :'breed' => :'String' + :'color' => :'String' } end + # List of class defined in allOf (OpenAPI v3) + def self.openapi_all_of + [ + :'Animal' + ] + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -46,6 +53,13 @@ module Petstore # convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } + # call parent's initialize + super(attributes) + + if attributes.has_key?(:'breed') + self.breed = attributes[:'breed'] + end + if attributes.has_key?(:'className') self.class_name = attributes[:'className'] end @@ -55,16 +69,12 @@ module Petstore else self.color = 'red' end - - if attributes.has_key?(:'breed') - self.breed = attributes[:'breed'] - end end # Show invalid properties with the reasons. Usually used together with valid? # @return Array for valid properties with the reasons def list_invalid_properties - invalid_properties = Array.new + invalid_properties = super if @class_name.nil? invalid_properties.push('invalid value for "class_name", class_name cannot be nil.') end @@ -76,7 +86,7 @@ module Petstore # @return true if the model is valid def valid? return false if @class_name.nil? - true + true && super end # Checks equality by comparing each attribute. @@ -84,9 +94,9 @@ module Petstore def ==(o) return true if self.equal?(o) self.class == o.class && + breed == o.breed && class_name == o.class_name && - color == o.color && - breed == o.breed + color == o.color && super(o) end # @see the `==` method @@ -98,7 +108,7 @@ module Petstore # Calculates hash code according to all attributes. # @return [Fixnum] Hash code def hash - [class_name, color, breed].hash + [breed, class_name, color].hash end # Builds the object from hash @@ -106,6 +116,7 @@ module Petstore # @return [Object] Returns the model itself def build_from_hash(attributes) return nil unless attributes.is_a?(Hash) + super(attributes) self.class.openapi_types.each_pair do |key, type| if type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the the attribute @@ -178,7 +189,7 @@ module Petstore # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = {} + hash = super self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) next if value.nil? @@ -204,5 +215,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/enum_arrays.rb b/samples/client/petstore/ruby/lib/petstore/models/enum_arrays.rb index 16a31ed6437..d870963ab7e 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/enum_arrays.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/enum_arrays.rb @@ -224,5 +224,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/enum_test.rb b/samples/client/petstore/ruby/lib/petstore/models/enum_test.rb index d0828881c03..b66bdd16472 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/enum_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/enum_test.rb @@ -290,5 +290,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/file.rb b/samples/client/petstore/ruby/lib/petstore/models/file.rb index 9a242c87642..473eb78e06d 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/file.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/file.rb @@ -181,5 +181,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/file_schema_test_class.rb b/samples/client/petstore/ruby/lib/petstore/models/file_schema_test_class.rb index 15b1abc488a..43619c4d00c 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/file_schema_test_class.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/file_schema_test_class.rb @@ -190,5 +190,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/format_test.rb b/samples/client/petstore/ruby/lib/petstore/models/format_test.rb index 4dff547a851..0d1bc02ddda 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/format_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/format_test.rb @@ -493,5 +493,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/has_only_read_only.rb b/samples/client/petstore/ruby/lib/petstore/models/has_only_read_only.rb index 2a34807da79..272a53c53f2 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/has_only_read_only.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/has_only_read_only.rb @@ -188,5 +188,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/list.rb b/samples/client/petstore/ruby/lib/petstore/models/list.rb index 5edff2ea014..d0399fb4bd4 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/list.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/list.rb @@ -179,5 +179,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/map_test.rb b/samples/client/petstore/ruby/lib/petstore/models/map_test.rb index 6d3f5f5f8eb..02f17237f70 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/map_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/map_test.rb @@ -236,5 +236,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/mixed_properties_and_additional_properties_class.rb b/samples/client/petstore/ruby/lib/petstore/models/mixed_properties_and_additional_properties_class.rb index b65eeb0be55..35e069618c0 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/mixed_properties_and_additional_properties_class.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/mixed_properties_and_additional_properties_class.rb @@ -199,5 +199,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/model200_response.rb b/samples/client/petstore/ruby/lib/petstore/models/model200_response.rb index 52dd2ab76cd..b1321c3ffae 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/model200_response.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/model200_response.rb @@ -189,5 +189,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/model_return.rb b/samples/client/petstore/ruby/lib/petstore/models/model_return.rb index ab24fe326f8..d573b9ea9af 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/model_return.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/model_return.rb @@ -180,5 +180,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/name.rb b/samples/client/petstore/ruby/lib/petstore/models/name.rb index 75aeab463e0..98aab8f78f4 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/name.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/name.rb @@ -212,5 +212,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/number_only.rb b/samples/client/petstore/ruby/lib/petstore/models/number_only.rb index e5d95d4d2e6..1e7e626cd17 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/number_only.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/number_only.rb @@ -179,5 +179,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/order.rb b/samples/client/petstore/ruby/lib/petstore/models/order.rb index 5c47cda94c5..11f9f4c3710 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/order.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/order.rb @@ -261,5 +261,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/outer_composite.rb b/samples/client/petstore/ruby/lib/petstore/models/outer_composite.rb index 5098b8e8cd3..230bc670767 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/outer_composite.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/outer_composite.rb @@ -197,5 +197,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/pet.rb b/samples/client/petstore/ruby/lib/petstore/models/pet.rb index 653c84dcc5c..183f2d9b7ba 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/pet.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/pet.rb @@ -273,5 +273,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/read_only_first.rb b/samples/client/petstore/ruby/lib/petstore/models/read_only_first.rb index 45bd488b6d0..a181f9a0a9e 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/read_only_first.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/read_only_first.rb @@ -188,5 +188,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/special_model_name.rb b/samples/client/petstore/ruby/lib/petstore/models/special_model_name.rb index 5e6428da39e..2ed4335bef2 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/special_model_name.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/special_model_name.rb @@ -179,5 +179,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/tag.rb b/samples/client/petstore/ruby/lib/petstore/models/tag.rb index 8361c631d48..e160a1de275 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/tag.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/tag.rb @@ -188,5 +188,7 @@ module Petstore value end end + end + end diff --git a/samples/client/petstore/ruby/lib/petstore/models/user.rb b/samples/client/petstore/ruby/lib/petstore/models/user.rb index 23aeb5d3d33..2c2e0402db5 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/user.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/user.rb @@ -243,5 +243,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Model/MapTest.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Model/MapTest.php index 4f24eb7b46f..7b3c55958f8 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Model/MapTest.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Model/MapTest.php @@ -173,8 +173,6 @@ class MapTest implements ModelInterface, ArrayAccess return self::$openAPIModelName; } - const MAP_OF_ENUM_STRING_UPPER = 'UPPER'; - const MAP_OF_ENUM_STRING_LOWER = 'lower'; @@ -186,8 +184,7 @@ class MapTest implements ModelInterface, ArrayAccess public function getMapOfEnumStringAllowableValues() { return [ - self::MAP_OF_ENUM_STRING_UPPER, - self::MAP_OF_ENUM_STRING_LOWER, + ]; } diff --git a/samples/openapi3/client/petstore/ruby/docs/Cat.md b/samples/openapi3/client/petstore/ruby/docs/Cat.md index d0fc50e4da8..d41bb3660ce 100644 --- a/samples/openapi3/client/petstore/ruby/docs/Cat.md +++ b/samples/openapi3/client/petstore/ruby/docs/Cat.md @@ -3,8 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**declawed** | **BOOLEAN** | | [optional] **class_name** | **String** | | **color** | **String** | | [optional] [default to 'red'] -**declawed** | **BOOLEAN** | | [optional] diff --git a/samples/openapi3/client/petstore/ruby/docs/Dog.md b/samples/openapi3/client/petstore/ruby/docs/Dog.md index 1e66990d593..0c73ff3baff 100644 --- a/samples/openapi3/client/petstore/ruby/docs/Dog.md +++ b/samples/openapi3/client/petstore/ruby/docs/Dog.md @@ -3,8 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**breed** | **String** | | [optional] **class_name** | **String** | | **color** | **String** | | [optional] [default to 'red'] -**breed** | **String** | | [optional] diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/additional_properties_class.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/additional_properties_class.rb index 14bbd6ce1bb..6b716e0fa3d 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/additional_properties_class.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/additional_properties_class.rb @@ -192,5 +192,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/animal.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/animal.rb index bf0434c32f6..b82f4d6de05 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/animal.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/animal.rb @@ -34,6 +34,11 @@ module Petstore } end + # discriminator's property name in OpenAPI v3 + def self.openapi_discriminator_name + :'className' + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -195,5 +200,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/api_response.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/api_response.rb index 98cd00426ec..7b3e9eeae23 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/api_response.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/api_response.rb @@ -197,5 +197,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/array_of_array_of_number_only.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/array_of_array_of_number_only.rb index 997b7d76013..75605c56bd5 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/array_of_array_of_number_only.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/array_of_array_of_number_only.rb @@ -181,5 +181,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/array_of_number_only.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/array_of_number_only.rb index c5305f99ed9..22f04b5b925 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/array_of_number_only.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/array_of_number_only.rb @@ -181,5 +181,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/array_test.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/array_test.rb index 064ba67475d..e37a54fdecc 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/array_test.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/array_test.rb @@ -203,5 +203,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/capitalization.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/capitalization.rb index 67131328f2d..9be52e89ff0 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/capitalization.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/capitalization.rb @@ -225,5 +225,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/cat.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/cat.rb index d2cb1452eef..300da74d361 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/cat.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/cat.rb @@ -13,31 +13,38 @@ OpenAPI Generator version: 4.0.0-SNAPSHOT require 'date' module Petstore - class Cat + class Cat < Animal + attr_accessor :declawed + attr_accessor :class_name attr_accessor :color - attr_accessor :declawed - # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { + :'declawed' => :'declawed', :'class_name' => :'className', - :'color' => :'color', - :'declawed' => :'declawed' + :'color' => :'color' } end # Attribute type mapping. def self.openapi_types { + :'declawed' => :'BOOLEAN', :'class_name' => :'String', - :'color' => :'String', - :'declawed' => :'BOOLEAN' + :'color' => :'String' } end + # List of class defined in allOf (OpenAPI v3) + def self.openapi_all_of + [ + :'Animal' + ] + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -46,6 +53,13 @@ module Petstore # convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } + # call parent's initialize + super(attributes) + + if attributes.has_key?(:'declawed') + self.declawed = attributes[:'declawed'] + end + if attributes.has_key?(:'className') self.class_name = attributes[:'className'] end @@ -55,16 +69,12 @@ module Petstore else self.color = 'red' end - - if attributes.has_key?(:'declawed') - self.declawed = attributes[:'declawed'] - end end # Show invalid properties with the reasons. Usually used together with valid? # @return Array for valid properties with the reasons def list_invalid_properties - invalid_properties = Array.new + invalid_properties = super if @class_name.nil? invalid_properties.push('invalid value for "class_name", class_name cannot be nil.') end @@ -76,7 +86,7 @@ module Petstore # @return true if the model is valid def valid? return false if @class_name.nil? - true + true && super end # Checks equality by comparing each attribute. @@ -84,9 +94,9 @@ module Petstore def ==(o) return true if self.equal?(o) self.class == o.class && + declawed == o.declawed && class_name == o.class_name && - color == o.color && - declawed == o.declawed + color == o.color && super(o) end # @see the `==` method @@ -98,7 +108,7 @@ module Petstore # Calculates hash code according to all attributes. # @return [Fixnum] Hash code def hash - [class_name, color, declawed].hash + [declawed, class_name, color].hash end # Builds the object from hash @@ -106,6 +116,7 @@ module Petstore # @return [Object] Returns the model itself def build_from_hash(attributes) return nil unless attributes.is_a?(Hash) + super(attributes) self.class.openapi_types.each_pair do |key, type| if type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the the attribute @@ -178,7 +189,7 @@ module Petstore # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = {} + hash = super self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) next if value.nil? @@ -204,5 +215,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/category.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/category.rb index 11638f01077..a00d2e34927 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/category.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/category.rb @@ -195,5 +195,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/class_model.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/class_model.rb index f946ed55be0..013dfc01e5b 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/class_model.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/class_model.rb @@ -180,5 +180,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/client.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/client.rb index eb11c6e587e..e3e84e1d86c 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/client.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/client.rb @@ -179,5 +179,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/dog.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/dog.rb index 49a8866a3b9..ea62445687e 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/dog.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/dog.rb @@ -13,31 +13,38 @@ OpenAPI Generator version: 4.0.0-SNAPSHOT require 'date' module Petstore - class Dog + class Dog < Animal + attr_accessor :breed + attr_accessor :class_name attr_accessor :color - attr_accessor :breed - # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { + :'breed' => :'breed', :'class_name' => :'className', - :'color' => :'color', - :'breed' => :'breed' + :'color' => :'color' } end # Attribute type mapping. def self.openapi_types { + :'breed' => :'String', :'class_name' => :'String', - :'color' => :'String', - :'breed' => :'String' + :'color' => :'String' } end + # List of class defined in allOf (OpenAPI v3) + def self.openapi_all_of + [ + :'Animal' + ] + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -46,6 +53,13 @@ module Petstore # convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v } + # call parent's initialize + super(attributes) + + if attributes.has_key?(:'breed') + self.breed = attributes[:'breed'] + end + if attributes.has_key?(:'className') self.class_name = attributes[:'className'] end @@ -55,16 +69,12 @@ module Petstore else self.color = 'red' end - - if attributes.has_key?(:'breed') - self.breed = attributes[:'breed'] - end end # Show invalid properties with the reasons. Usually used together with valid? # @return Array for valid properties with the reasons def list_invalid_properties - invalid_properties = Array.new + invalid_properties = super if @class_name.nil? invalid_properties.push('invalid value for "class_name", class_name cannot be nil.') end @@ -76,7 +86,7 @@ module Petstore # @return true if the model is valid def valid? return false if @class_name.nil? - true + true && super end # Checks equality by comparing each attribute. @@ -84,9 +94,9 @@ module Petstore def ==(o) return true if self.equal?(o) self.class == o.class && + breed == o.breed && class_name == o.class_name && - color == o.color && - breed == o.breed + color == o.color && super(o) end # @see the `==` method @@ -98,7 +108,7 @@ module Petstore # Calculates hash code according to all attributes. # @return [Fixnum] Hash code def hash - [class_name, color, breed].hash + [breed, class_name, color].hash end # Builds the object from hash @@ -106,6 +116,7 @@ module Petstore # @return [Object] Returns the model itself def build_from_hash(attributes) return nil unless attributes.is_a?(Hash) + super(attributes) self.class.openapi_types.each_pair do |key, type| if type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the the attribute @@ -178,7 +189,7 @@ module Petstore # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = {} + hash = super self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) next if value.nil? @@ -204,5 +215,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/enum_arrays.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/enum_arrays.rb index 16a31ed6437..d870963ab7e 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/enum_arrays.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/enum_arrays.rb @@ -224,5 +224,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/enum_test.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/enum_test.rb index d0828881c03..b66bdd16472 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/enum_test.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/enum_test.rb @@ -290,5 +290,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/file.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/file.rb index 9a242c87642..473eb78e06d 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/file.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/file.rb @@ -181,5 +181,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/file_schema_test_class.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/file_schema_test_class.rb index 15b1abc488a..43619c4d00c 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/file_schema_test_class.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/file_schema_test_class.rb @@ -190,5 +190,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/foo.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/foo.rb index 6c353572556..1d722410923 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/foo.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/foo.rb @@ -181,5 +181,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/format_test.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/format_test.rb index ea892a9ce0a..a1bab83fc89 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/format_test.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/format_test.rb @@ -524,5 +524,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/has_only_read_only.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/has_only_read_only.rb index 2a34807da79..272a53c53f2 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/has_only_read_only.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/has_only_read_only.rb @@ -188,5 +188,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/inline_response_default.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/inline_response_default.rb index 07c5d8adda0..5d4ac11be7e 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/inline_response_default.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/inline_response_default.rb @@ -179,5 +179,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/list.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/list.rb index 5edff2ea014..d0399fb4bd4 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/list.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/list.rb @@ -179,5 +179,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/map_test.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/map_test.rb index 6d3f5f5f8eb..02f17237f70 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/map_test.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/map_test.rb @@ -236,5 +236,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/mixed_properties_and_additional_properties_class.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/mixed_properties_and_additional_properties_class.rb index b65eeb0be55..35e069618c0 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/mixed_properties_and_additional_properties_class.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/mixed_properties_and_additional_properties_class.rb @@ -199,5 +199,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/model200_response.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/model200_response.rb index 52dd2ab76cd..b1321c3ffae 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/model200_response.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/model200_response.rb @@ -189,5 +189,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/model_return.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/model_return.rb index ab24fe326f8..d573b9ea9af 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/model_return.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/model_return.rb @@ -180,5 +180,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/name.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/name.rb index 75aeab463e0..98aab8f78f4 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/name.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/name.rb @@ -212,5 +212,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/number_only.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/number_only.rb index e5d95d4d2e6..1e7e626cd17 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/number_only.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/number_only.rb @@ -179,5 +179,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/order.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/order.rb index 5c47cda94c5..11f9f4c3710 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/order.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/order.rb @@ -261,5 +261,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/outer_composite.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/outer_composite.rb index 5098b8e8cd3..230bc670767 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/outer_composite.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/outer_composite.rb @@ -197,5 +197,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/pet.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/pet.rb index 653c84dcc5c..183f2d9b7ba 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/pet.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/pet.rb @@ -273,5 +273,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/read_only_first.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/read_only_first.rb index 45bd488b6d0..a181f9a0a9e 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/read_only_first.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/read_only_first.rb @@ -188,5 +188,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/special_model_name.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/special_model_name.rb index 5e6428da39e..2ed4335bef2 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/special_model_name.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/special_model_name.rb @@ -179,5 +179,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/tag.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/tag.rb index 8361c631d48..e160a1de275 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/tag.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/tag.rb @@ -188,5 +188,7 @@ module Petstore value end end + end + end diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/models/user.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/models/user.rb index 23aeb5d3d33..2c2e0402db5 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/models/user.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/models/user.rb @@ -243,5 +243,7 @@ module Petstore value end end + end + end diff --git a/samples/schema/petstore/mysql/mysql_schema.sql b/samples/schema/petstore/mysql/mysql_schema.sql index 5870b90fab9..f9db1a3f09a 100644 --- a/samples/schema/petstore/mysql/mysql_schema.sql +++ b/samples/schema/petstore/mysql/mysql_schema.sql @@ -95,9 +95,9 @@ CREATE TABLE IF NOT EXISTS `Capitalization` ( -- CREATE TABLE IF NOT EXISTS `Cat` ( + `declawed` TINYINT(1) DEFAULT NULL, `className` TEXT NOT NULL, - `color` TEXT, - `declawed` TINYINT(1) DEFAULT NULL + `color` TEXT ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- @@ -131,9 +131,9 @@ CREATE TABLE IF NOT EXISTS `Client` ( -- CREATE TABLE IF NOT EXISTS `Dog` ( + `breed` TEXT DEFAULT NULL, `className` TEXT NOT NULL, - `color` TEXT, - `breed` TEXT DEFAULT NULL + `color` TEXT ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- diff --git a/samples/server/petstore/php-slim/lib/Model/Cat.php b/samples/server/petstore/php-slim/lib/Model/Cat.php index 9a800c02979..8f7b6cd9b00 100644 --- a/samples/server/petstore/php-slim/lib/Model/Cat.php +++ b/samples/server/petstore/php-slim/lib/Model/Cat.php @@ -10,12 +10,12 @@ namespace OpenAPIServer\Model; class Cat { + /** @var bool $declawed */ + private $declawed; + /** @var string $className */ private $className; /** @var string $color */ private $color; - - /** @var bool $declawed */ - private $declawed; } diff --git a/samples/server/petstore/php-slim/lib/Model/Dog.php b/samples/server/petstore/php-slim/lib/Model/Dog.php index 2af41c927e4..183cc27b6d5 100644 --- a/samples/server/petstore/php-slim/lib/Model/Dog.php +++ b/samples/server/petstore/php-slim/lib/Model/Dog.php @@ -10,12 +10,12 @@ namespace OpenAPIServer\Model; class Dog { + /** @var string $breed */ + private $breed; + /** @var string $className */ private $className; /** @var string $color */ private $color; - - /** @var string $breed */ - private $breed; } diff --git a/samples/server/petstore/php-ze-ph/src/App/DTO/Cat.php b/samples/server/petstore/php-ze-ph/src/App/DTO/Cat.php index e1596de8ede..006c072a855 100644 --- a/samples/server/petstore/php-ze-ph/src/App/DTO/Cat.php +++ b/samples/server/petstore/php-ze-ph/src/App/DTO/Cat.php @@ -8,6 +8,12 @@ use Articus\DataTransfer\Annotation as DTA; */ class Cat { + /** + * @DTA\Data(field="declawed", nullable=true) + * @DTA\Validator(name="Type", options={"type":"bool"}) + * @var bool + */ + public $declawed; /** * @DTA\Data(field="className") * @DTA\Validator(name="Type", options={"type":"string"}) @@ -20,10 +26,4 @@ class Cat * @var string */ public $color; - /** - * @DTA\Data(field="declawed", nullable=true) - * @DTA\Validator(name="Type", options={"type":"bool"}) - * @var bool - */ - public $declawed; } diff --git a/samples/server/petstore/php-ze-ph/src/App/DTO/Dog.php b/samples/server/petstore/php-ze-ph/src/App/DTO/Dog.php index 74482a9a33e..0c5417d5b50 100644 --- a/samples/server/petstore/php-ze-ph/src/App/DTO/Dog.php +++ b/samples/server/petstore/php-ze-ph/src/App/DTO/Dog.php @@ -8,6 +8,12 @@ use Articus\DataTransfer\Annotation as DTA; */ class Dog { + /** + * @DTA\Data(field="breed", nullable=true) + * @DTA\Validator(name="Type", options={"type":"string"}) + * @var string + */ + public $breed; /** * @DTA\Data(field="className") * @DTA\Validator(name="Type", options={"type":"string"}) @@ -20,10 +26,4 @@ class Dog * @var string */ public $color; - /** - * @DTA\Data(field="breed", nullable=true) - * @DTA\Validator(name="Type", options={"type":"string"}) - * @var string - */ - public $breed; } diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs index 0daa05e4dbf..640a8773dd2 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs @@ -185,6 +185,10 @@ impl Capitalization { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Cat { + #[serde(rename = "declawed")] + #[serde(skip_serializing_if="Option::is_none")] + pub declawed: Option, + #[serde(rename = "className")] pub class_name: String, @@ -192,18 +196,14 @@ pub struct Cat { #[serde(skip_serializing_if="Option::is_none")] pub color: Option, - #[serde(rename = "declawed")] - #[serde(skip_serializing_if="Option::is_none")] - pub declawed: Option, - } impl Cat { pub fn new(class_name: String, ) -> Cat { Cat { + declawed: None, class_name: class_name, color: Some("red".to_string()), - declawed: None, } } } @@ -265,6 +265,10 @@ impl Client { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Dog { + #[serde(rename = "breed")] + #[serde(skip_serializing_if="Option::is_none")] + pub breed: Option, + #[serde(rename = "className")] pub class_name: String, @@ -272,18 +276,14 @@ pub struct Dog { #[serde(skip_serializing_if="Option::is_none")] pub color: Option, - #[serde(rename = "breed")] - #[serde(skip_serializing_if="Option::is_none")] - pub breed: Option, - } impl Dog { pub fn new(class_name: String, ) -> Dog { Dog { + breed: None, class_name: class_name, color: Some("red".to_string()), - breed: None, } } }