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
1 change: 1 addition & 0 deletions docs/generators/python-experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|packageVersion|python package version.| |1.0.0|
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
|useInlineModelResolver|use the inline model resolver, if true inline complex models will be extracted into components and $refs to them will be used| |false|
|useNose|use the nose test framework| |false|

## IMPORT MAPPING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,6 @@ public interface CodegenConfig {
String generatorLanguageVersion();

List<VendorExtension> getSupportedVendorExtensions();

boolean getUseInlineModelResolver();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4713,12 +4713,12 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
String parameterDataType = this.getParameterDataType(parameter, parameterSchema);
if (parameterDataType != null) {
codegenParameter.dataType = parameterDataType;
if (ModelUtils.isObjectSchema(parameterSchema)) {
codegenProperty.complexType = codegenParameter.dataType;
}
Comment thread
spacether marked this conversation as resolved.
} else {
codegenParameter.dataType = codegenProperty.dataType;
}
if (ModelUtils.isObjectSchema(parameterSchema)) {
codegenProperty.complexType = codegenParameter.dataType;
}
if (ModelUtils.isSet(parameterSchema)) {
imports.add(codegenProperty.baseType);
}
Expand Down Expand Up @@ -7429,4 +7429,7 @@ public String generatorLanguageVersion() {
public List<VendorExtension> getSupportedVendorExtensions() {
return new ArrayList<>();
}

@Override
public boolean getUseInlineModelResolver() { return true; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,10 @@ public List<File> generate() {
}

// resolve inline models
InlineModelResolver inlineModelResolver = new InlineModelResolver();
inlineModelResolver.flatten(openAPI);
if (config.getUseInlineModelResolver()) {
InlineModelResolver inlineModelResolver = new InlineModelResolver();
inlineModelResolver.flatten(openAPI);
}

configureGeneratorProperties();
configureOpenAPIInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
// nose is a python testing framework, we use pytest if USE_NOSE is unset
public static final String USE_NOSE = "useNose";
public static final String RECURSION_LIMIT = "recursionLimit";
public static final String USE_INLINE_MODEL_RESOLVER = "useInlineModelResolver";

protected String packageUrl;
protected String apiDocPath = "docs/";
protected String modelDocPath = "docs/";
protected boolean useNose = Boolean.FALSE;
protected boolean useNose = false;
protected boolean useInlineModelResolver = false;

protected Map<Character, String> regexModifiers;

Expand Down Expand Up @@ -192,6 +194,8 @@ public PythonExperimentalClientCodegen() {
cliOptions.add(CliOption.newBoolean(USE_NOSE, "use the nose test framework").
defaultValue(Boolean.FALSE.toString()));
cliOptions.add(new CliOption(RECURSION_LIMIT, "Set the recursion limit. If not set, use the system default value."));
cliOptions.add(CliOption.newBoolean(USE_INLINE_MODEL_RESOLVER, "use the inline model resolver, if true inline complex models will be extracted into components and $refs to them will be used").
defaultValue(Boolean.FALSE.toString()));

supportedLibraries.put("urllib3", "urllib3-based client");
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use: urllib3");
Expand Down Expand Up @@ -260,7 +264,7 @@ public void processOpts() {
}

modelTemplateFiles.put("model." + templateExtension, ".py");
apiTemplateFiles.put("api." + templateExtension, ".py");
apiTemplateFiles.put("api." + templateExtension, ".py");
modelTestTemplateFiles.put("model_test." + templateExtension, ".py");
apiTestTemplateFiles.put("api_test." + templateExtension, ".py");
modelDocTemplateFiles.put("model_doc." + templateExtension, ".md");
Expand Down Expand Up @@ -321,6 +325,10 @@ public void processOpts() {
setUseNose((String) additionalProperties.get(USE_NOSE));
}

if (additionalProperties.containsKey(USE_INLINE_MODEL_RESOLVER)) {
setUseInlineModelResolver((String) additionalProperties.get(USE_INLINE_MODEL_RESOLVER));
}

// check to see if setRecursionLimit is set and whether it's an integer
if (additionalProperties.containsKey(RECURSION_LIMIT)) {
try {
Expand Down Expand Up @@ -1254,20 +1262,31 @@ private String getTypeString(Schema p, String prefix, String suffix, List<String
return prefix + modelName + fullSuffix;
}
}
if (isAnyTypeSchema(p)) {
if (ModelUtils.isAnyType(p)) {
return prefix + "bool, date, datetime, dict, float, int, list, str, none_type" + suffix;
}
// Resolve $ref because ModelUtils.isXYZ methods do not automatically resolve references.
if (ModelUtils.isNullable(ModelUtils.getReferencedSchema(this.openAPI, p))) {
fullSuffix = ", none_type" + suffix;
}
if (isFreeFormObject(p) && getAdditionalProperties(p) == null) {
return prefix + "bool, date, datetime, dict, float, int, list, str" + fullSuffix;
} else if (ModelUtils.isNumberSchema(p)) {
if (ModelUtils.isNumberSchema(p)) {
return prefix + "int, float" + fullSuffix;
} else if ((ModelUtils.isMapSchema(p) || "object".equals(p.getType())) && getAdditionalProperties(p) != null) {
Schema inner = getAdditionalProperties(p);
return prefix + "{str: " + getTypeString(inner, "(", ")", referencedModelNames) + "}" + fullSuffix;
} else if (ModelUtils.isTypeObjectSchema(p)) {
if (p.getAdditionalProperties() != null && p.getAdditionalProperties().equals(false)) {
if (p.getProperties() == null) {
// type object with no properties and additionalProperties = false, empty dict only
return prefix + "{str: typing.Any}" + fullSuffix;
} else {
// properties only
// TODO add type hints for those properties only as values
return prefix + "{str: typing.Any}" + fullSuffix;
}
} else {
// additionalProperties exists
Schema inner = getAdditionalProperties(p);
return prefix + "{str: " + getTypeString(inner, "(", ")", referencedModelNames) + "}" + fullSuffix;
// TODO add code here to add property values too if they exist
}
} else if (ModelUtils.isArraySchema(p)) {
ArraySchema ap = (ArraySchema) p;
Schema inner = ap.getItems();
Expand All @@ -1284,8 +1303,7 @@ private String getTypeString(Schema p, String prefix, String suffix, List<String
} else {
return prefix + getTypeString(inner, "[", "]", referencedModelNames) + fullSuffix;
}
}
if (ModelUtils.isFileSchema(p)) {
} else if (ModelUtils.isFileSchema(p)) {
return prefix + "file_type" + fullSuffix;
}
String baseType = getSchemaType(p);
Expand All @@ -1302,7 +1320,7 @@ private String getTypeString(Schema p, String prefix, String suffix, List<String
public String getTypeDeclaration(Schema p) {
// this is used to set dataType, which defines a python tuple of classes
// in Python we will wrap this in () to make it a tuple but here we
// will omit the parens so the generated documentaion will not include
// will omit the parens so the generated documentation will not include
// them
return getTypeString(p, "", "", null);
}
Expand Down Expand Up @@ -2237,6 +2255,13 @@ public void setUseNose(String val) {
this.useNose = Boolean.parseBoolean(val);
}

@Override
public boolean getUseInlineModelResolver() { return useInlineModelResolver; }

public void setUseInlineModelResolver(String val) {
this.useInlineModelResolver = Boolean.parseBoolean(val);
}

public void setPackageUrl(String packageUrl) {
this.packageUrl = packageUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import re # noqa: F401
import sys # noqa: F401
import typing
import urllib3
import functools # noqa: F401
{{#with operation}}
{{#or headerParams bodyParam produces}}
from urllib3._collections import HTTPHeaderDict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re # noqa: F401
import sys # noqa: F401
import typing # noqa: F401
import functools # noqa: F401

from frozendict import frozendict # noqa: F401

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@classmethod
@property
@functools.cache
def _composed_schemas(cls):
# we need this here to make our import statements work
# we must store _composed_schemas in here so the code is only run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ docs/Boolean.md
docs/BooleanEnum.md
docs/Capitalization.md
docs/Cat.md
docs/CatAllOf.md
docs/Category.md
docs/ChildCat.md
docs/ChildCatAllOf.md
docs/ClassModel.md
docs/Client.md
docs/ComplexQuadrilateral.md
docs/ComplexQuadrilateralAllOf.md
docs/ComposedAnyOfDifferentTypesNoValidations.md
docs/ComposedArray.md
docs/ComposedBool.md
Expand All @@ -42,7 +39,6 @@ docs/ComposedNumber.md
docs/ComposedObject.md
docs/ComposedOneOfDifferentTypes.md
docs/ComposedString.md
docs/CompositionInProperty.md
docs/Currency.md
docs/DanishPig.md
docs/DateTimeTest.md
Expand All @@ -51,13 +47,11 @@ docs/DateWithValidations.md
docs/DecimalPayload.md
docs/DefaultApi.md
docs/Dog.md
docs/DogAllOf.md
docs/Drawing.md
docs/EnumArrays.md
docs/EnumClass.md
docs/EnumTest.md
docs/EquilateralTriangle.md
docs/EquilateralTriangleAllOf.md
docs/FakeApi.md
docs/FakeClassnameTags123Api.md
docs/File.md
Expand All @@ -70,17 +64,14 @@ docs/GmFruit.md
docs/GrandparentAnimal.md
docs/HasOnlyReadOnly.md
docs/HealthCheckResult.md
docs/InlineResponseDefault.md
docs/IntegerEnum.md
docs/IntegerEnumBig.md
docs/IntegerEnumOneValue.md
docs/IntegerEnumWithDefaultValue.md
docs/IntegerMax10.md
docs/IntegerMin15.md
docs/IsoscelesTriangle.md
docs/IsoscelesTriangleAllOf.md
docs/Mammal.md
docs/MapBean.md
docs/MapTest.md
docs/MixedPropertiesAndAdditionalPropertiesClass.md
docs/Model200Response.md
Expand Down Expand Up @@ -110,11 +101,9 @@ docs/Quadrilateral.md
docs/QuadrilateralInterface.md
docs/ReadOnlyFirst.md
docs/ScaleneTriangle.md
docs/ScaleneTriangleAllOf.md
docs/Shape.md
docs/ShapeOrNull.md
docs/SimpleQuadrilateral.md
docs/SimpleQuadrilateralAllOf.md
docs/SomeObject.md
docs/SpecialModelName.md
docs/StoreApi.md
Expand Down Expand Up @@ -169,14 +158,11 @@ petstore_api/model/boolean.py
petstore_api/model/boolean_enum.py
petstore_api/model/capitalization.py
petstore_api/model/cat.py
petstore_api/model/cat_all_of.py
petstore_api/model/category.py
petstore_api/model/child_cat.py
petstore_api/model/child_cat_all_of.py
petstore_api/model/class_model.py
petstore_api/model/client.py
petstore_api/model/complex_quadrilateral.py
petstore_api/model/complex_quadrilateral_all_of.py
petstore_api/model/composed_any_of_different_types_no_validations.py
petstore_api/model/composed_array.py
petstore_api/model/composed_bool.py
Expand All @@ -185,21 +171,18 @@ petstore_api/model/composed_number.py
petstore_api/model/composed_object.py
petstore_api/model/composed_one_of_different_types.py
petstore_api/model/composed_string.py
petstore_api/model/composition_in_property.py
petstore_api/model/currency.py
petstore_api/model/danish_pig.py
petstore_api/model/date_time_test.py
petstore_api/model/date_time_with_validations.py
petstore_api/model/date_with_validations.py
petstore_api/model/decimal_payload.py
petstore_api/model/dog.py
petstore_api/model/dog_all_of.py
petstore_api/model/drawing.py
petstore_api/model/enum_arrays.py
petstore_api/model/enum_class.py
petstore_api/model/enum_test.py
petstore_api/model/equilateral_triangle.py
petstore_api/model/equilateral_triangle_all_of.py
petstore_api/model/file.py
petstore_api/model/file_schema_test_class.py
petstore_api/model/foo.py
Expand All @@ -210,17 +193,14 @@ petstore_api/model/gm_fruit.py
petstore_api/model/grandparent_animal.py
petstore_api/model/has_only_read_only.py
petstore_api/model/health_check_result.py
petstore_api/model/inline_response_default.py
petstore_api/model/integer_enum.py
petstore_api/model/integer_enum_big.py
petstore_api/model/integer_enum_one_value.py
petstore_api/model/integer_enum_with_default_value.py
petstore_api/model/integer_max10.py
petstore_api/model/integer_min15.py
petstore_api/model/isosceles_triangle.py
petstore_api/model/isosceles_triangle_all_of.py
petstore_api/model/mammal.py
petstore_api/model/map_bean.py
petstore_api/model/map_test.py
petstore_api/model/mixed_properties_and_additional_properties_class.py
petstore_api/model/model200_response.py
Expand Down Expand Up @@ -249,11 +229,9 @@ petstore_api/model/quadrilateral.py
petstore_api/model/quadrilateral_interface.py
petstore_api/model/read_only_first.py
petstore_api/model/scalene_triangle.py
petstore_api/model/scalene_triangle_all_of.py
petstore_api/model/shape.py
petstore_api/model/shape_or_null.py
petstore_api/model/simple_quadrilateral.py
petstore_api/model/simple_quadrilateral_all_of.py
petstore_api/model/some_object.py
petstore_api/model/special_model_name.py
petstore_api/model/string.py
Expand Down
11 changes: 0 additions & 11 deletions samples/openapi3/client/petstore/python-experimental/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,11 @@ Class | Method | HTTP request | Description
- [BooleanEnum](docs/BooleanEnum.md)
- [Capitalization](docs/Capitalization.md)
- [Cat](docs/Cat.md)
- [CatAllOf](docs/CatAllOf.md)
- [Category](docs/Category.md)
- [ChildCat](docs/ChildCat.md)
- [ChildCatAllOf](docs/ChildCatAllOf.md)
- [ClassModel](docs/ClassModel.md)
- [Client](docs/Client.md)
- [ComplexQuadrilateral](docs/ComplexQuadrilateral.md)
- [ComplexQuadrilateralAllOf](docs/ComplexQuadrilateralAllOf.md)
- [ComposedAnyOfDifferentTypesNoValidations](docs/ComposedAnyOfDifferentTypesNoValidations.md)
- [ComposedArray](docs/ComposedArray.md)
- [ComposedBool](docs/ComposedBool.md)
Expand All @@ -178,21 +175,18 @@ Class | Method | HTTP request | Description
- [ComposedObject](docs/ComposedObject.md)
- [ComposedOneOfDifferentTypes](docs/ComposedOneOfDifferentTypes.md)
- [ComposedString](docs/ComposedString.md)
- [CompositionInProperty](docs/CompositionInProperty.md)
- [Currency](docs/Currency.md)
- [DanishPig](docs/DanishPig.md)
- [DateTimeTest](docs/DateTimeTest.md)
- [DateTimeWithValidations](docs/DateTimeWithValidations.md)
- [DateWithValidations](docs/DateWithValidations.md)
- [DecimalPayload](docs/DecimalPayload.md)
- [Dog](docs/Dog.md)
- [DogAllOf](docs/DogAllOf.md)
- [Drawing](docs/Drawing.md)
- [EnumArrays](docs/EnumArrays.md)
- [EnumClass](docs/EnumClass.md)
- [EnumTest](docs/EnumTest.md)
- [EquilateralTriangle](docs/EquilateralTriangle.md)
- [EquilateralTriangleAllOf](docs/EquilateralTriangleAllOf.md)
- [File](docs/File.md)
- [FileSchemaTestClass](docs/FileSchemaTestClass.md)
- [Foo](docs/Foo.md)
Expand All @@ -203,17 +197,14 @@ Class | Method | HTTP request | Description
- [GrandparentAnimal](docs/GrandparentAnimal.md)
- [HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
- [HealthCheckResult](docs/HealthCheckResult.md)
- [InlineResponseDefault](docs/InlineResponseDefault.md)
- [IntegerEnum](docs/IntegerEnum.md)
- [IntegerEnumBig](docs/IntegerEnumBig.md)
- [IntegerEnumOneValue](docs/IntegerEnumOneValue.md)
- [IntegerEnumWithDefaultValue](docs/IntegerEnumWithDefaultValue.md)
- [IntegerMax10](docs/IntegerMax10.md)
- [IntegerMin15](docs/IntegerMin15.md)
- [IsoscelesTriangle](docs/IsoscelesTriangle.md)
- [IsoscelesTriangleAllOf](docs/IsoscelesTriangleAllOf.md)
- [Mammal](docs/Mammal.md)
- [MapBean](docs/MapBean.md)
- [MapTest](docs/MapTest.md)
- [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
- [Model200Response](docs/Model200Response.md)
Expand Down Expand Up @@ -242,11 +233,9 @@ Class | Method | HTTP request | Description
- [QuadrilateralInterface](docs/QuadrilateralInterface.md)
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [ScaleneTriangle](docs/ScaleneTriangle.md)
- [ScaleneTriangleAllOf](docs/ScaleneTriangleAllOf.md)
- [Shape](docs/Shape.md)
- [ShapeOrNull](docs/ShapeOrNull.md)
- [SimpleQuadrilateral](docs/SimpleQuadrilateral.md)
- [SimpleQuadrilateralAllOf](docs/SimpleQuadrilateralAllOf.md)
- [SomeObject](docs/SomeObject.md)
- [SpecialModelName](docs/SpecialModelName.md)
- [String](docs/String.md)
Expand Down
Loading