OpenAPITools / OpenAPITools/openapi-generator
[BUG] Referenced Component Schema With Properties Not Being Instantiated As ObjectSchema
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
While processing the OpenAPI spec, an ObjectSchema that has a property that is a referenced ObjectSchema that also has properties does not populate the vars[] entry correctly as the DefaultCodeGen.fromProperty() does not correctly populate the CodegGenProperty
In the extract below, you can see the test_referenced_object_schema is correctly identified as an ObjectSchema an all the properties are picked up description, xml etc.
2022-12-15T10:38:50.076+0000 [DEBUG] [org.openapitools.codegen.DefaultCodegen] debugging fromProperty for test_referenced_object_schema : class ObjectSchema {
class Schema {
type: object
format: null
$ref: null
description: Test Referenced Object Schema Description
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: null
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: class XML {
name: XMLNameTestReferencedObjectSchema
namespace: null
prefix: null
attribute: null
wrapped: null
}
}
}
If we look at test_with_properties_referenced_object_schema we can see none of the properties are picked up, description, xml etc and the class is just Schema
2022-12-15T10:38:50.078+0000 [DEBUG] [org.openapitools.codegen.DefaultCodegen] debugging fromProperty for test_with_properties_referenced_object_schema : class Schema {
type: null
format: null
$ref: #/components/schemas/TestWithPropertiesReferencedObjectSchema
description: null
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: null
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
While searching for issues I found 9371 This looks like it has the same problem where referenced schemas in an array are not picking up the XML Name, and I think this is because of the same issue with the Schema Map not being populated with an ObjectSchema when properties are defined in the referenced schema.
openapi-generator version
6.2.1
OpenAPI declaration file content or url
---
openapi: "3.0.3"
info:
description: "Supplier Marketplace Experiences API"
title: "Supplier Marketplace Experiences API"
version: "1.0.0"
tags:
- name: TestTag
description: "Test Tag"
security:
- bearerAuth: []
paths:
/testpath:
post:
summary: Test the path
description: Test the path
tags:
- TestTag
operationId: testOperationId
requestBody:
$ref: "#/components/requestBodies/TestRequestBody"
responses:
200:
$ref: "#/components/responses/TestResponse"
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
requestBodies:
TestRequestBody:
content:
application/xml:
schema:
$ref: "#/components/schemas/TestRequestObjectSchema"
application/json:
schema:
$ref: "#/components/schemas/TestRequestObjectSchema"
responses:
TestResponse:
description: Test Response Description
content:
application/xml:
schema:
$ref: "#/components/schemas/TestResponseObjectSchema"
schemas:
TestRequestObjectSchema:
description: Test Request Object Schema
type: object
xml:
name: 'Test_Request'
namespace: 'http://www.test.org'
properties:
test_property_integer_schema:
description: Testing an integer property defined inline
type: integer
xml:
name: 'TestPropertyIntegerSchema'
attribute: true
TestResponseObjectSchema:
description: Test Response Object Schema
type: object
xml:
name: 'TestResponseObjectSchema'
namespace: 'http://www.test.org'
properties:
test_string:
$ref: '#/components/schemas/TestReferencedStringSchema'
test_referenced_object_schema:
$ref: '#/components/schemas/TestReferencedObjectSchema'
test_with_properties_referenced_object_schema:
$ref: '#/components/schemas/TestWithPropertiesReferencedObjectSchema'
TestReferencedStringSchema:
description: Test Referenced String Schema Description
type: string
xml:
name: XMLNameTestReferencedStringSchema
attribute: true
TestReferencedObjectSchema:
description: Test Referenced Object Schema Description
type: object
xml:
name: XMLNameTestReferencedObjectSchema
TestWithPropertiesReferencedObjectSchema:
description: Test With Properties Referenced Object Schema
type: object
xml:
name: XMLNameTestWithPropertiesReferencedObjectSchema
properties:
test_with_properties_string_schema:
type: string
description: Test With Properties String Schema Description
xml:
name: XMLNameTestWithPropertiesStringSchema
Generation Details
We used the Gradle Plugin
Steps to reproduce
Use the above spec. This happens for all properties of an ObjectSchema that reference another object schema that also has properties.
Below is the output for fromProperty that is called during addVars()
2022-12-15T10:38:50.069+0000 [DEBUG] [org.openapitools.codegen.DefaultCodegen] debugging fromProperty for test_property_integer_schema : class IntegerSchema {
class Schema {
type: integer
format: null
$ref: null
description: Testing an integer property defined inline
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: null
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: class XML {
name: TestPropertyIntegerSchema
namespace: null
prefix: null
attribute: true
wrapped: null
}
}
}
2022-12-15T10:38:50.071+0000 [DEBUG] [org.openapitools.codegen.DefaultCodegen] debugging from property return: CodegenProperty{openApiType='integer', baseName='test_property_integer_schema', complexType='null', getter='getTestPropertyIntegerSchema', setter='setTestPropertyIntegerSchema', description='Testing an integer property defined inline', dataType='Integer', datatypeWithEnum='Integer', dataFormat='null', name='testPropertyIntegerSchema', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.test_property_integer_schema;', baseType='Integer', containerType='null', title='null', unescapedDescription='Testing an integer property defined inline', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{
"type" : "integer",
"description" : "Testing an integer property defined inline",
"xml" : {
"name" : "TestPropertyIntegerSchema",
"attribute" : true
}
}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=false, isNumeric=true, isInteger=true, isShort=false, isLong=false, isUnboundedInteger=true, 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, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isInnerEnum=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='TestPropertyIntegerSchema', nameInSnakeCase='TEST_PROPERTY_INTEGER_SCHEMA', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=true, xmlPrefix='null', xmlName='TestPropertyIntegerSchema', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=null, dependentRequired=null, contains=null}
2022-12-15T10:38:50.072+0000 [DEBUG] [org.openapitools.codegen.DefaultCodegen] debugging fromProperty for test_string : class StringSchema {
class Schema {
type: string
format: null
$ref: null
description: Test Referenced String Schema Description
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: null
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: class XML {
name: XMLNameTestReferencedStringSchema
namespace: null
prefix: null
attribute: true
wrapped: null
}
}
}
2022-12-15T10:38:50.075+0000 [DEBUG] [org.openapitools.codegen.DefaultCodegen] debugging from property return: CodegenProperty{openApiType='string', baseName='test_string', complexType='null', getter='getTestString', setter='setTestString', description='Test Referenced String Schema Description', dataType='String', datatypeWithEnum='String', dataFormat='null', name='testString', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.test_string;', baseType='String', containerType='null', title='null', unescapedDescription='Test Referenced String Schema Description', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{
"type" : "string",
"description" : "Test Referenced String Schema Description",
"xml" : {
"name" : "XMLNameTestReferencedStringSchema",
"attribute" : true
}
}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=true, 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, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isInnerEnum=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='TestString', nameInSnakeCase='TEST_STRING', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=true, xmlPrefix='null', xmlName='XMLNameTestReferencedStringSchema', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=null, dependentRequired=null, contains=null}
2022-12-15T10:38:50.076+0000 [DEBUG] [org.openapitools.codegen.DefaultCodegen] debugging fromProperty for test_referenced_object_schema : class ObjectSchema {
class Schema {
type: object
format: null
$ref: null
description: Test Referenced Object Schema Description
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: null
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: class XML {
name: XMLNameTestReferencedObjectSchema
namespace: null
prefix: null
attribute: null
wrapped: null
}
}
}
2022-12-15T10:38:50.078+0000 [DEBUG] [org.openapitools.codegen.DefaultCodegen] debugging from property return: CodegenProperty{openApiType='object', baseName='test_referenced_object_schema', complexType='null', getter='getTestReferencedObjectSchema', setter='setTestReferencedObjectSchema', description='Test Referenced Object Schema Description', dataType='Object', datatypeWithEnum='Object', dataFormat='null', name='testReferencedObjectSchema', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.test_referenced_object_schema;', baseType='Object', containerType='null', title='null', unescapedDescription='Test Referenced Object Schema Description', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{
"type" : "object",
"description" : "Test Referenced Object Schema Description",
"xml" : {
"name" : "XMLNameTestReferencedObjectSchema"
}
}', minimum='null', maximum='null', 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, isFreeFormObject=true, isArray=false, isMap=false, isEnum=false, isInnerEnum=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='TestReferencedObjectSchema', nameInSnakeCase='TEST_REFERENCED_OBJECT_SCHEMA', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='XMLNameTestReferencedObjectSchema', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=null, dependentRequired=null, contains=null}
2022-12-15T10:38:50.078+0000 [DEBUG] [org.openapitools.codegen.DefaultCodegen] debugging fromProperty for test_with_properties_referenced_object_schema : class Schema {
type: null
format: null
$ref: #/components/schemas/TestWithPropertiesReferencedObjectSchema
description: null
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: null
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
2022-12-15T10:38:50.083+0000 [DEBUG] [org.openapitools.codegen.DefaultCodegen] debugging from property return: CodegenProperty{openApiType='TestWithPropertiesReferencedObjectSchema', baseName='test_with_properties_referenced_object_schema', complexType='TestWithPropertiesReferencedObjectSchema', getter='getTestWithPropertiesReferencedObjectSchema', setter='setTestWithPropertiesReferencedObjectSchema', description='null', dataType='TestWithPropertiesReferencedObjectSchema', datatypeWithEnum='TestWithPropertiesReferencedObjectSchema', dataFormat='null', name='testWithPropertiesReferencedObjectSchema', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.test_with_properties_referenced_object_schema;', baseType='TestWithPropertiesReferencedObjectSchema', containerType='null', title='null', unescapedDescription='null', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{
"$ref" : "#/components/schemas/TestWithPropertiesReferencedObjectSchema"
}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=false, isModel=true, 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, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isInnerEnum=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='TestWithPropertiesReferencedObjectSchema', nameInSnakeCase='TEST_WITH_PROPERTIES_REFERENCED_OBJECT_SCHEMA', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, requiredVarsMap=null, ref=#/components/schemas/TestWithPropertiesReferencedObjectSchema, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=null, dependentRequired=null, contains=null}
2022-12-15T10:38:50.086+0000 [INFO] [org.openapitools.codegen.DefaultGenerator] Model TestReferencedObjectSchema not generated since it's a free-form object
2022-12-15T10:38:50.087+0000 [DEBUG] [org.openapitools.codegen.DefaultCodegen] debugging fromProperty for test_with_properties_string_schema : class StringSchema {
class Schema {
type: string
format: null
$ref: null
description: Test With Properties String Schema Description
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: null
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: class XML {
name: XMLNameTestWithPropertiesStringSchema
namespace: null
prefix: null
attribute: null
wrapped: null
}
}
}
2022-12-15T10:38:50.089+0000 [DEBUG] [org.openapitools.codegen.DefaultCodegen] debugging from property return: CodegenProperty{openApiType='string', baseName='test_with_properties_string_schema', complexType='null', getter='getTestWithPropertiesStringSchema', setter='setTestWithPropertiesStringSchema', description='Test With Properties String Schema Description', dataType='String', datatypeWithEnum='String', dataFormat='null', name='testWithPropertiesStringSchema', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.test_with_properties_string_schema;', baseType='String', containerType='null', title='null', unescapedDescription='Test With Properties String Schema Description', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{
"type" : "string",
"description" : "Test With Properties String Schema Description",
"xml" : {
"name" : "XMLNameTestWithPropertiesStringSchema"
}
}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=true, 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, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isInnerEnum=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='TestWithPropertiesStringSchema', nameInSnakeCase='TEST_WITH_PROPERTIES_STRING_SCHEMA', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='XMLNameTestWithPropertiesStringSchema', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=null, dependentRequired=null, contains=null}
Related issues/PRs
Suggest a fix
I believe the issue is where the schema map is being populated. Other defined schemas like StringSchema or ObjectSchema with no properties are correctly instantiated as ObjectSchema.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in DefaultCodegen.fromProperty() and follow how addVars() handles a property whose schema is a reference to an object with properties. Reproduce the issue with the OpenAPI YAML spec and Gradle plugin setup described here. Done means the referenced object remains an ObjectSchema and its properties and metadata populate the resulting CodegenProperty and vars entry.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100