Skip to content

Commit e1c8014

Browse files
committed
set legacy config option in Python sample configs
1 parent 6afb316 commit e1c8014

6 files changed

Lines changed: 15 additions & 0 deletions

File tree

bin/configs/python-aiohttp.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ additionalProperties:
88
mapNumberTo: float
99
poetry1: true
1010
disallowAdditionalPropertiesIfNotPresent: true
11+
legacyDefaultDisallowAdditionalPropertiesIfNotPresentBehavior: true
1112
nameMappings:
1213
_type: underscore_type
1314
type_: type_with_underscore

bin/configs/python-echo-api.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ templateDir: modules/openapi-generator/src/main/resources/python
55
additionalProperties:
66
hideGenerationTimestamp: "true"
77
disallowAdditionalPropertiesIfNotPresent: true
8+
legacyDefaultDisallowAdditionalPropertiesIfNotPresentBehavior: true

bin/configs/python-fastapi.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ sourceFolder: "src"
66
additionalProperties:
77
hideGenerationTimestamp: "true"
88
disallowAdditionalPropertiesIfNotPresent: true
9+
legacyDefaultDisallowAdditionalPropertiesIfNotPresentBehavior: true

bin/configs/python-pydantic-v1-aiohttp.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ additionalProperties:
77
packageName: petstore_api
88
mapNumberTo: float
99
disallowAdditionalPropertiesIfNotPresent: true
10+
legacyDefaultDisallowAdditionalPropertiesIfNotPresentBehavior: true

bin/configs/python-pydantic-v1-echo-api.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ templateDir: modules/openapi-generator/src/main/resources/python-pydantic-v1
55
additionalProperties:
66
hideGenerationTimestamp: "true"
77
disallowAdditionalPropertiesIfNotPresent: true
8+
legacyDefaultDisallowAdditionalPropertiesIfNotPresentBehavior: true

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public abstract class AbstractPythonPydanticV1Codegen extends DefaultCodegen imp
4949
protected String packageName = "openapi_client";
5050
@Setter protected String packageVersion = "1.0.0";
5151
@Setter protected String projectName; // for setup.py, e.g. petstore-api
52+
@Setter
53+
protected boolean legacyDisallowAdditionalPropertiesDefaultBehavior = false;
5254
protected boolean hasModelsToImport = Boolean.FALSE;
5355
protected String mapNumberTo = "Union[StrictFloat, StrictInt]";
5456
protected Map<Character, String> regexModifiers;
@@ -138,6 +140,10 @@ public AbstractPythonPydanticV1Codegen() {
138140
public void processOpts() {
139141
super.processOpts();
140142

143+
if (additionalProperties.containsKey(CodegenConstants.LEGACY_DEFAULT_DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT_BEHAVIOR)) {
144+
setLegacyDisallowAdditionalPropertiesDefaultBehavior(Boolean.parseBoolean(additionalProperties.get(CodegenConstants.LEGACY_DEFAULT_DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT_BEHAVIOR).toString()));
145+
}
146+
141147
if (StringUtils.isEmpty(System.getenv("PYTHON_POST_PROCESS_FILE"))) {
142148
LOGGER.info("Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE=\"/usr/local/bin/yapf -i\"' (Linux/Mac)");
143149
LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).");
@@ -983,6 +989,10 @@ private ModelsMap postProcessModelsMap(ModelsMap objs) {
983989
model.getVendorExtensions().putIfAbsent("x-py-datetime-imports", datetimeImports);
984990
model.getVendorExtensions().putIfAbsent("x-py-readonly", readOnlyFields);
985991

992+
if (legacyDisallowAdditionalPropertiesDefaultBehavior) {
993+
model.vendorExtensions.putIfAbsent("x-py-legacy-disallow-additional-properties-default-behavior", true);
994+
}
995+
986996
// remove the items of postponedModelImports in modelImports to avoid circular imports error
987997
if (!modelImports.isEmpty() && !postponedModelImports.isEmpty()) {
988998
modelImports.removeAll(postponedModelImports);

0 commit comments

Comments
 (0)