[BUG] [Python-flask] generator creates invalid code for fields that are determined to be "numeric" type
Created by: Johnlon
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Using the python code sample generator config of ....
This bug exists in all python generators I think - i replicated it in python-fastapi because the problem is in the python generators and none seem to handle the necessary transformation that happens in other generators.
generatorName: python-flask
outputDir: samples/server/petstore/python-flask-with-fake-endpoints-models-for-testing-with-http-signature
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/python-flask
Then the OAS fragment ...
format_test:
type: object
....
properties:
......
decimal:
type: string
format: number
Generates python format_test.py looking like this ...
THERE IS AN IMPORT ...
from openapi_server.models.decimal import Decimal
AS WELL AS
self.openapi_types = {
....
'decimal': Decimal,
This is a bug as there is no such local class openapi_server.models.decimal and instead this should be referring to some python native datatype I believe.
In anycase this doesn't work in python as far as I can see.
ModelUtils.java has
public static boolean isDecimalSchema(Schema schema) {
if (SchemaTypeUtil.STRING_TYPE.equals(schema.getType()) // type: string
&& "number".equals(schema.getFormat())) { // format: number
return true;
}
return false;
}
.. which detects the OAS fragment above.
DefaultCodegen.java has ...
else if (ModelUtils.isDecimalSchema(schema)) {
// special handle of type: string, format: number
return "decimal";
I'm not sure what happens next but I assume that do to an explicit type mapping of "decimal" into Python then the code generator assumes this is a local model class and we get bad code.
This seems like a pretty big issue for the python code gen - surely a field like "decimal: type: string format: number" must crop up the whole time in OAS?? How mature is this product?
openapi-generator version
Master as of this bug
OpenAPI declaration file content or url
Use the generator config above.
Generation Details
Use the generator cfg above then to to the outputDir and take a look at test_format.py
Try running the server and it fails.
Steps to reproduce
as above
Suggest a fix
Map this type to a sensible py type