Skip to content

Commit

Permalink
Fix python-fastapi to update number parameter to float rather than st…
Browse files Browse the repository at this point in the history
…rictfloat
  • Loading branch information
Louis Sullivan authored and Louis Sullivan committed Dec 13, 2024
1 parent b218e23 commit 5d62b14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -5265,12 +5274,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit 5d62b14

Please sign in to comment.