Open AlanCitrix opened 10 months ago
schema:
default: "available"
oneOf:
- $ref: '#/components/schemas/StatusType'
If you change oneOf to allOf, would that work?
Unfortunately that produces the same result. Here is the debug model:
}, {
"openApiType" : "interface{}",
"baseName" : "status",
"getter" : "GetStatus",
"setter" : "setStatus",
"dataType" : "interface{}",
"datatypeWithEnum" : "interface{}",
"name" : "Status",
"defaultValueWithParam" : " = data.status;",
"baseType" : "interface{}",
"example" : "null",
"jsonSchema" : "{\r\n \"schema\" : {\r\n \"type\" : \"string\",\r\n \"enum\" : [ \"available\", \"pending\", \"sold\" ]\r\n }\r\n}",
"exclusiveMinimum" : false,
"exclusiveMaximum" : false,
"required" : false,
"deprecated" : false,
"hasMoreNonReadOnly" : false,
"isPrimitiveType" : true,
"isModel" : false,
"isContainer" : false,
"isString" : false,
"isNumeric" : false,
"isInteger" : false,
"isShort" : false,
"isLong" : false,
"isUnboundedInteger" : false,
"isNumber" : false,
"isFloat" : false,
"isDouble" : false,
"isDecimal" : false,
"isByteArray" : false,
"isBinary" : false,
"isFile" : false,
"isBoolean" : false,
"isDate" : false,
"isDateTime" : false,
"isUuid" : false,
"isUri" : false,
"isEmail" : false,
"isPassword" : false,
"isNull" : false,
"isVoid" : false,
"isFreeFormObject" : false,
"isAnyType" : true,
"isArray" : false,
"isMap" : false,
"isEnum" : false,
"isInnerEnum" : false,
"isEnumRef" : false,
"isReadOnly" : false,
"isWriteOnly" : false,
"isNullable" : true,
"isSelfReference" : false,
"isCircularReference" : false,
"isDiscriminator" : false,
"isNew" : false,
"vars" : [ ],
"requiredVars" : [ ],
"vendorExtensions" : {
"schema" : {
"type" : "string",
"enum" : [ "available", "pending", "sold" ]
},
"x-golang-is-container" : true,
"x-go-base-type" : "interface{}"
},
"hasValidation" : false,
"isInherited" : false,
"nameInCamelCase" : "status",
"nameInSnakeCase" : "STATUS",
"uniqueItems" : false,
"isXmlAttribute" : false,
"isXmlWrapped" : false,
"additionalPropertiesIsAnyType" : false,
"hasVars" : false,
"hasRequired" : false,
"hasDiscriminatorWithNonEmptyMapping" : false,
"hasMultipleTypes" : false,
"schemaIsFromAdditionalProperties" : false,
"isBooleanSchemaTrue" : false,
"isBooleanSchemaFalse" : false,
"isEnumOrRef" : false,
"hasItems" : false,
"iexclusiveMaximum" : false,
"datatype" : "interface{}"
} ],
Actually my mistake, allOf
did do the trick. There was another bug in the swagger which I've fixed in the first post. There was an extra schema
in the enum. Thanks for the workaround.
components:
schemas:
StatusType:
schema: // <--- removed this and changed to allOf, works now
type: string
enum:
- available
- pending
- sold
Bug Report Checklist
Description
When using an enum schema with
oneOf
anddefault
, the new default value handling from #15126 causes the generated code to not build.openapi-generator version
master @ 8b15d482
OpenAPI declaration file content or url
Generation Details
Generates the following invalid go:
Steps to reproduce
A query parameter using a schema with
default
andoneOf
:Related issues/PRs
Issue introduced by #15126
Suggest a fix
I tried running the generation with
defaultValue=false
but that didn't stop the default value code from being generated: