Endpoints are not created for routes with Pydantic model default values
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 45/100
Rechercherichtung
Beginnen Sie in openapi_python_client/parser/properties/union.py etwa bei Zeile 87 und reproduzieren Sie den Fehler mit der bereitgestellten OpenAPI-Spezifikation oder dem FastAPI-Beispiel. Verfolgen Sie, wie der Standardwert der Union validiert wird, und überprüfen Sie anschließend, dass der Endpunkt erfolgreich generiert wird, anstatt weggelassen zu werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Python
- Sterne
- 2k
- Forks
- 293
- Ø Merge
- 34 Min.
- Gemergte PRs (30 T.)
- 1
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus openapi-generators/openapi-python-client
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
openapi-generators/openapi-python-client#1451 · 1 Kommentar ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 52/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 64/100
openapi-generators/openapi-python-client#1435 · 1 Kommentar ·
Alle Issues in openapi-generators/openapi-python-client
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
zostera/django-bootstrap4#894 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
use-agent-os/agent-os#3276 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
NousResearch/hermes-agent#117848 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
zilliztech/memsearch#759 ·