Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python-experimental] JSON schema 'null' type should be modeled as 'none_type' #6121

Merged
merged 61 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
61 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
e16c24e
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset 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
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 @@ -143,6 +143,7 @@ public PythonClientCodegen() {
// map uuid to string for the time being
typeMapping.put("UUID", "str");
typeMapping.put("URI", "str");
typeMapping.put("null", "none_type");

// from https://docs.python.org/3/reference/lexical_analysis.html#keywords
setReservedWordsLowerCase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
composedSchemaSets.add(cm.oneOf);
for (Set<String> importSet : composedSchemaSets) {
for (String otherModelName : importSet) {
cm.imports.add(otherModelName);
if (!languageSpecificPrimitives.contains(otherModelName)) {
spacether marked this conversation as resolved.
Show resolved Hide resolved
cm.imports.add(otherModelName);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,10 @@ def get_oneof_instance(self, model_args, constant_args):
schemas described by oneOf.
Args:
self: the class we are handling
model_args (dict): var_name to var_value
model_args (dict/None): var_name to var_value
sebastien-rosset marked this conversation as resolved.
Show resolved Hide resolved
The input data, e.g. the payload that must match a oneOf schema
in the OpenAPI document.
in the OpenAPI document. If the input data is the null value,
model_args is None.
constant_args (dict): var_name to var_value
args that every model requires, including configuration, server
and path to item.
Expand All @@ -986,6 +987,13 @@ def get_oneof_instance(self, model_args, constant_args):
# Iterate over each oneOf schema and determine if the input data
# matches the oneOf schemas.
for oneof_class in self._composed_schemas()['oneOf']:
if oneof_class is none_type:
sebastien-rosset marked this conversation as resolved.
Show resolved Hide resolved
# The only way the input data can match the 'None' type
# is if the input data is the 'null' value.
if model_args is None:
# The input data matches the 'None' type.
oneof_instances.append(model_args)
sebastien-rosset marked this conversation as resolved.
Show resolved Hide resolved
continue
# transform js keys from input data to python keys in fixed_model_args
fixed_model_args = change_keys_js_to_python(
model_args, oneof_class)
Expand Down Expand Up @@ -1030,10 +1038,13 @@ def get_anyof_instances(self, model_args, constant_args):
"""
Args:
self: the class we are handling
model_args (dict): var_name to var_value
used to make instances
model_args (dict/None): var_name to var_value
The input data, e.g. the payload that must match at least one
anyOf child schema in the OpenAPI document. If the input data
is the null value, model_args is None.
constant_args (dict): var_name to var_value
used to make instances
args that every model requires, including configuration, server
and path to item.

Returns
anyof_instances (list)
Expand All @@ -1043,6 +1054,13 @@ def get_anyof_instances(self, model_args, constant_args):
return anyof_instances

for anyof_class in self._composed_schemas()['anyOf']:
if anyof_class is none_type:
sebastien-rosset marked this conversation as resolved.
Show resolved Hide resolved
# The only way the input data can match the 'None' type
# is if the input data is the 'null' value.
if model_args is None:
spacether marked this conversation as resolved.
Show resolved Hide resolved
# The input data matches the 'None' type.
anyof_instances.append(model_args)
continue
# transform js keys to python keys in fixed_model_args
fixed_model_args = change_keys_js_to_python(model_args, anyof_class)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,7 @@ components:
- $ref: '#/components/schemas/banana'
fruitReq:
oneOf:
- type: 'null'
sebastien-rosset marked this conversation as resolved.
Show resolved Hide resolved
- $ref: '#/components/schemas/appleReq'
- $ref: '#/components/schemas/bananaReq'
appleReq:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,7 @@ components:
type: string
fruitReq:
oneOf:
- type: "null"
spacether marked this conversation as resolved.
Show resolved Hide resolved
- $ref: '#/components/schemas/appleReq'
- $ref: '#/components/schemas/bananaReq'
x-one-of-name: FruitReq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func (s *FruitReq) UnmarshalJSON(src []byte) error {
s.FruitReqInterface = unmarshaledBananaReq
return nil
}
var unmarshaledNull *Null = &Null{}
err = json.Unmarshal(src, unmarshaledNull)
if err == nil {
s.FruitReqInterface = unmarshaledNull
return nil
}
return fmt.Errorf("No oneOf model could be deserialized from payload: %s", string(src))
}
type NullableFruitReq struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1231,9 +1231,10 @@ def get_oneof_instance(self, model_args, constant_args):
schemas described by oneOf.
Args:
self: the class we are handling
model_args (dict): var_name to var_value
model_args (dict/None): var_name to var_value
The input data, e.g. the payload that must match a oneOf schema
in the OpenAPI document.
in the OpenAPI document. If the input data is the null value,
model_args is None.
constant_args (dict): var_name to var_value
args that every model requires, including configuration, server
and path to item.
Expand All @@ -1248,6 +1249,13 @@ def get_oneof_instance(self, model_args, constant_args):
# Iterate over each oneOf schema and determine if the input data
# matches the oneOf schemas.
for oneof_class in self._composed_schemas()['oneOf']:
if oneof_class is none_type:
# The only way the input data can match the 'None' type
# is if the input data is the 'null' value.
if model_args is None:
# The input data matches the 'None' type.
oneof_instances.append(model_args)
continue
# transform js keys from input data to python keys in fixed_model_args
fixed_model_args = change_keys_js_to_python(
model_args, oneof_class)
Expand Down Expand Up @@ -1292,10 +1300,13 @@ def get_anyof_instances(self, model_args, constant_args):
"""
Args:
self: the class we are handling
model_args (dict): var_name to var_value
used to make instances
model_args (dict/None): var_name to var_value
The input data, e.g. the payload that must match at least one
anyOf child schema in the OpenAPI document. If the input data
is the null value, model_args is None.
constant_args (dict): var_name to var_value
used to make instances
args that every model requires, including configuration, server
and path to item.

Returns
anyof_instances (list)
Expand All @@ -1305,6 +1316,13 @@ def get_anyof_instances(self, model_args, constant_args):
return anyof_instances

for anyof_class in self._composed_schemas()['anyOf']:
if anyof_class is none_type:
# The only way the input data can match the 'None' type
# is if the input data is the 'null' value.
if model_args is None:
# The input data matches the 'None' type.
anyof_instances.append(model_args)
continue
# transform js keys to python keys in fixed_model_args
fixed_model_args = change_keys_js_to_python(model_args, anyof_class)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,6 @@ def _composed_schemas():
'oneOf': [
apple_req.AppleReq,
banana_req.BananaReq,
none_type,
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def testFruitReq(self):
'oneOf': [
petstore_api.AppleReq,
petstore_api.BananaReq,
type(None),
],
}
)
Expand Down