Generates invalid python code for seemingly correct json
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 55/100
Rechercherichtung
Reproduzieren Sie das Problem mit dem bereitgestellten OpenAPI-Ausschnitt unter Verwendung von openapi-python-client 0.28.3 und verfolgen Sie anschließend die Generierung des Request-Bodys für nullable primitive Schemas. Der Payload nennt keine Repository-Datei und keinen Test; abgeschlossen ist die Aufgabe, wenn das generierte Endpoint-Modul syntaktisch gültig ist und den primitiven Request-Body ohne das im Bericht gezeigte verwaiste else verarbeitet.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Describe the bug
generator around primitives in request body fails
OpenAPI Spec File
I cannot share the full spec but this is an excempt:
"/api/helloworlduser/{externalId}/something": {
"patch": {
"tags": [
"UpdateHelloWorldUser"
],
"description": "Update user",
"operationId": "HelloWorldUserUpdate",
"parameters": [
{
"name": "externalId",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "number",
"format": "double",
"nullable": true
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserReadDTO"
}
}
}
}
}
}
},
this generates the file:
from http import HTTPStatus
from typing import Any, cast
from urllib.parse import quote
import httpx
from ...client import AuthenticatedClient, Client
from ...types import Response, UNSET
from ... import errors
from ...models.user_read_dto import UserReadDTO
from ...types import UNSET, Unset
from typing import cast
def _get_kwargs(
external_id: str,
*,
body: float | None | Unset = UNSET,
) -> dict[str, Any]:
headers: dict[str, Any] = {}
_kwargs: dict[str, Any] = {
"method": "patch",
"url": "/api/helloworlduser/{external_id}/something".format(external_id=quote(str(external_id), safe=""),),
}
else:
_kwargs["json"] = body
headers["Content-Type"] = "application/json"
_kwargs["headers"] = headers
return _kwargs
def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> UserReadDTO | None:
if response.status_code == 200:
response_200 = UserReadDTO.from_dict(response.json())
return response_200
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None
def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[UserReadDTO]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)
def sync_detailed(
external_id: str,
*,
client: AuthenticatedClient | Client,
body: float | None | Unset = UNSET,
) -> Response[UserReadDTO]:
""" Update user
Args:
external_id (str):
body (float | None | Unset):
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[UserReadDTO]
"""
kwargs = _get_kwargs(
external_id=external_id,
body=body,
)
response = client.get_httpx_client().request(
**kwargs,
)
return _build_response(client=client, response=response)
def sync(
external_id: str,
*,
client: AuthenticatedClient | Client,
body: float | None | Unset = UNSET,
) -> UserReadDTO | None:
""" Update user
Args:
external_id (str):
body (float | None | Unset):
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
UserReadDTO
"""
return sync_detailed(
external_id=external_id,
client=client,
body=body,
).parsed
async def asyncio_detailed(
external_id: str,
*,
client: AuthenticatedClient | Client,
body: float | None | Unset = UNSET,
) -> Response[UserReadDTO]:
""" Update user
Args:
external_id (str):
body (float | None | Unset):
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[UserReadDTO]
"""
kwargs = _get_kwargs(
external_id=external_id,
body=body,
)
response = await client.get_async_httpx_client().request(
**kwargs
)
return _build_response(client=client, response=response)
async def asyncio(
external_id: str,
*,
client: AuthenticatedClient | Client,
body: float | None | Unset = UNSET,
) -> UserReadDTO | None:
""" Update user
Args:
external_id (str):
body (float | None | Unset):
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
UserReadDTO
"""
return (await asyncio_detailed(
external_id=external_id,
client=client,
body=body,
)).parsed
which is a complete broken file (see the else in get_kwargs).
Desktop (please complete the following information):
- OS: mac os
- Python Version: 3.14
- openapi-python-client version: 0.28.3
- 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
-
link-check link-check:sphinx-theme
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
OpenHands/extensions#626 · 1 Kommentar ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
CSCfi/sd-search-api#39 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100