Fixes fromProperty when property is required vs optional (#12858)

* Adds required boolean to fromProperty

* Adds required to other method signatures

* pythn-exp sample regenerated

* Samples regenerated

* Adds java test of fix
This commit is contained in:
Justin Black 2022-07-13 18:17:33 -07:00 committed by GitHub
parent 5aa0e0a456
commit c44fe8a04a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 224 additions and 155 deletions

View File

@ -2456,26 +2456,29 @@ public class DefaultCodegen implements CodegenConfig {
} }
private static class NamedSchema { private static class NamedSchema {
private NamedSchema(String name, Schema s) { private NamedSchema(String name, Schema s, boolean required) {
this.name = name; this.name = name;
this.schema = s; this.schema = s;
this.required = required;
} }
private String name; private String name;
private Schema schema; private Schema schema;
private boolean required;
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
NamedSchema that = (NamedSchema) o; NamedSchema that = (NamedSchema) o;
return Objects.equals(name, that.name) && return Objects.equals(required, that.required) &&
Objects.equals(name, that.name) &&
Objects.equals(schema, that.schema); Objects.equals(schema, that.schema);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(name, schema); return Objects.hash(name, schema, required);
} }
} }
@ -2548,7 +2551,7 @@ public class DefaultCodegen implements CodegenConfig {
if (StringUtils.isBlank(interfaceSchema.get$ref())) { if (StringUtils.isBlank(interfaceSchema.get$ref())) {
// primitive type // primitive type
String languageType = getTypeDeclaration(interfaceSchema); String languageType = getTypeDeclaration(interfaceSchema);
CodegenProperty interfaceProperty = fromProperty(languageType, interfaceSchema); CodegenProperty interfaceProperty = fromProperty(languageType, interfaceSchema, false);
if (ModelUtils.isArraySchema(interfaceSchema) || ModelUtils.isMapSchema(interfaceSchema)) { if (ModelUtils.isArraySchema(interfaceSchema) || ModelUtils.isMapSchema(interfaceSchema)) {
while (interfaceProperty != null) { while (interfaceProperty != null) {
addImport(m, interfaceProperty.complexType); addImport(m, interfaceProperty.complexType);
@ -2584,7 +2587,7 @@ public class DefaultCodegen implements CodegenConfig {
refSchema = allDefinitions.get(ref); refSchema = allDefinitions.get(ref);
} }
final String modelName = toModelName(ref); final String modelName = toModelName(ref);
CodegenProperty interfaceProperty = fromProperty(modelName, interfaceSchema); CodegenProperty interfaceProperty = fromProperty(modelName, interfaceSchema, false);
m.interfaces.add(modelName); m.interfaces.add(modelName);
addImport(composed, refSchema, m, modelName); addImport(composed, refSchema, m, modelName);
@ -2835,7 +2838,7 @@ public class DefaultCodegen implements CodegenConfig {
m.setTypeProperties(schema); m.setTypeProperties(schema);
m.setComposedSchemas(getComposedSchemas(schema)); m.setComposedSchemas(getComposedSchemas(schema));
if (ModelUtils.isArraySchema(schema)) { if (ModelUtils.isArraySchema(schema)) {
CodegenProperty arrayProperty = fromProperty(name, schema); CodegenProperty arrayProperty = fromProperty(name, schema, false);
m.setItems(arrayProperty.items); m.setItems(arrayProperty.items);
m.arrayModelType = arrayProperty.complexType; m.arrayModelType = arrayProperty.complexType;
addParentContainer(m, name, schema); addParentContainer(m, name, schema);
@ -2955,17 +2958,17 @@ public class DefaultCodegen implements CodegenConfig {
if (schema.getAdditionalProperties() == null) { if (schema.getAdditionalProperties() == null) {
if (!disallowAdditionalPropertiesIfNotPresent) { if (!disallowAdditionalPropertiesIfNotPresent) {
isAdditionalPropertiesTrue = true; isAdditionalPropertiesTrue = true;
addPropProp = fromProperty("", new Schema()); addPropProp = fromProperty("", new Schema(), false);
additionalPropertiesIsAnyType = true; additionalPropertiesIsAnyType = true;
} }
} else if (schema.getAdditionalProperties() instanceof Boolean) { } else if (schema.getAdditionalProperties() instanceof Boolean) {
if (Boolean.TRUE.equals(schema.getAdditionalProperties())) { if (Boolean.TRUE.equals(schema.getAdditionalProperties())) {
isAdditionalPropertiesTrue = true; isAdditionalPropertiesTrue = true;
addPropProp = fromProperty("", new Schema()); addPropProp = fromProperty("", new Schema(), false);
additionalPropertiesIsAnyType = true; additionalPropertiesIsAnyType = true;
} }
} else { } else {
addPropProp = fromProperty("", (Schema) schema.getAdditionalProperties()); addPropProp = fromProperty("", (Schema) schema.getAdditionalProperties(), false);
if (ModelUtils.isAnyType((Schema) schema.getAdditionalProperties())) { if (ModelUtils.isAnyType((Schema) schema.getAdditionalProperties())) {
additionalPropertiesIsAnyType = true; additionalPropertiesIsAnyType = true;
} }
@ -3451,7 +3454,7 @@ public class DefaultCodegen implements CodegenConfig {
innerSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type"); innerSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type");
p.setAdditionalProperties(innerSchema); p.setAdditionalProperties(innerSchema);
} }
CodegenProperty cp = fromProperty("inner", innerSchema); CodegenProperty cp = fromProperty("inner", innerSchema, false);
updatePropertyForMap(property, cp); updatePropertyForMap(property, cp);
} }
@ -3522,6 +3525,19 @@ public class DefaultCodegen implements CodegenConfig {
property.pattern = toRegularExpression(p.getPattern()); property.pattern = toRegularExpression(p.getPattern());
} }
/**
* TODO remove this in 7.0.0 as a breaking change
* This method was kept when required was added to the fromProperty signature
* to ensure that the change was non-breaking
*
* @param name name of the property
* @param p OAS property schema
* @return Codegen Property object
*/
public CodegenProperty fromProperty(String name, Schema p) {
return fromProperty(name, p, false);
}
/** /**
* Convert OAS Property object to Codegen Property object. * Convert OAS Property object to Codegen Property object.
* <p> * <p>
@ -3531,26 +3547,28 @@ public class DefaultCodegen implements CodegenConfig {
* Any subsequent processing of the CodegenModel return value must be idempotent * Any subsequent processing of the CodegenModel return value must be idempotent
* for a given (String name, Schema schema). * for a given (String name, Schema schema).
* *
* @param name name of the property * @param name name of the property
* @param p OAS property schema * @param p OAS property schema
* @param required true if the property is required in the next higher object schema, false otherwise
* @return Codegen Property object * @return Codegen Property object
*/ */
public CodegenProperty fromProperty(String name, Schema p) { public CodegenProperty fromProperty(String name, Schema p, boolean required) {
if (p == null) { if (p == null) {
LOGGER.error("Undefined property/schema for `{}`. Default to type:string.", name); LOGGER.error("Undefined property/schema for `{}`. Default to type:string.", name);
return null; return null;
} }
LOGGER.debug("debugging fromProperty for {} : {}", name, p); LOGGER.debug("debugging fromProperty for {} : {}", name, p);
NamedSchema ns = new NamedSchema(name, p); NamedSchema ns = new NamedSchema(name, p, required);
CodegenProperty cpc = schemaCodegenPropertyCache.get(ns); CodegenProperty cpc = schemaCodegenPropertyCache.get(ns);
if (cpc != null) { if (cpc != null) {
LOGGER.debug("Cached fromProperty for {} : {}", name, p.getName()); LOGGER.debug("Cached fromProperty for {} : {} required={}", name, p.getName(), required);
return cpc; return cpc;
} }
// unalias schema // unalias schema
p = unaliasSchema(p, schemaMapping); p = unaliasSchema(p, schemaMapping);
CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY); CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
property.required = required;
ModelUtils.syncValidationProperties(p, property); ModelUtils.syncValidationProperties(p, property);
property.name = toVarName(name); property.name = toVarName(name);
@ -3717,7 +3735,7 @@ public class DefaultCodegen implements CodegenConfig {
} }
ArraySchema arraySchema = (ArraySchema) p; ArraySchema arraySchema = (ArraySchema) p;
Schema innerSchema = unaliasSchema(getSchemaItems(arraySchema), schemaMapping); Schema innerSchema = unaliasSchema(getSchemaItems(arraySchema), schemaMapping);
CodegenProperty cp = fromProperty(itemName, innerSchema); CodegenProperty cp = fromProperty(itemName, innerSchema, false);
updatePropertyForArray(property, cp); updatePropertyForArray(property, cp);
} else if (ModelUtils.isTypeObjectSchema(p)) { } else if (ModelUtils.isTypeObjectSchema(p)) {
updatePropertyForObject(property, p); updatePropertyForObject(property, p);
@ -3965,14 +3983,14 @@ public class DefaultCodegen implements CodegenConfig {
Schema responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(methodResponse), schemaMapping); Schema responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(methodResponse), schemaMapping);
if (responseSchema != null) { if (responseSchema != null) {
CodegenProperty cm = fromProperty("response", responseSchema); CodegenProperty cm = fromProperty("response", responseSchema, false);
if (ModelUtils.isArraySchema(responseSchema)) { if (ModelUtils.isArraySchema(responseSchema)) {
ArraySchema as = (ArraySchema) responseSchema; ArraySchema as = (ArraySchema) responseSchema;
CodegenProperty innerProperty = fromProperty("response", getSchemaItems(as)); CodegenProperty innerProperty = fromProperty("response", getSchemaItems(as), false);
op.returnBaseType = innerProperty.baseType; op.returnBaseType = innerProperty.baseType;
} else if (ModelUtils.isMapSchema(responseSchema)) { } else if (ModelUtils.isMapSchema(responseSchema)) {
CodegenProperty innerProperty = fromProperty("response", getAdditionalProperties(responseSchema)); CodegenProperty innerProperty = fromProperty("response", getAdditionalProperties(responseSchema), false);
op.returnBaseType = innerProperty.baseType; op.returnBaseType = innerProperty.baseType;
} else { } else {
if (cm.complexType != null) { if (cm.complexType != null) {
@ -4430,7 +4448,7 @@ public class DefaultCodegen implements CodegenConfig {
r.setPattern(toRegularExpression(responseSchema.getPattern())); r.setPattern(toRegularExpression(responseSchema.getPattern()));
} }
CodegenProperty cp = fromProperty("response", responseSchema); CodegenProperty cp = fromProperty("response", responseSchema, false);
r.dataType = getTypeDeclaration(responseSchema); r.dataType = getTypeDeclaration(responseSchema);
if (!ModelUtils.isArraySchema(responseSchema)) { if (!ModelUtils.isArraySchema(responseSchema)) {
@ -4453,7 +4471,7 @@ public class DefaultCodegen implements CodegenConfig {
r.isArray = true; r.isArray = true;
r.containerType = cp.containerType; r.containerType = cp.containerType;
ArraySchema as = (ArraySchema) responseSchema; ArraySchema as = (ArraySchema) responseSchema;
CodegenProperty items = fromProperty("response", getSchemaItems(as)); CodegenProperty items = fromProperty("response", getSchemaItems(as), false);
r.setItems(items); r.setItems(items);
CodegenProperty innerCp = items; CodegenProperty innerCp = items;
@ -4612,7 +4630,7 @@ public class DefaultCodegen implements CodegenConfig {
private void updateParameterForMap(CodegenParameter codegenParameter, Schema parameterSchema, Set<String> imports) { private void updateParameterForMap(CodegenParameter codegenParameter, Schema parameterSchema, Set<String> imports) {
CodegenProperty codegenProperty = fromProperty("inner", getAdditionalProperties(parameterSchema)); CodegenProperty codegenProperty = fromProperty("inner", getAdditionalProperties(parameterSchema), false);
codegenParameter.items = codegenProperty; codegenParameter.items = codegenProperty;
codegenParameter.mostInnerItems = codegenProperty.mostInnerItems; codegenParameter.mostInnerItems = codegenProperty.mostInnerItems;
codegenParameter.baseType = codegenProperty.dataType; codegenParameter.baseType = codegenProperty.dataType;
@ -4700,11 +4718,11 @@ public class DefaultCodegen implements CodegenConfig {
if (this instanceof RustServerCodegen) { if (this instanceof RustServerCodegen) {
// for rust server, we need to do somethings special as it uses // for rust server, we need to do somethings special as it uses
// $ref (e.g. #components/schemas/Pet) to determine whether it's a model // $ref (e.g. #components/schemas/Pet) to determine whether it's a model
prop = fromProperty(parameter.getName(), parameterSchema); prop = fromProperty(parameter.getName(), parameterSchema, false);
} else if (getUseInlineModelResolver()) { } else if (getUseInlineModelResolver()) {
prop = fromProperty(parameter.getName(), getReferencedSchemaWhenNotEnum(parameterSchema)); prop = fromProperty(parameter.getName(), getReferencedSchemaWhenNotEnum(parameterSchema), false);
} else { } else {
prop = fromProperty(parameter.getName(), parameterSchema); prop = fromProperty(parameter.getName(), parameterSchema, false);
} }
codegenParameter.setSchema(prop); codegenParameter.setSchema(prop);
} else if (parameter.getContent() != null) { } else if (parameter.getContent() != null) {
@ -4827,7 +4845,7 @@ public class DefaultCodegen implements CodegenConfig {
collectionFormat = getCollectionFormat(parameter); collectionFormat = getCollectionFormat(parameter);
// default to csv: // default to csv:
collectionFormat = StringUtils.isEmpty(collectionFormat) ? "csv" : collectionFormat; collectionFormat = StringUtils.isEmpty(collectionFormat) ? "csv" : collectionFormat;
CodegenProperty itemsProperty = fromProperty("inner", inner); CodegenProperty itemsProperty = fromProperty("inner", inner, false);
codegenParameter.items = itemsProperty; codegenParameter.items = itemsProperty;
codegenParameter.mostInnerItems = itemsProperty.mostInnerItems; codegenParameter.mostInnerItems = itemsProperty.mostInnerItems;
codegenParameter.baseType = itemsProperty.dataType; codegenParameter.baseType = itemsProperty.dataType;
@ -4843,15 +4861,10 @@ public class DefaultCodegen implements CodegenConfig {
; ;
} }
CodegenProperty codegenProperty = fromProperty(parameter.getName(), parameterSchema); CodegenProperty codegenProperty = fromProperty(parameter.getName(), parameterSchema, false);
if (Boolean.TRUE.equals(codegenProperty.isModel)) { if (Boolean.TRUE.equals(codegenProperty.isModel)) {
codegenParameter.isModel = true; codegenParameter.isModel = true;
} }
// TODO revise below which seems not working
//if (parameterSchema.getRequired() != null && !parameterSchema.getRequired().isEmpty() && parameterSchema.getRequired().contains(codegenProperty.baseName)) {
codegenProperty.required = Boolean.TRUE.equals(parameter.getRequired()) ? true : false;
//}
//codegenProperty.required = true;
if (parameterModelName != null) { if (parameterModelName != null) {
codegenParameter.dataType = parameterModelName; codegenParameter.dataType = parameterModelName;
@ -4865,7 +4878,9 @@ public class DefaultCodegen implements CodegenConfig {
imports.add(codegenProperty.baseType); imports.add(codegenProperty.baseType);
} }
codegenParameter.dataFormat = codegenProperty.dataFormat; codegenParameter.dataFormat = codegenProperty.dataFormat;
codegenParameter.required = codegenProperty.required; if (parameter.getRequired() != null) {
codegenParameter.required = parameter.getRequired().booleanValue();
}
if (codegenProperty.isEnum) { if (codegenProperty.isEnum) {
codegenParameter.datatypeWithEnum = codegenProperty.datatypeWithEnum; codegenParameter.datatypeWithEnum = codegenProperty.datatypeWithEnum;
@ -4902,15 +4917,19 @@ public class DefaultCodegen implements CodegenConfig {
if (schema.get$ref() != null) { if (schema.get$ref() != null) {
schema = ModelUtils.getReferencedSchema(openAPI, schema); schema = ModelUtils.getReferencedSchema(openAPI, schema);
} }
codegenParameter.items = fromProperty(codegenParameter.paramName, schema); codegenParameter.items = fromProperty(codegenParameter.paramName, schema, false);
// https://swagger.io/docs/specification/serialization/ // https://swagger.io/docs/specification/serialization/
if (schema != null) { if (schema != null) {
Map<String, Schema<?>> properties = schema.getProperties(); Map<String, Schema<?>> properties = schema.getProperties();
List<String> requiredVarNames = new ArrayList<>();
if (schema.getRequired() != null) {
requiredVarNames.addAll(schema.getRequired());
}
if (properties != null) { if (properties != null) {
codegenParameter.items.vars = codegenParameter.items.vars =
properties.entrySet().stream() properties.entrySet().stream()
.map(entry -> { .map(entry -> {
CodegenProperty property = fromProperty(entry.getKey(), entry.getValue()); CodegenProperty property = fromProperty(entry.getKey(), entry.getValue(), requiredVarNames.contains(entry.getKey()));
property.baseName = codegenParameter.baseName + "[" + entry.getKey() + "]"; property.baseName = codegenParameter.baseName + "[" + entry.getKey() + "]";
return property; return property;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
@ -5189,7 +5208,7 @@ public class DefaultCodegen implements CodegenConfig {
} else { } else {
schema = header.getSchema(); schema = header.getSchema();
} }
CodegenProperty cp = fromProperty(headerEntry.getKey(), schema); CodegenProperty cp = fromProperty(headerEntry.getKey(), schema, false);
cp.setDescription(escapeText(description)); cp.setDescription(escapeText(description));
cp.setUnescapedDescription(description); cp.setUnescapedDescription(description);
if (header.getRequired() != null) { if (header.getRequired() != null) {
@ -5257,7 +5276,7 @@ public class DefaultCodegen implements CodegenConfig {
* @param schema the input OAS schema. * @param schema the input OAS schema.
*/ */
protected void addParentContainer(CodegenModel model, String name, Schema schema) { protected void addParentContainer(CodegenModel model, String name, Schema schema) {
final CodegenProperty property = fromProperty(name, schema); final CodegenProperty property = fromProperty(name, schema, false);
addImport(model, property.complexType); addImport(model, property.complexType);
model.parent = toInstantiationType(schema); model.parent = toInstantiationType(schema);
final String containerType = property.containerType; final String containerType = property.containerType;
@ -5423,13 +5442,16 @@ public class DefaultCodegen implements CodegenConfig {
if (prop == null) { if (prop == null) {
LOGGER.warn("Please report the issue. There shouldn't be null property for {}", key); LOGGER.warn("Please report the issue. There shouldn't be null property for {}", key);
} else { } else {
final CodegenProperty cp = fromProperty(key, prop); final CodegenProperty cp = fromProperty(key, prop, mandatory.contains(key));
cp.required = mandatory.contains(key);
vars.add(cp); vars.add(cp);
m.setHasVars(true);
if (cp.required) {
m.setHasRequired(true);
m.getRequiredVars().add(cp);
}
if (cm == null) { if (cm == null) {
continue; continue;
} }
cm.hasRequired = cm.hasRequired || cp.required;
cm.hasOptional = cm.hasOptional || !cp.required; cm.hasOptional = cm.hasOptional || !cp.required;
if (cp.isEnum) { if (cp.isEnum) {
// FIXME: if supporting inheritance, when called a second time for allProperties it is possible for // FIXME: if supporting inheritance, when called a second time for allProperties it is possible for
@ -5445,9 +5467,7 @@ public class DefaultCodegen implements CodegenConfig {
addImportsForPropertyType(cm, cp); addImportsForPropertyType(cm, cp);
// if required, add to the list "requiredVars" // if required, add to the list "requiredVars"
if (Boolean.TRUE.equals(cp.required)) { if (Boolean.FALSE.equals(cp.required)) {
cm.requiredVars.add(cp);
} else { // else add to the list "optionalVars" for optional property
cm.optionalVars.add(cp); cm.optionalVars.add(cp);
} }
@ -6467,7 +6487,7 @@ public class DefaultCodegen implements CodegenConfig {
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER); CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
LOGGER.debug("Debugging fromFormProperty {}: {}", name, propertySchema); LOGGER.debug("Debugging fromFormProperty {}: {}", name, propertySchema);
CodegenProperty codegenProperty = fromProperty(name, propertySchema); CodegenProperty codegenProperty = fromProperty(name, propertySchema, false);
Schema ps = unaliasSchema(propertySchema, schemaMapping); Schema ps = unaliasSchema(propertySchema, schemaMapping);
ModelUtils.syncValidationProperties(ps, codegenParameter); ModelUtils.syncValidationProperties(ps, codegenParameter);
@ -6553,7 +6573,7 @@ public class DefaultCodegen implements CodegenConfig {
; ;
} else if (ModelUtils.isArraySchema(ps)) { } else if (ModelUtils.isArraySchema(ps)) {
Schema inner = getSchemaItems((ArraySchema) ps); Schema inner = getSchemaItems((ArraySchema) ps);
CodegenProperty arrayInnerProperty = fromProperty("inner", inner); CodegenProperty arrayInnerProperty = fromProperty("inner", inner, false);
codegenParameter.items = arrayInnerProperty; codegenParameter.items = arrayInnerProperty;
codegenParameter.mostInnerItems = arrayInnerProperty.mostInnerItems; codegenParameter.mostInnerItems = arrayInnerProperty.mostInnerItems;
codegenParameter.isPrimitiveType = false; codegenParameter.isPrimitiveType = false;
@ -6648,7 +6668,7 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter.isNullable = codegenModel.isNullable; codegenParameter.isNullable = codegenModel.isNullable;
imports.add(codegenParameter.baseType); imports.add(codegenParameter.baseType);
} else { } else {
CodegenProperty codegenProperty = fromProperty("property", schema); CodegenProperty codegenProperty = fromProperty("property", schema, false);
if (codegenProperty != null && codegenProperty.getComplexType() != null && codegenProperty.getComplexType().contains(" | ")) { if (codegenProperty != null && codegenProperty.getComplexType() != null && codegenProperty.getComplexType().contains(" | ")) {
List<String> parts = Arrays.asList(codegenProperty.getComplexType().split(" \\| ")); List<String> parts = Arrays.asList(codegenProperty.getComplexType().split(" \\| "));
@ -6713,7 +6733,7 @@ public class DefaultCodegen implements CodegenConfig {
inner = new StringSchema().description("//TODO automatically added by openapi-generator"); inner = new StringSchema().description("//TODO automatically added by openapi-generator");
schema.setAdditionalProperties(inner); schema.setAdditionalProperties(inner);
} }
CodegenProperty codegenProperty = fromProperty("property", schema); CodegenProperty codegenProperty = fromProperty("property", schema, false);
imports.add(codegenProperty.baseType); imports.add(codegenProperty.baseType);
@ -6745,7 +6765,7 @@ public class DefaultCodegen implements CodegenConfig {
} }
protected void updateRequestBodyForPrimitiveType(CodegenParameter codegenParameter, Schema schema, String bodyParameterName, Set<String> imports) { protected void updateRequestBodyForPrimitiveType(CodegenParameter codegenParameter, Schema schema, String bodyParameterName, Set<String> imports) {
CodegenProperty codegenProperty = fromProperty("PRIMITIVE_REQUEST_BODY", schema); CodegenProperty codegenProperty = fromProperty("PRIMITIVE_REQUEST_BODY", schema, false);
if (codegenProperty != null) { if (codegenProperty != null) {
if (StringUtils.isEmpty(bodyParameterName)) { if (StringUtils.isEmpty(bodyParameterName)) {
codegenParameter.baseName = "body"; // default to body codegenParameter.baseName = "body"; // default to body
@ -6779,7 +6799,7 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter.isFreeFormObject = true; codegenParameter.isFreeFormObject = true;
// HTTP request body is free form object // HTTP request body is free form object
CodegenProperty codegenProperty = fromProperty("FREE_FORM_REQUEST_BODY", schema); CodegenProperty codegenProperty = fromProperty("FREE_FORM_REQUEST_BODY", schema, false);
if (codegenProperty != null) { if (codegenProperty != null) {
if (StringUtils.isEmpty(bodyParameterName)) { if (StringUtils.isEmpty(bodyParameterName)) {
codegenParameter.baseName = "body"; // default to body codegenParameter.baseName = "body"; // default to body
@ -6808,7 +6828,7 @@ public class DefaultCodegen implements CodegenConfig {
} else { } else {
final ArraySchema arraySchema = (ArraySchema) schema; final ArraySchema arraySchema = (ArraySchema) schema;
Schema inner = getSchemaItems(arraySchema); Schema inner = getSchemaItems(arraySchema);
CodegenProperty codegenProperty = fromProperty("property", arraySchema); CodegenProperty codegenProperty = fromProperty("property", arraySchema, false);
imports.add(codegenProperty.baseType); imports.add(codegenProperty.baseType);
CodegenProperty innerCp = codegenProperty; CodegenProperty innerCp = codegenProperty;
CodegenProperty mostInnerItem = innerCp; CodegenProperty mostInnerItem = innerCp;
@ -6942,7 +6962,7 @@ public class DefaultCodegen implements CodegenConfig {
String contentType = contentEntry.getKey(); String contentType = contentEntry.getKey();
CodegenProperty schemaProp = null; CodegenProperty schemaProp = null;
if (mt.getSchema() != null) { if (mt.getSchema() != null) {
schemaProp = fromProperty(toMediaTypeSchemaName(contentType, mediaTypeSchemaSuffix), mt.getSchema()); schemaProp = fromProperty(toMediaTypeSchemaName(contentType, mediaTypeSchemaSuffix), mt.getSchema(), false);
} }
CodegenMediaType codegenMt = new CodegenMediaType(schemaProp, ceMap); CodegenMediaType codegenMt = new CodegenMediaType(schemaProp, ceMap);
cmtContent.put(contentType, codegenMt); cmtContent.put(contentType, codegenMt);
@ -7049,27 +7069,9 @@ public class DefaultCodegen implements CodegenConfig {
protected void addVarsRequiredVarsAdditionalProps(Schema schema, IJsonSchemaValidationProperties property) { protected void addVarsRequiredVarsAdditionalProps(Schema schema, IJsonSchemaValidationProperties property) {
setAddProps(schema, property); setAddProps(schema, property);
if (!"object".equals(schema.getType())) { Set<String> mandatory = schema.getRequired() == null ? Collections.emptySet()
return; : new TreeSet<>(schema.getRequired());
} addVars(property, property.getVars(), schema.getProperties(), mandatory);
if (schema instanceof ObjectSchema) {
ObjectSchema objSchema = (ObjectSchema) schema;
HashSet<String> requiredVars = new HashSet<>();
if (objSchema.getRequired() != null) {
requiredVars.addAll(objSchema.getRequired());
}
if (objSchema.getProperties() != null && objSchema.getProperties().size() > 0) {
property.setHasVars(true);
}
addVars(property, property.getVars(), objSchema.getProperties(), requiredVars);
List<CodegenProperty> requireCpVars = property.getVars()
.stream()
.filter(p -> Boolean.TRUE.equals(p.required)).collect(Collectors.toList());
property.setRequiredVars(requireCpVars);
if (property.getRequiredVars() != null && property.getRequiredVars().size() > 0) {
property.setHasRequired(true);
}
}
} }
private void addJsonSchemaForBodyRequestInCaseItsNotPresent(CodegenParameter codegenParameter, RequestBody body) { private void addJsonSchemaForBodyRequestInCaseItsNotPresent(CodegenParameter codegenParameter, RequestBody body) {
@ -7576,7 +7578,7 @@ public class DefaultCodegen implements CodegenConfig {
Schema notSchema = schema.getNot(); Schema notSchema = schema.getNot();
CodegenProperty notProperty = null; CodegenProperty notProperty = null;
if (notSchema != null) { if (notSchema != null) {
notProperty = fromProperty("NotSchema", notSchema); notProperty = fromProperty("NotSchema", notSchema, false);
} }
List<CodegenProperty> allOf = new ArrayList<>(); List<CodegenProperty> allOf = new ArrayList<>();
List<CodegenProperty> oneOf = new ArrayList<>(); List<CodegenProperty> oneOf = new ArrayList<>();
@ -7602,7 +7604,7 @@ public class DefaultCodegen implements CodegenConfig {
List<CodegenProperty> xOf = new ArrayList<>(); List<CodegenProperty> xOf = new ArrayList<>();
int i = 0; int i = 0;
for (Schema xOfSchema : xOfCollection) { for (Schema xOfSchema : xOfCollection) {
CodegenProperty cp = fromProperty(collectionName + "_" + i, xOfSchema); CodegenProperty cp = fromProperty(collectionName + "_" + i, xOfSchema, false);
xOf.add(cp); xOf.add(cp);
i += 1; i += 1;
} }

View File

@ -129,7 +129,7 @@ public interface IJsonSchemaValidationProperties {
boolean getHasVars(); boolean getHasVars();
void setHasVars(boolean hasRequiredVars); void setHasVars(boolean hasVars);
boolean getHasRequired(); boolean getHasRequired();

View File

@ -385,8 +385,8 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
} }
@Override @Override
public CodegenProperty fromProperty(String name, Schema p) { public CodegenProperty fromProperty(String name, Schema p, boolean required) {
CodegenProperty property = super.fromProperty(name, p); CodegenProperty property = super.fromProperty(name, p, required);
if (property != null) { if (property != null) {
String nameInCamelCase = property.nameInCamelCase; String nameInCamelCase = property.nameInCamelCase;
nameInCamelCase = sanitizeName(nameInCamelCase); nameInCamelCase = sanitizeName(nameInCamelCase);
@ -566,7 +566,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) { if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
ApiResponse methodResponse = findMethodResponse(operation.getResponses()); ApiResponse methodResponse = findMethodResponse(operation.getResponses());
if (methodResponse != null && ModelUtils.getSchemaFromResponse(methodResponse) != null) { if (methodResponse != null && ModelUtils.getSchemaFromResponse(methodResponse) != null) {
CodegenProperty cm = fromProperty("response", ModelUtils.getSchemaFromResponse(methodResponse)); CodegenProperty cm = fromProperty("response", ModelUtils.getSchemaFromResponse(methodResponse), false);
op.vendorExtensions.put("x-codegen-response", cm); op.vendorExtensions.put("x-codegen-response", cm);
op.vendorExtensions.put("x-is-model-type", isModelType(cm)); op.vendorExtensions.put("x-is-model-type", isModelType(cm));
op.vendorExtensions.put("x-is-stream-type", isStreamType(cm)); op.vendorExtensions.put("x-is-stream-type", isStreamType(cm));

View File

@ -251,8 +251,8 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public CodegenProperty fromProperty(String name, Schema p) { public CodegenProperty fromProperty(String name, Schema p, boolean required) {
CodegenProperty property = super.fromProperty(name, p); CodegenProperty property = super.fromProperty(name, p, required);
String nameInCamelCase = property.nameInCamelCase; String nameInCamelCase = property.nameInCamelCase;
if (nameInCamelCase.length() > 1) { if (nameInCamelCase.length() > 1) {
nameInCamelCase = sanitizeName(Character.toLowerCase(nameInCamelCase.charAt(0)) + nameInCamelCase.substring(1)); nameInCamelCase = sanitizeName(Character.toLowerCase(nameInCamelCase.charAt(0)) + nameInCamelCase.substring(1));

View File

@ -551,8 +551,8 @@ public abstract class AbstractDartCodegen extends DefaultCodegen {
} }
@Override @Override
public CodegenProperty fromProperty(String name, Schema p) { public CodegenProperty fromProperty(String name, Schema p, boolean required) {
final CodegenProperty property = super.fromProperty(name, p); final CodegenProperty property = super.fromProperty(name, p, required);
// Handle composed properties // Handle composed properties
if (ModelUtils.isComposedSchema(p)) { if (ModelUtils.isComposedSchema(p)) {

View File

@ -461,8 +461,8 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
* @return Codegen Property object * @return Codegen Property object
*/ */
@Override @Override
public CodegenProperty fromProperty(String name, Schema p) { public CodegenProperty fromProperty(String name, Schema p, boolean required) {
CodegenProperty prop = super.fromProperty(name, p); CodegenProperty prop = super.fromProperty(name, p, required);
if (ModelUtils.isArraySchema(p)) { if (ModelUtils.isArraySchema(p)) {
ArraySchema as = (ArraySchema) p; ArraySchema as = (ArraySchema) p;
if (ModelUtils.isSet(as)) { if (ModelUtils.isSet(as)) {

View File

@ -852,8 +852,8 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
} }
@Override @Override
public CodegenProperty fromProperty(String name, Schema p) { public CodegenProperty fromProperty(String name, Schema p, boolean required) {
CodegenProperty cm = super.fromProperty(name, p); CodegenProperty cm = super.fromProperty(name, p, required);
Schema ref = ModelUtils.getReferencedSchema(openAPI, p); Schema ref = ModelUtils.getReferencedSchema(openAPI, p);
if (ref != null) { if (ref != null) {
if (ref.getEnum() != null) { if (ref.getEnum() != null) {

View File

@ -242,7 +242,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
if (apiResponse != null) { if (apiResponse != null) {
Schema response = ModelUtils.getSchemaFromResponse(apiResponse); Schema response = ModelUtils.getSchemaFromResponse(apiResponse);
if (response != null) { if (response != null) {
CodegenProperty cm = fromProperty("response", response); CodegenProperty cm = fromProperty("response", response, false);
op.vendorExtensions.put("x-codegen-response", cm); op.vendorExtensions.put("x-codegen-response", cm);
if ("HttpContent".equals(cm.dataType)) { if ("HttpContent".equals(cm.dataType)) {
op.vendorExtensions.put("x-codegen-response-ishttpcontent", true); op.vendorExtensions.put("x-codegen-response-ishttpcontent", true);

View File

@ -297,7 +297,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
Schema response = ModelUtils.getSchemaFromResponse(methodResponse); Schema response = ModelUtils.getSchemaFromResponse(methodResponse);
response = ModelUtils.unaliasSchema(this.openAPI, response, schemaMapping); response = ModelUtils.unaliasSchema(this.openAPI, response, schemaMapping);
if (response != null) { if (response != null) {
CodegenProperty cm = fromProperty("response", response); CodegenProperty cm = fromProperty("response", response, false);
op.vendorExtensions.put("x-codegen-response", cm); op.vendorExtensions.put("x-codegen-response", cm);
if ("std::shared_ptr<HttpContent>".equals(cm.dataType)) { if ("std::shared_ptr<HttpContent>".equals(cm.dataType)) {
op.vendorExtensions.put("x-codegen-response-ishttpcontent", true); op.vendorExtensions.put("x-codegen-response-ishttpcontent", true);

View File

@ -384,8 +384,8 @@ public class GoClientCodegen extends AbstractGoCodegen {
} }
@Override @Override
public CodegenProperty fromProperty(String name, Schema p) { public CodegenProperty fromProperty(String name, Schema p, boolean required) {
CodegenProperty prop = super.fromProperty(name, p); CodegenProperty prop = super.fromProperty(name, p, required);
String cc = camelize(prop.name, true); String cc = camelize(prop.name, true);
if (isReservedWord(cc)) { if (isReservedWord(cc)) {
cc = escapeReservedWord(cc); cc = escapeReservedWord(cc);

View File

@ -323,7 +323,7 @@ public class KtormSchemaCodegen extends AbstractKotlinCodegen {
} }
if (!hasPrimaryKey) { if (!hasPrimaryKey) {
final IntegerSchema schema = new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT); final IntegerSchema schema = new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT);
CodegenProperty cp = super.fromProperty(primaryKeyConvention, schema); CodegenProperty cp = super.fromProperty(primaryKeyConvention, schema, false);
cp.setRequired(true); cp.setRequired(true);
model.vars.add(0, cp); model.vars.add(0, cp);
model.allVars.add(0, cp); model.allVars.add(0, cp);

View File

@ -307,8 +307,8 @@ public class PhpLaravelServerCodegen extends AbstractPhpCodegen {
} }
@Override @Override
public CodegenProperty fromProperty(String name, Schema p) { public CodegenProperty fromProperty(String name, Schema p, boolean required) {
CodegenProperty property = super.fromProperty(name, p); CodegenProperty property = super.fromProperty(name, p, required);
Schema referencedSchema = ModelUtils.getReferencedSchema(this.openAPI, p); Schema referencedSchema = ModelUtils.getReferencedSchema(this.openAPI, p);
//Referenced enum case: //Referenced enum case:

View File

@ -446,8 +446,8 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
* @return Codegen Property object * @return Codegen Property object
*/ */
@Override @Override
public CodegenProperty fromProperty(String name, Schema p) { public CodegenProperty fromProperty(String name, Schema p, boolean required) {
CodegenProperty cp = super.fromProperty(name, p); CodegenProperty cp = super.fromProperty(name, p, required);
if (cp.isEnum) { if (cp.isEnum) {
updateCodegenPropertyEnum(cp); updateCodegenPropertyEnum(cp);
} }
@ -518,7 +518,7 @@ public class PythonClientCodegen extends PythonLegacyClientCodegen {
return cp; return cp;
} }
Schema unaliasedSchema = unaliasSchema(schema, schemaMapping); Schema unaliasedSchema = unaliasSchema(schema, schemaMapping);
CodegenProperty unaliasedProp = fromProperty("body", unaliasedSchema); CodegenProperty unaliasedProp = fromProperty("body", unaliasedSchema, false);
Boolean dataTypeMismatch = !cp.dataType.equals(unaliasedProp.dataType); Boolean dataTypeMismatch = !cp.dataType.equals(unaliasedProp.dataType);
Boolean baseTypeMismatch = !cp.baseType.equals(unaliasedProp.complexType) && unaliasedProp.complexType != null; Boolean baseTypeMismatch = !cp.baseType.equals(unaliasedProp.complexType) && unaliasedProp.complexType != null;
if (dataTypeMismatch || baseTypeMismatch) { if (dataTypeMismatch || baseTypeMismatch) {

View File

@ -849,8 +849,8 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
* @return Codegen Property object * @return Codegen Property object
*/ */
@Override @Override
public CodegenProperty fromProperty(String name, Schema p) { public CodegenProperty fromProperty(String name, Schema p, boolean required) {
CodegenProperty cp = super.fromProperty(name, p); CodegenProperty cp = super.fromProperty(name, p, required);
if (cp.isAnyType && cp.isNullable) { if (cp.isAnyType && cp.isNullable) {
cp.isNullable = false; cp.isNullable = false;
} }
@ -964,7 +964,7 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
return cp; return cp;
} }
Schema unaliasedSchema = unaliasSchema(schema, schemaMapping); Schema unaliasedSchema = unaliasSchema(schema, schemaMapping);
CodegenProperty unaliasedProp = fromProperty("body", unaliasedSchema); CodegenProperty unaliasedProp = fromProperty("body", unaliasedSchema, false);
Boolean dataTypeMismatch = !cp.dataType.equals(unaliasedProp.dataType); Boolean dataTypeMismatch = !cp.dataType.equals(unaliasedProp.dataType);
Boolean baseTypeMismatch = !cp.baseType.equals(unaliasedProp.complexType) && unaliasedProp.complexType != null; Boolean baseTypeMismatch = !cp.baseType.equals(unaliasedProp.complexType) && unaliasedProp.complexType != null;
if (dataTypeMismatch || baseTypeMismatch) { if (dataTypeMismatch || baseTypeMismatch) {
@ -1022,7 +1022,7 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
codegenParameter.isNullable = codegenModel.isNullable; codegenParameter.isNullable = codegenModel.isNullable;
imports.add(codegenParameter.baseType); imports.add(codegenParameter.baseType);
} else { } else {
CodegenProperty codegenProperty = fromProperty("property", schema); CodegenProperty codegenProperty = fromProperty("property", schema, false);
if (codegenProperty != null && codegenProperty.getComplexType() != null && codegenProperty.getComplexType().contains(" | ")) { if (codegenProperty != null && codegenProperty.getComplexType() != null && codegenProperty.getComplexType().contains(" | ")) {
List<String> parts = Arrays.asList(codegenProperty.getComplexType().split(" \\| ")); List<String> parts = Arrays.asList(codegenProperty.getComplexType().split(" \\| "));
@ -2033,7 +2033,7 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
isAdditionalPropertiesTrue = true; isAdditionalPropertiesTrue = true;
// pass in the hashCode as the name to ensure that the returned property is not from the cache // pass in the hashCode as the name to ensure that the returned property is not from the cache
// if we need to set indent on every one, then they need to be different // if we need to set indent on every one, then they need to be different
addPropProp = fromProperty(String.valueOf(property.hashCode()), new Schema()); addPropProp = fromProperty(String.valueOf(property.hashCode()), new Schema(), false);
addPropProp.name = ""; addPropProp.name = "";
addPropProp.baseName = ""; addPropProp.baseName = "";
addPropProp.nameInSnakeCase = null; addPropProp.nameInSnakeCase = null;
@ -2042,14 +2042,14 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
} else if (schema.getAdditionalProperties() instanceof Boolean) { } else if (schema.getAdditionalProperties() instanceof Boolean) {
if (Boolean.TRUE.equals(schema.getAdditionalProperties())) { if (Boolean.TRUE.equals(schema.getAdditionalProperties())) {
isAdditionalPropertiesTrue = true; isAdditionalPropertiesTrue = true;
addPropProp = fromProperty(String.valueOf(property.hashCode()), new Schema()); addPropProp = fromProperty(String.valueOf(property.hashCode()), new Schema(), false);
addPropProp.name = ""; addPropProp.name = "";
addPropProp.baseName = ""; addPropProp.baseName = "";
addPropProp.nameInSnakeCase = null; addPropProp.nameInSnakeCase = null;
additionalPropertiesIsAnyType = true; additionalPropertiesIsAnyType = true;
} }
} else { } else {
addPropProp = fromProperty(String.valueOf(property.hashCode()), (Schema) schema.getAdditionalProperties()); addPropProp = fromProperty(String.valueOf(property.hashCode()), (Schema) schema.getAdditionalProperties(), false);
addPropProp.name = ""; addPropProp.name = "";
addPropProp.baseName = ""; addPropProp.baseName = "";
addPropProp.nameInSnakeCase = null; addPropProp.nameInSnakeCase = null;

View File

@ -443,8 +443,8 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
} }
@Override @Override
public ExtendedCodegenProperty fromProperty(String name, Schema p) { public ExtendedCodegenProperty fromProperty(String name, Schema p, boolean required) {
CodegenProperty cp = super.fromProperty(name, p); CodegenProperty cp = super.fromProperty(name, p, required);
return new ExtendedCodegenProperty(cp); return new ExtendedCodegenProperty(cp);
} }
@ -515,7 +515,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
if (op.returnPassthrough instanceof String && cm != null) { if (op.returnPassthrough instanceof String && cm != null) {
cp = (ExtendedCodegenProperty) this.processCodeGenModel(cm).vars.get(1); cp = (ExtendedCodegenProperty) this.processCodeGenModel(cm).vars.get(1);
} else if (responseSchema != null) { } else if (responseSchema != null) {
cp = fromProperty("response", responseSchema); cp = fromProperty("response", responseSchema, false);
this.processCodegenProperty(cp, "", null); this.processCodegenProperty(cp, "", null);
} }

View File

@ -4220,4 +4220,29 @@ public class DefaultCodegenTest {
Assert.assertEquals(codegenParameter.defaultValue, "1971-12-19T03:39:57-08:00"); Assert.assertEquals(codegenParameter.defaultValue, "1971-12-19T03:39:57-08:00");
Assert.assertEquals(codegenParameter.getSchema(), null); Assert.assertEquals(codegenParameter.getSchema(), null);
} }
@Test
public void testFromPropertyRequiredAndOptional() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_12857.yaml");
final DefaultCodegen codegen = new DefaultCodegen();
codegen.setOpenAPI(openAPI);
codegen.setDisallowAdditionalPropertiesIfNotPresent(false);
String modelName = "FooRequired";
Schema sc = openAPI.getComponents().getSchemas().get(modelName);
CodegenModel fooRequired = codegen.fromModel(modelName, sc);
modelName = "FooOptional";
sc = openAPI.getComponents().getSchemas().get(modelName);
CodegenModel fooOptional = codegen.fromModel(modelName, sc);
Assert.assertTrue(fooRequired.vars.get(0).required);
Assert.assertEquals(fooRequired.vars.get(0).name, "foo");
Assert.assertEquals(fooRequired.requiredVars.size(), 1);
Assert.assertEquals(fooRequired.requiredVars.get(0).name, "foo");
Assert.assertTrue(fooRequired.requiredVars.get(0).required);
Assert.assertFalse(fooOptional.vars.get(0).required);
Assert.assertEquals(fooOptional.vars.get(0).name, "foo");
Assert.assertEquals(fooOptional.requiredVars.size(), 0);
}
} }

View File

@ -0,0 +1,17 @@
openapi: 3.0.3
info:
title: openapi 3.0.3 sample spec
description: sample spec for testing openapi functionality, built from json schema
tests for draft6
version: 0.0.1
paths: {}
components:
schemas:
FooRequired:
properties:
foo: {}
required:
- foo
FooOptional:
properties:
foo: {}

View File

@ -5,7 +5,7 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**Name** | **string** | | [optional] **Name** | **string** | | [optional]
**PetType** | **string** | | [default to PetTypeEnum.ChildCat] **PetType** | **string** | | [optional] [default to PetTypeEnum.ChildCat]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) [[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

@ -53,8 +53,8 @@ namespace Org.OpenAPITools.Model
/// Gets or Sets PetType /// Gets or Sets PetType
/// </summary> /// </summary>
[DataMember(Name = "pet_type", IsRequired = true, EmitDefaultValue = false)] [DataMember(Name = "pet_type", EmitDefaultValue = false)]
public PetTypeEnum PetType public PetTypeEnum? PetType
{ {
get{ return _PetType;} get{ return _PetType;}
set set
@ -63,7 +63,7 @@ namespace Org.OpenAPITools.Model
_flagPetType = true; _flagPetType = true;
} }
} }
private PetTypeEnum _PetType; private PetTypeEnum? _PetType;
private bool _flagPetType; private bool _flagPetType;
/// <summary> /// <summary>
@ -86,10 +86,9 @@ namespace Org.OpenAPITools.Model
/// Initializes a new instance of the <see cref="ChildCat" /> class. /// Initializes a new instance of the <see cref="ChildCat" /> class.
/// </summary> /// </summary>
/// <param name="name">name.</param> /// <param name="name">name.</param>
/// <param name="petType">petType (required) (default to PetTypeEnum.ChildCat).</param> /// <param name="petType">petType (default to PetTypeEnum.ChildCat).</param>
public ChildCat(string name = default(string), PetTypeEnum petType = PetTypeEnum.ChildCat) : base() public ChildCat(string name = default(string), PetTypeEnum? petType = PetTypeEnum.ChildCat) : base()
{ {
this._PetType = petType;
this._Name = name; this._Name = name;
if (this.Name != null) if (this.Name != null)
{ {

View File

@ -5,7 +5,7 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**Name** | **string** | | [optional] **Name** | **string** | | [optional]
**PetType** | **string** | | [default to PetTypeEnum.ChildCat] **PetType** | **string** | | [optional] [default to PetTypeEnum.ChildCat]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) [[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

@ -53,8 +53,8 @@ namespace Org.OpenAPITools.Model
/// <summary> /// <summary>
/// Gets or Sets PetType /// Gets or Sets PetType
/// </summary> /// </summary>
[DataMember(Name = "pet_type", IsRequired = true, EmitDefaultValue = false)] [DataMember(Name = "pet_type", EmitDefaultValue = false)]
public PetTypeEnum PetType { get; set; } public PetTypeEnum? PetType { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ChildCat" /> class. /// Initializes a new instance of the <see cref="ChildCat" /> class.
/// </summary> /// </summary>
@ -67,11 +67,11 @@ namespace Org.OpenAPITools.Model
/// Initializes a new instance of the <see cref="ChildCat" /> class. /// Initializes a new instance of the <see cref="ChildCat" /> class.
/// </summary> /// </summary>
/// <param name="name">name.</param> /// <param name="name">name.</param>
/// <param name="petType">petType (required) (default to PetTypeEnum.ChildCat).</param> /// <param name="petType">petType (default to PetTypeEnum.ChildCat).</param>
public ChildCat(string name = default(string), PetTypeEnum petType = PetTypeEnum.ChildCat) : base() public ChildCat(string name = default(string), PetTypeEnum? petType = PetTypeEnum.ChildCat) : base()
{ {
this.PetType = petType;
this.Name = name; this.Name = name;
this.PetType = petType;
this.AdditionalProperties = new Dictionary<string, object>(); this.AdditionalProperties = new Dictionary<string, object>();
} }

View File

@ -5,7 +5,7 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**Name** | **string** | | [optional] **Name** | **string** | | [optional]
**PetType** | **string** | | [default to PetTypeEnum.ChildCat] **PetType** | **string** | | [optional] [default to PetTypeEnum.ChildCat]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) [[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

@ -52,8 +52,8 @@ namespace Org.OpenAPITools.Model
/// <summary> /// <summary>
/// Gets or Sets PetType /// Gets or Sets PetType
/// </summary> /// </summary>
[DataMember(Name = "pet_type", IsRequired = true, EmitDefaultValue = false)] [DataMember(Name = "pet_type", EmitDefaultValue = false)]
public PetTypeEnum PetType { get; set; } public PetTypeEnum? PetType { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ChildCat" /> class. /// Initializes a new instance of the <see cref="ChildCat" /> class.
/// </summary> /// </summary>
@ -66,11 +66,11 @@ namespace Org.OpenAPITools.Model
/// Initializes a new instance of the <see cref="ChildCat" /> class. /// Initializes a new instance of the <see cref="ChildCat" /> class.
/// </summary> /// </summary>
/// <param name="name">name.</param> /// <param name="name">name.</param>
/// <param name="petType">petType (required) (default to PetTypeEnum.ChildCat).</param> /// <param name="petType">petType (default to PetTypeEnum.ChildCat).</param>
public ChildCat(string name = default(string), PetTypeEnum petType = PetTypeEnum.ChildCat) : base() public ChildCat(string name = default(string), PetTypeEnum? petType = PetTypeEnum.ChildCat) : base()
{ {
this.PetType = petType;
this.Name = name; this.Name = name;
this.PetType = petType;
this.AdditionalProperties = new Dictionary<string, object>(); this.AdditionalProperties = new Dictionary<string, object>();
} }

View File

@ -5,7 +5,7 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**Name** | **string** | | [optional] **Name** | **string** | | [optional]
**PetType** | **string** | | [default to PetTypeEnum.ChildCat] **PetType** | **string** | | [optional] [default to PetTypeEnum.ChildCat]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) [[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

@ -52,8 +52,8 @@ namespace Org.OpenAPITools.Model
/// <summary> /// <summary>
/// Gets or Sets PetType /// Gets or Sets PetType
/// </summary> /// </summary>
[DataMember(Name = "pet_type", IsRequired = true, EmitDefaultValue = false)] [DataMember(Name = "pet_type", EmitDefaultValue = false)]
public PetTypeEnum PetType { get; set; } public PetTypeEnum? PetType { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ChildCat" /> class. /// Initializes a new instance of the <see cref="ChildCat" /> class.
/// </summary> /// </summary>
@ -66,11 +66,11 @@ namespace Org.OpenAPITools.Model
/// Initializes a new instance of the <see cref="ChildCat" /> class. /// Initializes a new instance of the <see cref="ChildCat" /> class.
/// </summary> /// </summary>
/// <param name="name">name.</param> /// <param name="name">name.</param>
/// <param name="petType">petType (required) (default to PetTypeEnum.ChildCat).</param> /// <param name="petType">petType (default to PetTypeEnum.ChildCat).</param>
public ChildCat(string name = default(string), PetTypeEnum petType = PetTypeEnum.ChildCat) : base() public ChildCat(string name = default(string), PetTypeEnum? petType = PetTypeEnum.ChildCat) : base()
{ {
this.PetType = petType;
this.Name = name; this.Name = name;
this.PetType = petType;
this.AdditionalProperties = new Dictionary<string, object>(); this.AdditionalProperties = new Dictionary<string, object>();
} }

View File

@ -5,7 +5,7 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**Name** | **string** | | [optional] **Name** | **string** | | [optional]
**PetType** | **string** | | [default to PetTypeEnum.ChildCat] **PetType** | **string** | | [optional] [default to PetTypeEnum.ChildCat]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) [[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

@ -52,8 +52,8 @@ namespace Org.OpenAPITools.Model
/// <summary> /// <summary>
/// Gets or Sets PetType /// Gets or Sets PetType
/// </summary> /// </summary>
[DataMember(Name = "pet_type", IsRequired = true, EmitDefaultValue = false)] [DataMember(Name = "pet_type", EmitDefaultValue = false)]
public PetTypeEnum PetType { get; set; } public PetTypeEnum? PetType { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ChildCat" /> class. /// Initializes a new instance of the <see cref="ChildCat" /> class.
/// </summary> /// </summary>
@ -66,11 +66,11 @@ namespace Org.OpenAPITools.Model
/// Initializes a new instance of the <see cref="ChildCat" /> class. /// Initializes a new instance of the <see cref="ChildCat" /> class.
/// </summary> /// </summary>
/// <param name="name">name.</param> /// <param name="name">name.</param>
/// <param name="petType">petType (required) (default to PetTypeEnum.ChildCat).</param> /// <param name="petType">petType (default to PetTypeEnum.ChildCat).</param>
public ChildCat(string name = default(string), PetTypeEnum petType = PetTypeEnum.ChildCat) : base() public ChildCat(string name = default(string), PetTypeEnum? petType = PetTypeEnum.ChildCat) : base()
{ {
this.PetType = petType;
this.Name = name; this.Name = name;
this.PetType = petType;
this.AdditionalProperties = new Dictionary<string, object>(); this.AdditionalProperties = new Dictionary<string, object>();
} }

View File

@ -5,7 +5,7 @@
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**Name** | **string** | | [optional] **Name** | **string** | | [optional]
**PetType** | **string** | | [default to PetTypeEnum.ChildCat] **PetType** | **string** | | [optional] [default to PetTypeEnum.ChildCat]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) [[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

@ -52,8 +52,8 @@ namespace Org.OpenAPITools.Model
/// <summary> /// <summary>
/// Gets or Sets PetType /// Gets or Sets PetType
/// </summary> /// </summary>
[DataMember(Name = "pet_type", IsRequired = true, EmitDefaultValue = false)] [DataMember(Name = "pet_type", EmitDefaultValue = false)]
public PetTypeEnum PetType { get; set; } public PetTypeEnum? PetType { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ChildCat" /> class. /// Initializes a new instance of the <see cref="ChildCat" /> class.
/// </summary> /// </summary>
@ -63,11 +63,11 @@ namespace Org.OpenAPITools.Model
/// Initializes a new instance of the <see cref="ChildCat" /> class. /// Initializes a new instance of the <see cref="ChildCat" /> class.
/// </summary> /// </summary>
/// <param name="name">name.</param> /// <param name="name">name.</param>
/// <param name="petType">petType (required) (default to PetTypeEnum.ChildCat).</param> /// <param name="petType">petType (default to PetTypeEnum.ChildCat).</param>
public ChildCat(string name = default(string), PetTypeEnum petType = PetTypeEnum.ChildCat) : base() public ChildCat(string name = default(string), PetTypeEnum? petType = PetTypeEnum.ChildCat) : base()
{ {
this.PetType = petType;
this.Name = name; this.Name = name;
this.PetType = petType;
} }
/// <summary> /// <summary>

View File

@ -8,7 +8,7 @@
| Name | Type | Description | Notes | | Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------| |------------ | ------------- | ------------- | -------------|
|**name** | **String** | | [optional] | |**name** | **String** | | [optional] |
|**petType** | [**String**](#String) | | | |**petType** | [**String**](#String) | | [optional] |

View File

@ -105,10 +105,10 @@ public class ChildCat extends ParentPet {
* Get petType * Get petType
* @return petType * @return petType
**/ **/
@jakarta.annotation.Nonnull @jakarta.annotation.Nullable
@ApiModelProperty(required = true, value = "") @ApiModelProperty(value = "")
@JsonProperty(JSON_PROPERTY_PET_TYPE) @JsonProperty(JSON_PROPERTY_PET_TYPE)
@JsonInclude(value = JsonInclude.Include.ALWAYS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public String getPetType() { public String getPetType() {
return petType; return petType;
@ -116,7 +116,7 @@ public class ChildCat extends ParentPet {
@JsonProperty(JSON_PROPERTY_PET_TYPE) @JsonProperty(JSON_PROPERTY_PET_TYPE)
@JsonInclude(value = JsonInclude.Include.ALWAYS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setPetType(String petType) { public void setPetType(String petType) {
if (!PET_TYPE_VALUES.contains(petType)) { if (!PET_TYPE_VALUES.contains(petType)) {
throw new IllegalArgumentException(petType + " is invalid. Possible values for petType: " + String.join(", ", PET_TYPE_VALUES)); throw new IllegalArgumentException(petType + " is invalid. Possible values for petType: " + String.join(", ", PET_TYPE_VALUES));

View File

@ -359,7 +359,7 @@ export interface ChildCat extends ParentPet {
* @type {string} * @type {string}
* @memberof ChildCat * @memberof ChildCat
*/ */
'pet_type': ChildCatPetTypeEnum; 'pet_type'?: ChildCatPetTypeEnum;
} }
export const ChildCatPetTypeEnum = { export const ChildCatPetTypeEnum = {

View File

@ -8,7 +8,7 @@
| Name | Type | Description | Notes | | Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------| |------------ | ------------- | ------------- | -------------|
|**name** | **String** | | [optional] | |**name** | **String** | | [optional] |
|**petType** | [**String**](#String) | | | |**petType** | [**String**](#String) | | [optional] |

View File

@ -105,10 +105,10 @@ public class ChildCat extends ParentPet {
* Get petType * Get petType
* @return petType * @return petType
**/ **/
@javax.annotation.Nonnull @javax.annotation.Nullable
@ApiModelProperty(required = true, value = "") @ApiModelProperty(value = "")
@JsonProperty(JSON_PROPERTY_PET_TYPE) @JsonProperty(JSON_PROPERTY_PET_TYPE)
@JsonInclude(value = JsonInclude.Include.ALWAYS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public String getPetType() { public String getPetType() {
return petType; return petType;
@ -116,7 +116,7 @@ public class ChildCat extends ParentPet {
@JsonProperty(JSON_PROPERTY_PET_TYPE) @JsonProperty(JSON_PROPERTY_PET_TYPE)
@JsonInclude(value = JsonInclude.Include.ALWAYS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setPetType(String petType) { public void setPetType(String petType) {
if (!PET_TYPE_VALUES.contains(petType)) { if (!PET_TYPE_VALUES.contains(petType)) {
throw new IllegalArgumentException(petType + " is invalid. Possible values for petType: " + String.join(", ", PET_TYPE_VALUES)); throw new IllegalArgumentException(petType + " is invalid. Possible values for petType: " + String.join(", ", PET_TYPE_VALUES));

View File

@ -1315,7 +1315,7 @@ skip_deserialization | bool | default is False | when True, headers and body wil
Name | Type | Description | Notes Name | Type | Description | Notes
------------ | ------------- | ------------- | ------------- ------------ | ------------- | ------------- | -------------
**additionalMetadata** | **str** | Additional data to pass to server | [optional] **additionalMetadata** | **str** | Additional data to pass to server | [optional]
**file** | **file_type** | file to upload | **file** | **file_type** | file to upload | [optional]
**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] **any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional]
### path_params ### path_params

View File

@ -73,6 +73,10 @@ class SchemaForRequestBodyApplicationXWwwFormUrlencoded(
DictSchema DictSchema
): ):
_required_property_names = set(( _required_property_names = set((
'number',
'double',
'pattern_without_delimiter',
'byte',
)) ))
@ -171,6 +175,10 @@ class SchemaForRequestBodyApplicationXWwwFormUrlencoded(
def __new__( def __new__(
cls, cls,
*args: typing.Union[dict, frozendict, ], *args: typing.Union[dict, frozendict, ],
number: number,
double: double,
pattern_without_delimiter: pattern_without_delimiter,
byte: byte,
integer: typing.Union[integer, Unset] = unset, integer: typing.Union[integer, Unset] = unset,
int32: typing.Union[int32, Unset] = unset, int32: typing.Union[int32, Unset] = unset,
int64: typing.Union[int64, Unset] = unset, int64: typing.Union[int64, Unset] = unset,
@ -186,6 +194,10 @@ class SchemaForRequestBodyApplicationXWwwFormUrlencoded(
return super().__new__( return super().__new__(
cls, cls,
*args, *args,
number=number,
double=double,
pattern_without_delimiter=pattern_without_delimiter,
byte=byte,
integer=integer, integer=integer,
int32=int32, int32=int32,
int64=int64, int64=int64,

View File

@ -73,6 +73,8 @@ class SchemaForRequestBodyApplicationXWwwFormUrlencoded(
DictSchema DictSchema
): ):
_required_property_names = set(( _required_property_names = set((
'param',
'param2',
)) ))
param = StrSchema param = StrSchema
param2 = StrSchema param2 = StrSchema
@ -81,12 +83,16 @@ class SchemaForRequestBodyApplicationXWwwFormUrlencoded(
def __new__( def __new__(
cls, cls,
*args: typing.Union[dict, frozendict, ], *args: typing.Union[dict, frozendict, ],
param: param,
param2: param2,
_configuration: typing.Optional[Configuration] = None, _configuration: typing.Optional[Configuration] = None,
**kwargs: typing.Type[Schema], **kwargs: typing.Type[Schema],
) -> 'SchemaForRequestBodyApplicationXWwwFormUrlencoded': ) -> 'SchemaForRequestBodyApplicationXWwwFormUrlencoded':
return super().__new__( return super().__new__(
cls, cls,
*args, *args,
param=param,
param2=param2,
_configuration=_configuration, _configuration=_configuration,
**kwargs, **kwargs,
) )

View File

@ -75,6 +75,7 @@ class SchemaForRequestBodyMultipartFormData(
DictSchema DictSchema
): ):
_required_property_names = set(( _required_property_names = set((
'file',
)) ))
additionalMetadata = StrSchema additionalMetadata = StrSchema
file = BinarySchema file = BinarySchema
@ -83,6 +84,7 @@ class SchemaForRequestBodyMultipartFormData(
def __new__( def __new__(
cls, cls,
*args: typing.Union[dict, frozendict, ], *args: typing.Union[dict, frozendict, ],
file: file,
additionalMetadata: typing.Union[additionalMetadata, Unset] = unset, additionalMetadata: typing.Union[additionalMetadata, Unset] = unset,
_configuration: typing.Optional[Configuration] = None, _configuration: typing.Optional[Configuration] = None,
**kwargs: typing.Type[Schema], **kwargs: typing.Type[Schema],
@ -90,6 +92,7 @@ class SchemaForRequestBodyMultipartFormData(
return super().__new__( return super().__new__(
cls, cls,
*args, *args,
file=file,
additionalMetadata=additionalMetadata, additionalMetadata=additionalMetadata,
_configuration=_configuration, _configuration=_configuration,
**kwargs, **kwargs,

View File

@ -101,6 +101,7 @@ class SchemaForRequestBodyMultipartFormData(
DictSchema DictSchema
): ):
_required_property_names = set(( _required_property_names = set((
'requiredFile',
)) ))
additionalMetadata = StrSchema additionalMetadata = StrSchema
requiredFile = BinarySchema requiredFile = BinarySchema
@ -109,6 +110,7 @@ class SchemaForRequestBodyMultipartFormData(
def __new__( def __new__(
cls, cls,
*args: typing.Union[dict, frozendict, ], *args: typing.Union[dict, frozendict, ],
requiredFile: requiredFile,
additionalMetadata: typing.Union[additionalMetadata, Unset] = unset, additionalMetadata: typing.Union[additionalMetadata, Unset] = unset,
_configuration: typing.Optional[Configuration] = None, _configuration: typing.Optional[Configuration] = None,
**kwargs: typing.Type[Schema], **kwargs: typing.Type[Schema],
@ -116,6 +118,7 @@ class SchemaForRequestBodyMultipartFormData(
return super().__new__( return super().__new__(
cls, cls,
*args, *args,
requiredFile=requiredFile,
additionalMetadata=additionalMetadata, additionalMetadata=additionalMetadata,
_configuration=_configuration, _configuration=_configuration,
**kwargs, **kwargs,

View File

@ -108,6 +108,7 @@ class SchemaForRequestBodyMultipartFormData(
cls, cls,
*args: typing.Union[dict, frozendict, ], *args: typing.Union[dict, frozendict, ],
additionalMetadata: typing.Union[additionalMetadata, Unset] = unset, additionalMetadata: typing.Union[additionalMetadata, Unset] = unset,
file: typing.Union[file, Unset] = unset,
_configuration: typing.Optional[Configuration] = None, _configuration: typing.Optional[Configuration] = None,
**kwargs: typing.Type[Schema], **kwargs: typing.Type[Schema],
) -> 'SchemaForRequestBodyMultipartFormData': ) -> 'SchemaForRequestBodyMultipartFormData':
@ -115,6 +116,7 @@ class SchemaForRequestBodyMultipartFormData(
cls, cls,
*args, *args,
additionalMetadata=additionalMetadata, additionalMetadata=additionalMetadata,
file=file,
_configuration=_configuration, _configuration=_configuration,
**kwargs, **kwargs,
) )