You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a fastapi defined interface with a enum (TaskStatus) and a structure (Task) containing an instance of that enum with a default.
I extract the openapi.json from the running fastapi using wget.
Then I generate the Java client code using swagger codegen.
The enum is generated just fine, but the default value in the object is missing the Enum type. I'm wondering if I'm missing something I need to add to the fastapi main.py or the generated openapi.json.
main.py:
fromtypingimportUnionfromenumimportEnumfrompydanticimportBaseModelfromfastapiimportFastAPIapp=FastAPI()
classTaskStatus(str,Enum):
NIL="NIL"NOT_APPROVED="NOT_APPROVED"NOT_READY="NOT_READY"NOT_ASSIGNED="NOT_ASSIGNED"PENDING="PENDING"EXECUTING="EXECUTING"DONE="DONE"classTask(BaseModel):
'''Base class for tasks'''task_id: int=-1'''ID of the task'''status: TaskStatus=TaskStatus.NOT_ASSIGNED'''Status of task to be tracked throughout runtime'''@app.get("/")defread_root():
return {"Hello": "World"}
@app.get("/task/{task_id}")defread_task(task_id: int ) ->Task:
task=Task( id=task_id )
returntask
Description
I have a fastapi defined interface with a enum (TaskStatus) and a structure (Task) containing an instance of that enum with a default.
I extract the openapi.json from the running fastapi using wget.
Then I generate the Java client code using swagger codegen.
The enum is generated just fine, but the default value in the object is missing the Enum type. I'm wondering if I'm missing something I need to add to the fastapi main.py or the generated openapi.json.
main.py:
generated java enum:
INVALID generated java Task class - enum default value should be TaskStatus.NOT_ASSIGNED:
Swagger-codegen version
swagger-codegen-cli-3.0.61.jar
Swagger declaration file content or url
Full openapi.json
snip:
Command line used for generation
wget http://127.0.0.1:8000/openapi.json
java -jar swagger-codegen-cli-3.0.61.jar generate -l java -i openapi.json -Dlibrary=jersey1,hideGenerationTimestamp=true -o java-jersey1
Steps to reproduce
regenerate the code with the linked openapi.json
Maybe I'm missing something somewhere?
The text was updated successfully, but these errors were encountered: