Description
Describe the bug
Schema fields may generate client models which contain invalid identifiers.
Example
Foo:
additionalProperties: false
properties:
1Q:
title: 1Q
type: object
2Q:
title: 2Q
type: object
required:
- 1Q
- 2Q
title: Foo
type: object
generates a class which is invalid Python:
class Foo:
""" """
1_q: Dict[Any, Any]
2_q: Dict[Any, Any]
def to_dict(self) -> Dict[str, Any]:
1_q = self.1_q
2_q = self.2_q
return {
"1Q": 1_q,
"2Q": 2_q,
}
Expected behavior
The output should be sanitized in some way. Python's str.isidentifier
can help, and the output could be prefixed by _
(although that could appear to be private, and thus confusing), or __
, or field_
, or something else.
In our manually-written clients, we replace it with one_q
and two_q
, but that's not generally applicable in openapi-python-client
(for reasons to include internationalization and maintaining semantic meaning)
As it stands now, this requires manual correction after generation. If the intent is (eventually) to support all valid OpenAPI schemas, then this would have to be addressed at some point.
Desktop (please complete the following information):
- OS: OSX 10.15.6
- Python Version: 3.7.3
- openapi-python-client version: 0.6.1
Thanks! Happy to send a PR for it.