Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -566,9 +566,14 @@ public void postProcessParameter(CodegenParameter p) {
}
}

private void addNullDefaultToOneOfAnyOfReqProps(Schema schema, CodegenModel result) {
private void fixComposedSchemaRequiredVars(Schema schema, CodegenModel result) {
// for composed schema models, if the required properties are only from oneOf or anyOf models
// give them a nulltype.Null so the user can omit including them in python
// remove them from the composed schema's required vars
// for composed schemas our code adds oneOf and anyOf required properties to
// the composed schema's required properties
// but they should not be required because if we have ComposedSchema: oneOf -schemaA -schemaB
// and the required props are only in schemaB, we do not need to use them when making an instance of
// ComposedSchema + schemaA
ComposedSchema cs = (ComposedSchema) schema;

// these are the properties that are from properties in self cs or cs allOf
Expand Down Expand Up @@ -596,7 +601,7 @@ private void addNullDefaultToOneOfAnyOfReqProps(Schema schema, CodegenModel resu

List<Schema> allOf = cs.getAllOf();
if ((schema.getProperties() != null && !schema.getProperties().isEmpty()) || allOf != null) {
// NOTE: this function also adds the allOf propesrties inside schema
// NOTE: this function also adds the allOf properties inside schema
addProperties(selfProperties, selfRequired, schema);
}
if (result.discriminator != null) {
Expand All @@ -605,16 +610,20 @@ private void addNullDefaultToOneOfAnyOfReqProps(Schema schema, CodegenModel resu
Set<String> selfRequiredSet = new HashSet<String>(selfRequired);

List<CodegenProperty> reqVars = result.getRequiredVars();
List<CodegenProperty> reqVarsThatMustBeOptional = new ArrayList<>();
if (reqVars != null) {
for (CodegenProperty cp : reqVars) {
String propName = cp.baseName;
if (otherRequiredSet.contains(propName) && !selfRequiredSet.contains(propName)) {
// if var is in otherRequiredSet and is not in selfRequiredSet and is in result.requiredVars
// then set it to nullable because the user doesn't have to give a value for it
cp.setDefaultValue("nulltype.Null");
cp.required = false;
reqVarsThatMustBeOptional.add(cp);
}
}
}
for (CodegenProperty cp : reqVarsThatMustBeOptional) {
result.getRequiredVars().remove(cp);
result.getOptionalVars().add(cp);
}
}

/**
Expand Down Expand Up @@ -643,7 +652,7 @@ protected void addParentContainer(CodegenModel model, String name, Schema schema
public CodegenModel fromModel(String name, Schema sc) {
CodegenModel cm = super.fromModel(name, sc);
if (cm.requiredVars.size() > 0 && (cm.oneOf.size() > 0 || cm.anyOf.size() > 0)) {
addNullDefaultToOneOfAnyOfReqProps(sc, cm);
fixComposedSchemaRequiredVars(sc, cm);
}
ArrayList<List<CodegenProperty>> listOfLists = new ArrayList<List<CodegenProperty>>();
listOfLists.add(cm.requiredVars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from {{packageName}}.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
'{{name}}': {{name}},
{{/requiredVars}}
}
# remove args whose value is Null because they are unset
required_arg_names = list(required_args.keys())
for required_arg_name in required_arg_names:
if required_args[required_arg_name] is nulltype.Null:
del required_args[required_arg_name]
model_args = {}
model_args.update(required_args)
model_args.update(kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
nulltype
python_dateutil >= 2.5.3
setuptools >= 21.0.0
urllib3 >= 1.25.3
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ VERSION = "{{packageVersion}}"
REQUIRES = [
"urllib3 >= 1.25.3",
"python-dateutil",
"nulltype",
{{#asyncio}}
"aiohttp >= 3.0.0",
{{/asyncio}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
2 changes: 0 additions & 2 deletions samples/client/petstore/python/petstore_api/model/animal.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
7 changes: 0 additions & 7 deletions samples/client/petstore/python/petstore_api/model/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down Expand Up @@ -187,11 +185,6 @@ def __init__(self, class_name, *args, **kwargs): # noqa: E501
required_args = {
'class_name': class_name,
}
# remove args whose value is Null because they are unset
required_arg_names = list(required_args.keys())
for required_arg_name in required_arg_names:
if required_args[required_arg_name] is nulltype.Null:
del required_args[required_arg_name]
model_args = {}
model_args.update(required_args)
model_args.update(kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
2 changes: 0 additions & 2 deletions samples/client/petstore/python/petstore_api/model/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
7 changes: 0 additions & 7 deletions samples/client/petstore/python/petstore_api/model/child.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down Expand Up @@ -181,11 +179,6 @@ def __init__(self, *args, **kwargs): # noqa: E501
}
required_args = {
}
# remove args whose value is Null because they are unset
required_arg_names = list(required_args.keys())
for required_arg_name in required_arg_names:
if required_args[required_arg_name] is nulltype.Null:
del required_args[required_arg_name]
model_args = {}
model_args.update(required_args)
model_args.update(kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down Expand Up @@ -184,11 +182,6 @@ def __init__(self, pet_type, *args, **kwargs): # noqa: E501
required_args = {
'pet_type': pet_type,
}
# remove args whose value is Null because they are unset
required_arg_names = list(required_args.keys())
for required_arg_name in required_arg_names:
if required_args[required_arg_name] is nulltype.Null:
del required_args[required_arg_name]
model_args = {}
model_args.update(required_args)
model_args.update(kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down Expand Up @@ -184,11 +182,6 @@ def __init__(self, pet_type, *args, **kwargs): # noqa: E501
required_args = {
'pet_type': pet_type,
}
# remove args whose value is Null because they are unset
required_arg_names = list(required_args.keys())
for required_arg_name in required_arg_names:
if required_args[required_arg_name] is nulltype.Null:
del required_args[required_arg_name]
model_args = {}
model_args.update(required_args)
model_args.update(kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down Expand Up @@ -184,11 +182,6 @@ def __init__(self, pet_type, *args, **kwargs): # noqa: E501
required_args = {
'pet_type': pet_type,
}
# remove args whose value is Null because they are unset
required_arg_names = list(required_args.keys())
for required_arg_name in required_arg_names:
if required_args[required_arg_name] is nulltype.Null:
del required_args[required_arg_name]
model_args = {}
model_args.update(required_args)
model_args.update(kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re # noqa: F401
import sys # noqa: F401

import nulltype # noqa: F401

from petstore_api.model_utils import ( # noqa: F401
ApiTypeError,
ModelComposed,
Expand Down
Loading