Generates invalid python code for seemingly correct json
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 55/100
Línea de trabajo
Reproduzca el problema con el fragmento de OpenAPI proporcionado usando openapi-python-client 0.28.3 y, a continuación, siga la generación del cuerpo de la solicitud para esquemas primitivos anulables. El payload no menciona ningún archivo del repositorio ni ninguna prueba; el trabajo está terminado cuando el módulo de endpoint generado es sintácticamente válido y gestiona el cuerpo de la solicitud primitivo sin el else huérfano mostrado en el informe.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Python
- Estrellas
- 2k
- Forks
- 293
- Merge medio
- 34 min
- PR fusionados (30 d)
- 1
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de openapi-generators/openapi-python-client
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
openapi-generators/openapi-python-client#1451 · 1 comentario ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 64/100
openapi-generators/openapi-python-client#1435 · 1 comentario ·
Todos los issues de openapi-generators/openapi-python-client
Issues similares
-
sponsored
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
opensubtitlescom: moviehash never sent when opensubtitles (.org) is not in the provider list Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
Diaoul/subliminal#1382 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
-
triage/confirmed
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
agentscope-ai/agentscope#2775 ·
-
worker.gpuVendors silently accepts unsupported/misspelled vendor names — no validation guard Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100