From 5d62b140228dd92b2e8fc8ab6c92e99c9211a8ce Mon Sep 17 00:00:00 2001 From: Louis Sullivan Date: Fri, 13 Dec 2024 11:49:19 +0000 Subject: [PATCH] Fix python-fastapi to update number parameter to float rather than strictfloat --- .../org/openapitools/codegen/DefaultCodegen.java | 16 ++++++++++------ .../languages/PythonFastAPIServerCodegen.java | 10 ++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index d8b577c93cae..245be08dc5a3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -5135,6 +5135,15 @@ protected void updateParameterForString(CodegenParameter codegenParameter, Schem } } + protected void updateParameterForNumber(CodegenParameter codegenParameter, Schema parameterSchema) { + codegenParameter.isPrimitiveType = true; + if (ModelUtils.isFloatSchema(parameterSchema)) { // float + codegenParameter.isFloat = true; + } else if (ModelUtils.isDoubleSchema(parameterSchema)) { // double + codegenParameter.isDouble = true; + } + } + /** * Convert OAS Parameter object to Codegen Parameter object * @@ -5265,12 +5274,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set imports) } else if (ModelUtils.isBooleanSchema(parameterSchema)) { codegenParameter.isPrimitiveType = true; } else if (ModelUtils.isNumberSchema(parameterSchema)) { - codegenParameter.isPrimitiveType = true; - if (ModelUtils.isFloatSchema(parameterSchema)) { // float - codegenParameter.isFloat = true; - } else if (ModelUtils.isDoubleSchema(parameterSchema)) { // double - codegenParameter.isDouble = true; - } + updateParameterForNumber(codegenParameter, parameterSchema); } else if (ModelUtils.isIntegerSchema(parameterSchema)) { // integer type codegenParameter.isPrimitiveType = true; if (ModelUtils.isLongSchema(parameterSchema)) { // int64/long format diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFastAPIServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFastAPIServerCodegen.java index 0ea2e9690aac..0004f33c5d6b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFastAPIServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFastAPIServerCodegen.java @@ -334,4 +334,14 @@ public String escapeReservedWord(String name) { } return "var_" + name; } + + @Override + protected void updateParameterForNumber(CodegenParameter codegenParameter, Schema parameterSchema) { + mapNumberTo = "float"; + if (ModelUtils.isNumberSchema(parameterSchema) || (ModelUtils.isFloatSchema(parameterSchema))) { // Number or float is a float + codegenParameter.isFloat = true; + } else if (ModelUtils.isDoubleSchema(parameterSchema)) { // double + codegenParameter.isDouble = true; + } + } }