[JAVA] Enum field with default generated incorrectly
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Inizia con l'openapi.json collegato e riproduci il problema usando il comando di generazione Java di swagger-codegen-cli mostrato. Traccia il modo in cui il valore predefinito dello stato del modello Task viene rappresentato nella classe Java generata, quindi verifica che il codice generato utilizzi la costante dell'enum TaskStatus e venga compilato correttamente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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:
from typing import Union
from enum import Enum
from pydantic import BaseModel
from fastapi import FastAPI
app = FastAPI()
class TaskStatus(str,Enum):
NIL = "NIL"
NOT_APPROVED = "NOT_APPROVED"
NOT_READY = "NOT_READY"
NOT_ASSIGNED = "NOT_ASSIGNED"
PENDING = "PENDING"
EXECUTING = "EXECUTING"
DONE = "DONE"
class Task(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("/")
def read_root():
return {"Hello": "World"}
@app.get("/task/{task_id}")
def read_task(task_id: int ) -> Task:
task = Task( id = task_id )
return task
generated java enum:
public enum TaskStatus {
NIL("NIL"),
NOT_APPROVED("NOT_APPROVED"),
NOT_READY("NOT_READY"),
NOT_ASSIGNED("NOT_ASSIGNED"),
PENDING("PENDING"),
EXECUTING("EXECUTING"),
DONE("DONE");
INVALID generated java Task class - enum default value should be TaskStatus.NOT_ASSIGNED:
public class Task {
@JsonProperty("task_id")
private Object taskId = -1;
@JsonProperty("status")
private TaskStatus status = NOT_ASSIGNED;
Swagger-codegen version
swagger-codegen-cli-3.0.61.jar
Swagger declaration file content or url
snip:
{
....
"/task/{task_id}": {
"get": {
"summary": "Read Task",
"operationId": "read_task_task__task_id__get",
"parameters": [{
"name": "task_id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"title": "Task Id"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Task"
}
...
},
"components": {
"schemas": {
...
"Task": {
"properties": {
"task_id": {
"type": "integer",
"title": "Task Id",
"default": -1
},
"status": {
"$ref": "#/components/schemas/TaskStatus",
"default": "NOT_ASSIGNED"
}
},
"type": "object",
"title": "Task",
"description": "Base class for tasks"
},
"TaskStatus": {
"type": "string",
"enum": ["NIL", "NOT_APPROVED", "NOT_READY", "NOT_ASSIGNED", "PENDING", "EXECUTING", "DONE"],
"title": "TaskStatus"
},
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?
- Lingua principale
- Mustache
- Stelle
- 17.8k
- Fork
- 6k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di swagger-api/swagger-codegen
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
swagger-api/swagger-codegen#12755 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
swagger-api/swagger-codegen#12445 ·
-
security vulnerability
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
swagger-api/swagger-codegen#11942 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
swagger-api/swagger-codegen#11812 · 1 reazione ·
-
security vulnerability
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
swagger-api/swagger-codegen#11594 ·
Tutte le issue di swagger-api/swagger-codegen
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
external-issue to-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
googleapis/google-cloud-swift#1151 ·
-
SqliteSaver.list(filter=...) silently misses nested metadata values containing non-ASCII text Apertaexternal
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
langchain-ai/langgraph#9074 · 1 commento ·
-
documentation specification
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
openai/openai-openapi#584 ·