Endpoints are not created for routes with Pydantic model default values
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Inizia in openapi_python_client/parser/properties/union.py intorno alla riga 87 e riproduci il fallimento con la specifica OpenAPI fornita o l’esempio FastAPI. Traccia come viene validato il valore predefinito dell’unione, quindi verifica che l’endpoint venga generato correttamente invece di essere omesso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
When attempting to generate the client for an endpoint containing a route with a default value represented by a Pydantic model, the client generation fails. Specifically, the issue arises when the default value is set as a Pydantic model, such as the example below:
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Cake(BaseModel):
slices: int
@app.post("/eat_cake")
async def eat_cake(cake: Cake | None = Cake(slices=20)):
return {"message": f"Eating {cake.slices} slices of cake!"}
The generated client results in the following error message:
Warning(s) encountered while generating. Client was generated, but some pieces may be missing
WARNING parsing POST /graph_study/{customer_name}/distinct_identities/distinct_to_base/eat_cake within default. Endpoint will not be generated.
Value {'slices': 20} is not valid, only None is allowed
This issue is caused by a condition not being met in the union.py file.
To Reproduce
- Define a FastAPI app with a route containing a Pydantic model with a default value.
- Attempt to generate the client using openapi-python-client version 0.17.2.
OpenAPI Spec File
{
"openapi": "3.0.2",
"info": {
"title": "FastAPI",
"version": "1.0"
},
"paths": {
"/cake_eater/eat_cake": {
"post": {
"summary": "Eat Cake",
"operationId": "eat_cake_cake_eater___eat_cake_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"anyOf": [
{
"$ref": "#/components/schemas/Cake"
},
{
"type": "null"
}
],
"title": "Cake",
"default": {
"slices": 20
}
}
}
}
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Cake": {
"properties": {
"slices": {
"type": "integer",
"title": "Slices"
}
},
"type": "object",
"required": [
"slices"
],
"title": "Cake"
},
"HTTPValidationError": {
"properties": {
"detail": {
"items": {
"$ref": "#/components/schemas/ValidationError"
},
"type": "array",
"title": "Detail"
}
},
"type": "object",
"title": "HTTPValidationError"
},
"ValidationError": {
"properties": {
"loc": {
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "integer"
}
]
},
"type": "array",
"title": "Location"
},
"msg": {
"type": "string",
"title": "Message"
},
"type": {
"type": "string",
"title": "Error Type"
}
},
"type": "object",
"required": [
"loc",
"msg",
"type"
],
"title": "ValidationError"
}
}
}
}
Desktop (please complete the following information):
- OS: Windows 11
- Python Version: 3.11.1
- openapi-python-client version 0.17.2
Additional context
- Lingua principale
- Python
- Stelle
- 2k
- Fork
- 293
- Merge medio
- 34m
- PR unite (30g)
- 1
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 openapi-generators/openapi-python-client
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
openapi-generators/openapi-python-client#1451 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 64/100
openapi-generators/openapi-python-client#1435 · 1 commento ·
Tutte le issue di openapi-generators/openapi-python-client
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
zostera/django-bootstrap4#894 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
use-agent-os/agent-os#3276 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
NousResearch/hermes-agent#117848 ·