Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
489985d
Handle null type
sebastien-rosset Apr 30, 2020
c16089e
Handle null type
sebastien-rosset Apr 30, 2020
26865b3
Handle null type. Add 'null' type in the OAS document for testing pur…
sebastien-rosset Apr 30, 2020
48c310e
Handle null type. Add 'null' type in the OAS document for testing pur…
sebastien-rosset Apr 30, 2020
fddb63b
Handle null type. Add 'null' type in the OAS document for testing pur…
sebastien-rosset Apr 30, 2020
cf4e9f8
Handle null type. Add 'null' type in the OAS document for testing pur…
sebastien-rosset Apr 30, 2020
3b59b47
Handle null type. Add 'null' type in the OAS document for testing pur…
sebastien-rosset May 1, 2020
b362f92
Handle null type. Add 'null' type in the OAS document for testing pur…
sebastien-rosset May 1, 2020
ae93643
improve documentation
sebastien-rosset May 1, 2020
f5acfba
Handle 'null' type
sebastien-rosset May 1, 2020
6ba1523
Handle 'null' type. Add unit tests
sebastien-rosset May 1, 2020
de13169
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 1, 2020
2a6a87a
Add NullType for go
sebastien-rosset May 2, 2020
86bc4c0
Add NullType for go
sebastien-rosset May 2, 2020
6b9c0ce
fix modeling of AnyType for go-experimental
sebastien-rosset May 2, 2020
b0d221e
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 2, 2020
a302894
execute scripts in bin directory
sebastien-rosset May 3, 2020
e449c82
resolve merge conflicts
sebastien-rosset May 3, 2020
043f247
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 4, 2020
1e14c94
Add review comments
sebastien-rosset May 4, 2020
747803e
Add 'null' type in oneOf
sebastien-rosset May 4, 2020
aa06a89
Improve OAS YAML file for golang openapi3 samples
sebastien-rosset May 4, 2020
543d406
'Any type' includes the null value, so 'isNullable' should be set to …
sebastien-rosset May 4, 2020
81093c7
'Any type' includes the null value, so 'isNullable' should be set to …
sebastien-rosset May 4, 2020
9a54ea1
Handle AnyType and NullType
sebastien-rosset May 5, 2020
dc7a7e0
handle anytype for go-experimental
sebastien-rosset May 5, 2020
ddc810c
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 5, 2020
03ec914
Log warning instead of error
sebastien-rosset May 5, 2020
bdf3653
anyOf/oneOf
sebastien-rosset May 5, 2020
9dbae45
Change x-golang-is-container extension to x-golang-has-wrapper
sebastien-rosset May 5, 2020
e1417ec
Add code comments
sebastien-rosset May 5, 2020
480ecbe
Handle Object and any type
sebastien-rosset May 5, 2020
a58f121
Handle Object and any type
sebastien-rosset May 5, 2020
01ff36e
Handle object and any type
sebastien-rosset May 5, 2020
ec97db3
add code comments
sebastien-rosset May 6, 2020
431356c
handle additional properties
sebastien-rosset May 6, 2020
93752ff
handle additional properties
sebastien-rosset May 6, 2020
261dbcd
handle additional properties
sebastien-rosset May 6, 2020
aa6b6df
handle anytype and objecttype for go-exerimental
sebastien-rosset May 6, 2020
90c0c9e
Move golang changes to a separate branch
sebastien-rosset May 7, 2020
f56c812
Move golang changes to a separate branch
sebastien-rosset May 7, 2020
b159356
Better names for the OAS document test properties
sebastien-rosset May 7, 2020
ef5149e
Move golang changes to a separate branch
sebastien-rosset May 7, 2020
84162be
Run samples scripts
sebastien-rosset May 7, 2020
ee786cb
Run samples scripts
sebastien-rosset May 7, 2020
058694b
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 7, 2020
82cb0e9
fix unit test issues
sebastien-rosset May 8, 2020
2c5c1cf
Handle none type
sebastien-rosset May 8, 2020
0694f83
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 8, 2020
b6afbc6
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 8, 2020
f275dc9
Fix index out of range exception
sebastien-rosset May 8, 2020
93cc8c8
fix formatting issues
sebastien-rosset May 8, 2020
6939648
fix formatting issues
sebastien-rosset May 8, 2020
8bdca05
fix formatting issues. Finally figured out how to check formatting in…
sebastien-rosset May 8, 2020
4c01344
fix formatting issues
sebastien-rosset May 8, 2020
537c28b
resolve merge conflicts
sebastien-rosset May 11, 2020
71d550c
resolve merge conflicts
sebastien-rosset May 11, 2020
11c52e4
resolve merge conflicts
sebastien-rosset May 12, 2020
eadca7a
Add reference to oneOf schema
sebastien-rosset May 12, 2020
603b6fb
Add model showing unit test failure with ref to oneOf schema
sebastien-rosset May 12, 2020
e16c24e
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 12, 2020
7b2ed9e
Updates get_discriminator_class to return visited_composed_classes
spacether May 12, 2020
9811b8c
Fixes broken test, adds is_valid_type
spacether May 12, 2020
8f1c202
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 12, 2020
5e48c72
run samples scripts
sebastien-rosset May 12, 2020
245c850
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 12, 2020
942edf0
move unit test to test_drawing.py file
sebastien-rosset May 12, 2020
f5050b0
Add more unit tests
sebastien-rosset May 12, 2020
251086b
invoke git pull from spacether fork
sebastien-rosset May 12, 2020
2feed29
invoke git pull from spacether fork
sebastien-rosset May 12, 2020
3a05ff6
invoke git pull from spacether fork
sebastien-rosset May 12, 2020
40ecbfb
Improve unit tests
sebastien-rosset May 12, 2020
d5bd3d3
Merge branch 'python-null-type' of github.com:CiscoM31/openapi-genera…
sebastien-rosset May 13, 2020
42f6781
Add is_nullable_type util function
sebastien-rosset May 13, 2020
c4bc09d
Add unit test for null value
sebastien-rosset May 13, 2020
094e00d
Add 'ShapeOrNull' type to handle the oneOf/anyOf scenario when the ch…
sebastien-rosset May 13, 2020
a0aa380
Support schema property which has to 'oneOf' schema and child schema…
sebastien-rosset May 13, 2020
7274ed5
Support schema property which has to 'oneOf' schema and child schema…
sebastien-rosset May 13, 2020
bb44600
Support schema property which has to 'oneOf' schema and child schema…
sebastien-rosset May 13, 2020
41e97e6
Mustache template should use invokerPackage tag to generate import
sebastien-rosset May 13, 2020
1760f6a
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 13, 2020
b26548e
handle null type in oneOf/anyOf
sebastien-rosset May 13, 2020
87ed97e
handle null type in oneOf/anyOf
sebastien-rosset May 13, 2020
7c4cd94
Add more unit test for nullable shape
sebastien-rosset May 13, 2020
3ae466e
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 13, 2020
6cfe426
resolve merge conflicts
sebastien-rosset May 13, 2020
274ab6c
resolve merge conflicts
sebastien-rosset May 13, 2020
6c55fd9
resolve merge conflicts
sebastien-rosset May 13, 2020
b628667
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 13, 2020
fddadc3
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 13, 2020
8ec12af
handle null type in oneOf/anyOf
sebastien-rosset May 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,32 @@ def attempt_convert_item(input_value, valid_classes, path_to_item,
return input_value


def is_type_nullable(input_type):
"""
Returns true if None is an allowed value for the specified input_type.

A type is nullable if at least one of the following conditions is true:
1. The OAS 'nullable' attribute has been specified,
1. The type is the 'null' type,
1. The type is a anyOf/oneOf composed schema, and a child schema is
the 'null' type.
Args:
input_type (type): the class of the input_value that we are
checking
Returns:
bool
"""
if input_type is none_type:
return True
if issubclass(input_type, ModelComposed):
# If oneOf/anyOf, check if the 'null' type is one of the allowed types.
for t in input_type._composed_schemas.get('oneOf', ()):
if is_type_nullable(t): return True
for t in input_type._composed_schemas.get('anyOf', ()):
if is_type_nullable(t): return True
return False


def is_valid_type(input_class_simple, valid_classes):
"""
Args:
Expand All @@ -883,9 +909,14 @@ def is_valid_type(input_class_simple, valid_classes):
bool
"""
valid_type = input_class_simple in valid_classes
if not valid_type and issubclass(input_class_simple, OpenApiModel):
if not valid_type and (
issubclass(input_class_simple, OpenApiModel) or
input_class_simple is none_type):
for valid_class in valid_classes:
if not valid_class.discriminator:
if input_class_simple is none_type and is_type_nullable(valid_class):
# Schema is oneOf/anyOf and the 'null' type is one of the allowed types.
return True
if not (issubclass(valid_class, OpenApiModel) and valid_class.discriminator):
continue
discr_propertyname_py = list(valid_class.discriminator.keys())[0]
discriminator_classes = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1897,8 +1897,19 @@ components:
properties:
mainShape:
# A property whose value is a 'oneOf' type, and the type is referenced instead
# of being define inline.
# of being defined inline. The value cannot be null.
$ref: '#/components/schemas/Shape'
shapeOrNull:
# A property whose value is a 'oneOf' type, and the type is referenced instead
# of being defined inline. The value may be null because ShapeOrNull has 'null'
# type as a child schema of 'oneOf'.
$ref: '#/components/schemas/ShapeOrNull'
nullableShape:
# A property whose value is a 'oneOf' type, and the type is referenced instead
# of being defined inline. The value may be null because NullableShape has the
# 'nullable: true' attribute. For this specific scenario this is exactly the
# same thing as 'shapeOrNull'.
$ref: '#/components/schemas/NullableShape'
shapes:
type: array
items:
Expand All @@ -1909,6 +1920,25 @@ components:
- $ref: '#/components/schemas/Quadrilateral'
discriminator:
propertyName: shapeType
ShapeOrNull:
description: The value may be a shape or the 'null' value.
This is introduced in OAS schema >= 3.1.
oneOf:
- type: 'null'
- $ref: '#/components/schemas/Triangle'
- $ref: '#/components/schemas/Quadrilateral'
discriminator:
propertyName: shapeType
NullableShape:
description: The value may be a shape or the 'null' value.
The 'nullable' attribute was introduced in OAS schema >= 3.0
and has been deprecated in OAS schema >= 3.1.
oneOf:
- $ref: '#/components/schemas/Triangle'
- $ref: '#/components/schemas/Quadrilateral'
discriminator:
propertyName: shapeType
nullable: true
ShapeInterface:
properties:
shapeType:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,32 @@ def attempt_convert_item(input_value, valid_classes, path_to_item,
return input_value


def is_type_nullable(input_type):
"""
Returns true if None is an allowed value for the specified input_type.

A type is nullable if at least one of the following conditions is true:
1. The OAS 'nullable' attribute has been specified,
1. The type is the 'null' type,
1. The type is a anyOf/oneOf composed schema, and a child schema is
the 'null' type.
Args:
input_type (type): the class of the input_value that we are
checking
Returns:
bool
"""
if input_type is none_type:
return True
if issubclass(input_type, ModelComposed):
# If oneOf/anyOf, check if the 'null' type is one of the allowed types.
for t in input_type._composed_schemas.get('oneOf', ()):
if is_type_nullable(t): return True
for t in input_type._composed_schemas.get('anyOf', ()):
if is_type_nullable(t): return True
return False


def is_valid_type(input_class_simple, valid_classes):
"""
Args:
Expand All @@ -1149,9 +1175,14 @@ def is_valid_type(input_class_simple, valid_classes):
bool
"""
valid_type = input_class_simple in valid_classes
if not valid_type and issubclass(input_class_simple, OpenApiModel):
if not valid_type and (
issubclass(input_class_simple, OpenApiModel) or
input_class_simple is none_type):
for valid_class in valid_classes:
if not valid_class.discriminator:
if input_class_simple is none_type and is_type_nullable(valid_class):
# Schema is oneOf/anyOf and the 'null' type is one of the allowed types.
return True
if not (issubclass(valid_class, OpenApiModel) and valid_class.discriminator):
continue
discr_propertyname_py = list(valid_class.discriminator.keys())[0]
discriminator_classes = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ Class | Method | HTTP request | Description
- [model_return.ModelReturn](docs/ModelReturn.md)
- [name.Name](docs/Name.md)
- [nullable_class.NullableClass](docs/NullableClass.md)
- [nullable_shape.NullableShape](docs/NullableShape.md)
- [number_only.NumberOnly](docs/NumberOnly.md)
- [order.Order](docs/Order.md)
- [outer_composite.OuterComposite](docs/OuterComposite.md)
Expand All @@ -191,6 +192,7 @@ Class | Method | HTTP request | Description
- [scalene_triangle.ScaleneTriangle](docs/ScaleneTriangle.md)
- [shape.Shape](docs/Shape.md)
- [shape_interface.ShapeInterface](docs/ShapeInterface.md)
- [shape_or_null.ShapeOrNull](docs/ShapeOrNull.md)
- [simple_quadrilateral.SimpleQuadrilateral](docs/SimpleQuadrilateral.md)
- [special_model_name.SpecialModelName](docs/SpecialModelName.md)
- [string_boolean_map.StringBooleanMap](docs/StringBooleanMap.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**main_shape** | [**shape.Shape**](Shape.md) | | [optional]
**shape_or_null** | [**shape_or_null.ShapeOrNull**](ShapeOrNull.md) | | [optional]
**nullable_shape** | [**nullable_shape.NullableShape, none_type**](NullableShape.md) | | [optional]
**shapes** | [**[shape.Shape]**](Shape.md) | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# nullable_shape.NullableShape

The value may be a shape or the 'null' value. The 'nullable' attribute was introduced in OAS schema >= 3.0 and has been deprecated in OAS schema >= 3.1.
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**shape_type** | **str** | |
**quadrilateral_type** | **str** | | defaults to nulltype.Null
**triangle_type** | **str** | | defaults to nulltype.Null

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


Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# shape_or_null.ShapeOrNull

The value may be a shape or the 'null' value. This is introduced in OAS schema >= 3.1.
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**shape_type** | **str** | |
**quadrilateral_type** | **str** | | defaults to nulltype.Null
**triangle_type** | **str** | | defaults to nulltype.Null

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


Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
from petstore_api.models.model_return import ModelReturn
from petstore_api.models.name import Name
from petstore_api.models.nullable_class import NullableClass
from petstore_api.models.nullable_shape import NullableShape
from petstore_api.models.number_only import NumberOnly
from petstore_api.models.order import Order
from petstore_api.models.outer_composite import OuterComposite
Expand All @@ -109,6 +110,7 @@
from petstore_api.models.scalene_triangle import ScaleneTriangle
from petstore_api.models.shape import Shape
from petstore_api.models.shape_interface import ShapeInterface
from petstore_api.models.shape_or_null import ShapeOrNull
from petstore_api.models.simple_quadrilateral import SimpleQuadrilateral
from petstore_api.models.special_model_name import SpecialModelName
from petstore_api.models.string_boolean_map import StringBooleanMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,32 @@ def attempt_convert_item(input_value, valid_classes, path_to_item,
return input_value


def is_type_nullable(input_type):
"""
Returns true if None is an allowed value for the specified input_type.

A type is nullable if at least one of the following conditions is true:
1. The OAS 'nullable' attribute has been specified,
1. The type is the 'null' type,
1. The type is a anyOf/oneOf composed schema, and a child schema is
the 'null' type.
Args:
input_type (type): the class of the input_value that we are
checking
Returns:
bool
"""
if input_type is none_type:
return True
if issubclass(input_type, ModelComposed):
# If oneOf/anyOf, check if the 'null' type is one of the allowed types.
for t in input_type._composed_schemas.get('oneOf', ()):
if is_type_nullable(t): return True
for t in input_type._composed_schemas.get('anyOf', ()):
if is_type_nullable(t): return True
return False


def is_valid_type(input_class_simple, valid_classes):
"""
Args:
Expand All @@ -1149,9 +1175,14 @@ def is_valid_type(input_class_simple, valid_classes):
bool
"""
valid_type = input_class_simple in valid_classes
if not valid_type and issubclass(input_class_simple, OpenApiModel):
if not valid_type and (
issubclass(input_class_simple, OpenApiModel) or
input_class_simple is none_type):
for valid_class in valid_classes:
if not valid_class.discriminator:
if input_class_simple is none_type and is_type_nullable(valid_class):
# Schema is oneOf/anyOf and the 'null' type is one of the allowed types.
return True
if not (issubclass(valid_class, OpenApiModel) and valid_class.discriminator):
continue
discr_propertyname_py = list(valid_class.discriminator.keys())[0]
discriminator_classes = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,21 @@
str,
validate_get_composed_info,
)
try:
from petstore_api.models import nullable_shape
except ImportError:
nullable_shape = sys.modules[
'petstore_api.models.nullable_shape']
try:
from petstore_api.models import shape
except ImportError:
shape = sys.modules[
'petstore_api.models.shape']
try:
from petstore_api.models import shape_or_null
except ImportError:
shape_or_null = sys.modules[
'petstore_api.models.shape_or_null']


class Drawing(ModelNormal):
Expand Down Expand Up @@ -83,6 +93,8 @@ def openapi_types():
"""
return {
'main_shape': (shape.Shape,), # noqa: E501
'shape_or_null': (shape_or_null.ShapeOrNull,), # noqa: E501
'nullable_shape': (nullable_shape.NullableShape, none_type,), # noqa: E501
'shapes': ([shape.Shape],), # noqa: E501
}

Expand All @@ -92,6 +104,8 @@ def discriminator():

attribute_map = {
'main_shape': 'mainShape', # noqa: E501
'shape_or_null': 'shapeOrNull', # noqa: E501
'nullable_shape': 'nullableShape', # noqa: E501
'shapes': 'shapes', # noqa: E501
}

Expand Down Expand Up @@ -140,6 +154,8 @@ def __init__(self, _check_type=True, _from_server=False, _path_to_item=(), _conf
through its discriminator because we passed in
_visited_composed_classes = (Animal,)
main_shape (shape.Shape): [optional] # noqa: E501
shape_or_null (shape_or_null.ShapeOrNull): [optional] # noqa: E501
nullable_shape (nullable_shape.NullableShape, none_type): [optional] # noqa: E501
shapes ([shape.Shape]): [optional] # noqa: E501
"""

Expand Down
Loading