Better OpenAPI spec v3 support: allOf, anyOf, oneOf (#1360)

* add oneOf support to Ruby

* add anyOf support to ruby client

* add discriminator support to ruby client

* fix typo

* update samples, fix NPE

* better format in ruby generator

* fix test cases, disable mapping test

* fix update script, update samples

* add test, fix mapping

* update exit code

* reenabled discriminator test

* remove duplicated properties

* add test for duplicated properties

* update samples, add new spec

* fix ruby test cases

* fix hasMore after removing duplicates

* refactor method, comment out haskell client test

* fix hasMore and update samples

* fix parent detection

* fix discriminator check

* [haskell-http-client] need to use {{vars}}{{required}} instead of {{requiredVars}}

* remove deprecated methods in default codegen (#1031)

* regenerate samples

* remove commented code
This commit is contained in:
William Cheng 2018-12-07 00:30:20 +08:00 committed by GitHub
parent c0634ac213
commit 774013c7e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
125 changed files with 1108 additions and 327 deletions

3
.gitignore vendored
View File

@ -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

View File

@ -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();
}
}

View File

@ -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<CodegenModel> interfaceModels;
public List<CodegenModel> children;
// anyOf, oneOf, allOf
public Set<String> anyOf = new TreeSet<String>();
public Set<String> oneOf = new TreeSet<String>();
public Set<String> allOf = new TreeSet<String>();
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<CodegenProperty> optionalVars = new ArrayList<CodegenProperty>(); // a list of optional properties
public List<CodegenProperty> readOnlyVars = new ArrayList<CodegenProperty>(); // a list of read-only properties
public List<CodegenProperty> readWriteVars = new ArrayList<CodegenProperty>(); // a list of properties for read, write
public List<CodegenProperty> allVars;
public List<CodegenProperty> parentVars = new ArrayList<>();
public List<CodegenProperty> allVars = new ArrayList<CodegenProperty>();
public List<CodegenProperty> parentVars = new ArrayList<CodegenProperty>();
public Map<String, Object> 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<CodegenProperty> removeDuplicatedProperty(List<CodegenProperty> vars) {
// clone the list first
List<CodegenProperty> newList = new ArrayList<CodegenProperty>();
for (CodegenProperty cp : vars) {
newList.add(cp.clone());
}
Set<String> propertyNames = new TreeSet<String>();
Set<String> duplicatedNames = new TreeSet<String>();
ListIterator<CodegenProperty> 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<CodegenProperty> 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;
}
}
}
}
}

View File

@ -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<String, Object>(this.vendorExtensions);
}
return cp;
} catch (CloneNotSupportedException e) {
throw new IllegalStateException(e);
@ -817,4 +814,6 @@ public class CodegenProperty implements Cloneable {
", isXmlWrapped=" + isXmlWrapped +
'}';
}
}

View File

@ -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<Schema> 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<String> names = new ArrayList<String>();
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<String> names = new ArrayList<String>();
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<String, Schema> properties = new LinkedHashMap<String, Schema>();
List<String> required = new ArrayList<String>();
Map<String, Schema> allProperties;
List<String> allRequired;
Map<String, Schema> allProperties = new LinkedHashMap<String, Schema>();
List<String> allRequired = new ArrayList<String>();
// 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<String, Schema>();
allRequired = new ArrayList<String>();
m.allVars = new ArrayList<CodegenProperty>();
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<Schema> interfaces = getInterfaces(composed);
// interfaces (intermediate models)
if (interfaces != null) {
// interfaces (schemas defined in allOf, anyOf, oneOf)
List<Schema> interfaces = ModelUtils.getInterfaces(composed);
if (!interfaces.isEmpty()) {
// m.interfaces is for backward compatibility
if (m.interfaces == null)
m.interfaces = new ArrayList<String>();
@ -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<String, String> 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<Schema> getInterfaces(ComposedSchema composed) {
List<Schema> 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<String, Schema> 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

View File

@ -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);
}
}
}

View File

@ -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<Schema> 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.<Schema>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<String, Schema> allSchemas) {
List<Schema> 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;

View File

@ -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}}
{{/isOAuth}}{{/authMethods}}

View File

@ -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
end

View File

@ -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
end

View File

@ -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<String, Object> 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));
}
});
}

View File

@ -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<String, Schema> 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"));

View File

@ -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()));

View File

@ -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");

View File

@ -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<String> anyOf = new TreeSet<String>();
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<String> oneOf = new TreeSet<String>();
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<CodegenDiscriminator.MappedModel> mappedModels = new LinkedHashSet<CodegenDiscriminator.MappedModel>();
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();

View File

@ -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

View File

@ -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

View File

@ -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"
}
}
}
}
}
}

View File

@ -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"
}
}
}
}
}
}

View File

@ -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)

View File

@ -140,11 +140,6 @@ namespace Org.OpenAPITools.Model
[DataMember(Name="enum_number", EmitDefaultValue=false)]
public EnumNumberEnum? EnumNumber { get; set; }
/// <summary>
/// Gets or Sets OuterEnum
/// </summary>
[DataMember(Name="outerEnum", EmitDefaultValue=false)]
public OuterEnum? OuterEnum { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="EnumTest" /> class.
/// </summary>
[JsonConstructorAttribute]
@ -157,7 +152,7 @@ namespace Org.OpenAPITools.Model
/// <param name="enumInteger">enumInteger.</param>
/// <param name="enumNumber">enumNumber.</param>
/// <param name="outerEnum">outerEnum.</param>
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
/// <summary>
/// Gets or Sets OuterEnum
/// </summary>
[DataMember(Name="outerEnum", EmitDefaultValue=false)]
public OuterEnum OuterEnum { get; set; }
/// <summary>
/// Returns the string presentation of the object

View File

@ -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)

View File

@ -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)

View File

@ -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"`
}

View File

@ -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"`
}

View File

@ -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

View File

@ -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

View File

@ -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 =

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -14,8 +14,6 @@ Name | Type | Description | Notes
## Enum: Map&lt;String, InnerEnum&gt;
Name | Value
---- | -----
UPPER | &quot;UPPER&quot;
LOWER | &quot;lower&quot;

View File

@ -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,
];
}

View File

@ -3,8 +3,8 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**declawed** | **BOOLEAN** | | [optional]
**class_name** | **String** | |
**color** | **String** | | [optional] [default to &#39;red&#39;]
**declawed** | **BOOLEAN** | | [optional]

View File

@ -3,8 +3,8 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**breed** | **String** | | [optional]
**class_name** | **String** | |
**color** | **String** | | [optional] [default to &#39;red&#39;]
**breed** | **String** | | [optional]

View File

@ -192,5 +192,7 @@ module Petstore
value
end
end
end
end

View File

@ -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

View File

@ -197,5 +197,7 @@ module Petstore
value
end
end
end
end

View File

@ -181,5 +181,7 @@ module Petstore
value
end
end
end
end

View File

@ -181,5 +181,7 @@ module Petstore
value
end
end
end
end

View File

@ -203,5 +203,7 @@ module Petstore
value
end
end
end
end

View File

@ -225,5 +225,7 @@ module Petstore
value
end
end
end
end

View File

@ -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

View File

@ -195,5 +195,7 @@ module Petstore
value
end
end
end
end

View File

@ -180,5 +180,7 @@ module Petstore
value
end
end
end
end

View File

@ -179,5 +179,7 @@ module Petstore
value
end
end
end
end

View File

@ -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

View File

@ -224,5 +224,7 @@ module Petstore
value
end
end
end
end

View File

@ -290,5 +290,7 @@ module Petstore
value
end
end
end
end

View File

@ -181,5 +181,7 @@ module Petstore
value
end
end
end
end

View File

@ -190,5 +190,7 @@ module Petstore
value
end
end
end
end

View File

@ -493,5 +493,7 @@ module Petstore
value
end
end
end
end

View File

@ -188,5 +188,7 @@ module Petstore
value
end
end
end
end

View File

@ -179,5 +179,7 @@ module Petstore
value
end
end
end
end

View File

@ -236,5 +236,7 @@ module Petstore
value
end
end
end
end

View File

@ -199,5 +199,7 @@ module Petstore
value
end
end
end
end

View File

@ -189,5 +189,7 @@ module Petstore
value
end
end
end
end

View File

@ -180,5 +180,7 @@ module Petstore
value
end
end
end
end

View File

@ -212,5 +212,7 @@ module Petstore
value
end
end
end
end

View File

@ -179,5 +179,7 @@ module Petstore
value
end
end
end
end

View File

@ -261,5 +261,7 @@ module Petstore
value
end
end
end
end

View File

@ -197,5 +197,7 @@ module Petstore
value
end
end
end
end

View File

@ -273,5 +273,7 @@ module Petstore
value
end
end
end
end

View File

@ -188,5 +188,7 @@ module Petstore
value
end
end
end
end

View File

@ -179,5 +179,7 @@ module Petstore
value
end
end
end
end

View File

@ -188,5 +188,7 @@ module Petstore
value
end
end
end
end

View File

@ -243,5 +243,7 @@ module Petstore
value
end
end
end
end

View File

@ -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,
];
}

View File

@ -3,8 +3,8 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**declawed** | **BOOLEAN** | | [optional]
**class_name** | **String** | |
**color** | **String** | | [optional] [default to &#39;red&#39;]
**declawed** | **BOOLEAN** | | [optional]

View File

@ -3,8 +3,8 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**breed** | **String** | | [optional]
**class_name** | **String** | |
**color** | **String** | | [optional] [default to &#39;red&#39;]
**breed** | **String** | | [optional]

View File

@ -192,5 +192,7 @@ module Petstore
value
end
end
end
end

View File

@ -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

View File

@ -197,5 +197,7 @@ module Petstore
value
end
end
end
end

View File

@ -181,5 +181,7 @@ module Petstore
value
end
end
end
end

View File

@ -181,5 +181,7 @@ module Petstore
value
end
end
end
end

View File

@ -203,5 +203,7 @@ module Petstore
value
end
end
end
end

View File

@ -225,5 +225,7 @@ module Petstore
value
end
end
end
end

View File

@ -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

View File

@ -195,5 +195,7 @@ module Petstore
value
end
end
end
end

View File

@ -180,5 +180,7 @@ module Petstore
value
end
end
end
end

View File

@ -179,5 +179,7 @@ module Petstore
value
end
end
end
end

View File

@ -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

View File

@ -224,5 +224,7 @@ module Petstore
value
end
end
end
end

View File

@ -290,5 +290,7 @@ module Petstore
value
end
end
end
end

View File

@ -181,5 +181,7 @@ module Petstore
value
end
end
end
end

Some files were not shown because too many files have changed in this diff Show More