Client generation error when property names differ only by underscore prefix / suffix
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
Piste de recherche
Commencez par openapi_python_client/utils.py, autour de l'appel findall indiqué, puis suivez les points d'entrée de la CLI generate et update. Reproduisez la collision avec schema-underscore-collision.yaml et examinez les méthodes to_dict et from_dict du modèle généré. C'est terminé lorsque des identifiants Python valides et distincts sont générés pour des propriétés telles que a, a et a, sans champs ni arguments nommés dupliqués.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Originally predicted in https://github.com/openapi-generators/openapi-python-client/issues/383#issuecomment-830839559
Since re.findall(rf"[^{DELIMITERS}]+", value) trims prefix and suffix _ characters while generating python property identifiers, 2+ schema properties on a single model that differ only by such underscores causes CLI generate and update commands to fail.
Given it would be problematic to carry through those untrimmed identifiers due to the semantic meaning of prefix and suffix _ on identifiers in python, it makes sense to have a fallback value to use like a title property or a configurable prefix.
Resulting error:
$ openapi-python-client generate --path schema-underscore-collision.yaml --fail-on-warning
Generating schema-underscore-collision-client
Error(s) encountered while generating, client was not created
black failed
reformatted schema_underscore_collision_client/api/__init__.py
reformatted schema_underscore_collision_client/__init__.py
reformatted schema_underscore_collision_client/types.py
error: cannot format schema_underscore_collision_client/models/get_response_200.py: cannot use --safe with this file; failed to parse source file AST: keyword argument repeated (<unknown>, line 55)
This could be caused by running Black with an older Python version that does not support new syntax used in your source file.
reformatted schema_underscore_collision_client/client.py
reformatted schema_underscore_collision_client/api/default/get.py
Oh no! 💥 💔 💥
5 files reformatted, 2 files left unchanged, 1 file failed to reformat.
Using an example schema-underscore-collision.yaml:
openapi: 3.0.2
info:
title: schema-underscore-collision
version: 1.0.0
paths:
/:
get:
description:
responses:
'200':
description: test
content:
application/json:
schema:
type: object
properties:
_a: {}
a: {}
a_: {}
The problematic schema_underscore_collision_client/models/get_response_200.py file, reported error is in the from_dict method but to_dict also suffers from the ambiguity:
from typing import Any, BinaryIO, Dict, List, Optional, TextIO, Tuple, Type, TypeVar, Union
import attr
from ..types import UNSET, Unset
T = TypeVar("T", bound="GetResponse200")
@attr.s(auto_attribs=True)
class GetResponse200:
"""
Attributes:
a (Union[Unset, Any]):
a (Union[Unset, Any]):
a (Union[Unset, Any]):
"""
a: Union[Unset, Any] = UNSET
a: Union[Unset, Any] = UNSET
a: Union[Unset, Any] = UNSET
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
def to_dict(self) -> Dict[str, Any]:
a = self.a
a = self.a
a = self.a
field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update({
})
if a is not UNSET:
field_dict["_a"] = a
if a is not UNSET:
field_dict["a"] = a
if a is not UNSET:
field_dict["a_"] = a
return field_dict
@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
a = d.pop("_a", UNSET)
a = d.pop("a", UNSET)
a = d.pop("a_", UNSET)
get_response_200 = cls(
a=a,
a=a,
a=a,
)
get_response_200.additional_properties = d
return get_response_200
@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())
def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]
def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value
def __delitem__(self, key: str) -> None:
del self.additional_properties[key]
def __contains__(self, key: str) -> bool:
return key in self.additional_properties
Versions
- Python:
3.7.12 - openapi-python-client:
0.11.1
- 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
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
zostera/django-bootstrap4#894 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
use-agent-os/agent-os#3276 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
NousResearch/hermes-agent#117848 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
zilliztech/memsearch#759 ·