Incorrect `const` property validation
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 35/100
Piste de recherche
Commencez par reproduire le problème avec le document OpenAPI fourni et inspectez la validation de const introduite dans #1024. Suivez la génération de test-service-client/test_service_client/models/test_model.py, en particulier la fonction _parse_foo pour le schéma Foo. La tâche est terminée lorsque la validation prend en compte les deux alternatives de const au lieu de retourner après la première, et qu’un test de régression couvre l’exemple.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug
The const property validation introduced in #1024 is not correct when there are >= 2 non-none values.
In particular, the validation accepts only the first value
OpenAPI Spec File
--> Please focus on the Foo schema at the end
{
"openapi": "3.1.0",
"info": {
"title": "Test Service",
"version": "0.1.0"
},
"paths": {
"/test": {
"post": {
"summary": "Test",
"operationId": "test",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/TestModel"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
}
},
"components": {
"schemas": {
"TestModel": {
"properties": {
"foo": {
"$ref": "#/components/schemas/Foo"
}
},
"type": "object",
"required": [
"foo"
],
"title": "TestModel"
},
"Foo": {
"oneOf": [
{
"const": 1
},
{
"const": 2
}
],
"title": "FooType"
}
}
}
}
Desktop (please complete the following information):
- OS: all
- Python Version: all
- openapi-python-client version: the latest code, after #1024
Additional context
The above schema generates the file test-service-client/test_service_client/models/test_model.py as follows:
class TestModel:
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
def _parse_foo(data: object) -> Union[Literal[1], Literal[2]]:
componentsschemas_foo_type_0 = cast(Literal[1], data)
if componentsschemas_foo_type_0 != 1:
raise ValueError(
f"/components/schemas/Foo_type_0 must match const 1, got '{componentsschemas_foo_type_0}'"
)
return componentsschemas_foo_type_0
# -----> ERROR HERE: the code below this line is never reached<------
componentsschemas_foo_type_1 = cast(Literal[2], data)
if componentsschemas_foo_type_1 != 2:
raise ValueError(
f"/components/schemas/Foo_type_1 must match const 2, got '{componentsschemas_foo_type_1}'"
)
return componentsschemas_foo_type_1
foo = _parse_foo(d.pop("foo"))
test_model = cls(
foo=foo,
)
test_model.additional_properties = d
return test_model
- Langage dominant
- Python
- Étoiles
- 2k
- Forks
- 293
- Merge moyen
- 34 min
- PR mergées (30 j)
- 1
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de openapi-generators/openapi-python-client
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
-
Difficulté 3/5 1-2 jours Accessibilité débutants 72/100
openapi-generators/openapi-python-client#1451 · 1 commentaire ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 52/100
-
Difficulté 3/5 1-2 jours Accessibilité débutants 64/100
openapi-generators/openapi-python-client#1435 · 1 commentaire ·
Toutes les issues de openapi-generators/openapi-python-client
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
anthropics/skills#1811 · 1 commentaire ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
speaches-ai/speaches#678 ·
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
datalayer/mcp-compose#42 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
UKGovernmentBEIS/inspect_evals#2523 ·