Skip to content

Commit

Permalink
Updated model generation, addProps handling moved into type object an…
Browse files Browse the repository at this point in the history
…d anyType handling (#10505)

* Updates fromModel helpers

* Samples regenerated

* updateModelForComposedSchema made protected so it can be overridden
  • Loading branch information
spacether committed Oct 1, 2021
1 parent 8c059a8 commit 638a2fa
Show file tree
Hide file tree
Showing 32 changed files with 26 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2381,7 +2381,7 @@ public int hashCode() {

Map<NamedSchema, CodegenProperty> schemaCodegenPropertyCache = new HashMap<NamedSchema, CodegenProperty>();

private void updateModelForComposedSchema(CodegenModel m, Schema schema, Map<String, Schema> allDefinitions) {
protected void updateModelForComposedSchema(CodegenModel m, Schema schema, Map<String, Schema> allDefinitions) {
final ComposedSchema composed = (ComposedSchema) schema;
Map<String, Schema> properties = new LinkedHashMap<String, Schema>();
List<String> required = new ArrayList<String>();
Expand Down Expand Up @@ -2596,6 +2596,8 @@ protected void updateModelForObject(CodegenModel m, Schema schema) {
// additionalProperties must be null, ObjectSchema, or empty Schema
addAdditionPropertiesToCodeGenModel(m, schema);
}
// process 'additionalProperties'
setAddProps(schema, m);
}

protected void updateModelForAnyType(CodegenModel m, Schema schema) {
Expand All @@ -2614,6 +2616,8 @@ protected void updateModelForAnyType(CodegenModel m, Schema schema) {
// passing null to allProperties and allRequired as there's no parent
addVars(m, unaliasPropertySchema(schema.getProperties()), schema.getRequired(), null, null);
}
// process 'additionalProperties'
setAddProps(schema, m);
}


Expand Down Expand Up @@ -2776,9 +2780,6 @@ public int compare(CodegenProperty one, CodegenProperty another) {
Collections.sort(m.allVars, comparator);
}

// process 'additionalProperties'
setAddProps(schema, m);

// post process model properties
if (m.vars != null) {
for (CodegenProperty prop : m.vars) {
Expand All @@ -2794,7 +2795,7 @@ public int compare(CodegenProperty one, CodegenProperty another) {
return m;
}

private void setAddProps(Schema schema, IJsonSchemaValidationProperties property){
protected void setAddProps(Schema schema, IJsonSchemaValidationProperties property){
if (schema.equals(new Schema())) {
// if we are trying to set additionalProperties on an empty schema stop recursing
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,5 +1152,7 @@ protected void updateModelForObject(CodegenModel m, Schema schema) {
addAdditionPropertiesToCodeGenModel(m, schema);
}
}
// process 'additionalProperties'
setAddProps(schema, m);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -385,5 +385,7 @@ protected void updateModelForObject(CodegenModel m, Schema schema) {
addAdditionPropertiesToCodeGenModel(m, schema);
}
}
// process 'additionalProperties'
setAddProps(schema, m);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,7 @@ protected void updateModelForObject(CodegenModel m, Schema schema) {
addAdditionPropertiesToCodeGenModel(m, schema);
}
}
// process 'additionalProperties'
setAddProps(schema, m);
}
}
1 change: 0 additions & 1 deletion samples/client/petstore/python/docs/AnimalFarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | [**[Animal]**](Animal.md) | |
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
1 change: 0 additions & 1 deletion samples/client/petstore/python/docs/EnumClass.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **str** | | defaults to "-efg", must be one of ["_abc", "-efg", "(xyz)", ]
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **float** | |
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
1 change: 0 additions & 1 deletion samples/client/petstore/python/docs/StringEnum.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **str** | | must be one of ["placed", "approved", "delivered", ]
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,7 @@ class AnimalFarm(ModelSimple):
validations = {
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
lazy_import()
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ class EnumClass(ModelSimple):
validations = {
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ class NumberWithValidations(ModelSimple):
},
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ class StringEnum(ModelSimple):
validations = {
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = False

Expand Down
1 change: 0 additions & 1 deletion samples/openapi3/client/petstore/python/docs/AnimalFarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | [**[Animal]**](Animal.md) | |
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | [**[StringEnum]**](StringEnum.md) | |
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **bool** | | defaults to True, must be one of [True, ]
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
1 change: 0 additions & 1 deletion samples/openapi3/client/petstore/python/docs/EnumClass.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **str** | | defaults to "-efg", must be one of ["_abc", "-efg", "(xyz)", ]
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **int** | | must be one of [0, 1, 2, ]
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **int** | | defaults to 0, must be one of [0, ]
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **int** | | defaults to 0, must be one of [0, 1, 2, ]
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **float** | |
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
1 change: 0 additions & 1 deletion samples/openapi3/client/petstore/python/docs/StringEnum.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Name | Type | Description | Notes
**value** | **str** | | must be one of ["placed", "approved", "delivered", "single quoted", '''multiple
lines''', '''double quote
with newline''', ]
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | **str** | | defaults to "placed", must be one of ["placed", "approved", "delivered", ]
**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]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,7 @@ class AnimalFarm(ModelSimple):
validations = {
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
lazy_import()
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,7 @@ class ArrayOfEnums(ModelSimple):
validations = {
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
lazy_import()
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ class BooleanEnum(ModelSimple):
validations = {
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ class EnumClass(ModelSimple):
validations = {
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ class IntegerEnum(ModelSimple):
validations = {
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ class IntegerEnumOneValue(ModelSimple):
validations = {
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ class IntegerEnumWithDefaultValue(ModelSimple):
validations = {
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ class NumberWithValidations(ModelSimple):
},
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,7 @@ class StringEnum(ModelSimple):
validations = {
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ class StringEnumWithDefaultValue(ModelSimple):
validations = {
}

@cached_property
def additional_properties_type():
"""
This must be a method because a model may have properties that are
of type self, this must run after the class is loaded
"""
return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501
additional_properties_type = None

_nullable = False

Expand Down

0 comments on commit 638a2fa

Please sign in to comment.