@@ -83,47 +83,46 @@ driver_standings.json
8383```
8484
8585```
86- json2models -f attrs - l DriverStandings driver_standings.json
86+ json2models -f pydantic -s flat - l DriverStandings - driver_standings.json
8787```
8888
8989``` python
90- import attr
91- from json_to_models.dynamic_typing import IntString, IsoDateString
90+ r """
91+ generated by json2python-models v0.1.2 at Mon May 4 17:46:30 2020
92+ command: /opt/projects/json2python-models/venv/bin/json2models -f pydantic -s flat -l DriverStandings - driver_standings.json
93+ """
94+ from pydantic import BaseModel, Field
9295from typing import List
93-
94-
95- @attr.s
96- class DriverStandings :
97- @attr.s
98- class DriverStanding :
99- @attr.s
100- class Driver :
101- driver_id: str = attr.ib()
102- permanent_number: IntString = attr.ib(converter = IntString)
103- code: str = attr.ib()
104- url: str = attr.ib()
105- given_name: str = attr.ib()
106- family_name: str = attr.ib()
107- date_of_birth: IsoDateString = attr.ib(converter = IsoDateString)
108- nationality: str = attr.ib()
109-
110- @attr.s
111- class Constructor :
112- constructor_id: str = attr.ib()
113- url: str = attr.ib()
114- name: str = attr.ib()
115- nationality: str = attr.ib()
116-
117- position: IntString = attr.ib(converter = IntString)
118- position_text: IntString = attr.ib(converter = IntString)
119- points: IntString = attr.ib(converter = IntString)
120- wins: IntString = attr.ib(converter = IntString)
121- driver: ' Driver' = attr.ib()
122- constructors: List[' Constructor' ] = attr.ib()
123-
124- season: IntString = attr.ib(converter = IntString)
125- round : IntString = attr.ib(converter = IntString)
126- driver_standings: List[' DriverStanding' ] = attr.ib()
96+ from typing_extensions import Literal
97+
98+ class DriverStandings (BaseModel ):
99+ season: int
100+ round_: int = Field(... , alias = " round" )
101+ DriverStandings: List[' DriverStanding' ]
102+
103+ class DriverStanding (BaseModel ):
104+ position: int
105+ position_text: int = Field(... , alias = " positionText" )
106+ points: int
107+ wins: int
108+ driver: ' Driver' = Field(... , alias = " Driver" )
109+ constructors: List[' Constructor' ] = Field(... , alias = " Constructors" )
110+
111+ class Driver (BaseModel ):
112+ driver_id: str = Field(... , alias = " driverId" )
113+ permanent_number: int = Field(... , alias = " permanentNumber" )
114+ code: str
115+ url: str
116+ given_name: str = Field(... , alias = " givenName" )
117+ family_name: str = Field(... , alias = " familyName" )
118+ date_of_birth: str = Field(... , alias = " dateOfBirth" )
119+ nationality: str
120+
121+ class Constructor (BaseModel ):
122+ constructor_id: str = Field(... , alias = " constructorId" )
123+ url: str
124+ name: str
125+ nationality: Literal[" Austrian" , " German" , " American" , " British" , " Italian" , " French" ]
127126```
128127
129128</p >
@@ -139,14 +138,19 @@ class DriverStandings:
139138It requires a lit bit of tweaking:
140139* Some fields store routes/models specs as dicts
141140* There is a lot of optinal fields so we reduce merging threshold
141+ * Disable string literals
142142
143143```
144- json_to_models -s flat -f dataclasses -m Swagger testing_tools/swagger.json
145- --dict-keys-fields securityDefinitions paths responses definitions properties
146- --merge percent_50 number
144+ json2models -s flat -f dataclasses -m Swagger testing_tools/swagger.json \
145+ --dict-keys-fields securityDefinitions paths responses definitions properties \
146+ --merge percent_50 number --max-strings-literals 0
147147```
148148
149149``` python
150+ r """
151+ generated by json2python-models v0.1.2 at Mon May 4 18:08:09 2020
152+ command: /opt/projects/json2python-models/json_to_models/__main__.py -s flat -f dataclasses -m Swagger testing_tools/swagger.json --max-strings-literals 0 --dict-keys-fields securityDefinitions paths responses definitions properties --merge percent_50 number
153+ """
150154from dataclasses import dataclass, field
151155from json_to_models.dynamic_typing import FloatString
152156from typing import Any, Dict, List, Optional, Union
@@ -192,15 +196,15 @@ class Path:
192196
193197@dataclass
194198class Property :
195- type : str
196- format : Optional[str ] = None
199+ type_ : str
200+ format_ : Optional[str ] = None
197201 xnullable: Optional[bool ] = None
198202 items: Optional[' Item_Schema' ] = None
199203
200204
201205@dataclass
202206class Property_2E :
203- type : str
207+ type_ : str
204208 title: Optional[str ] = None
205209 read_only: Optional[bool ] = None
206210 max_length: Optional[int ] = None
@@ -209,26 +213,26 @@ class Property_2E:
209213 enum: Optional[List[str ]] = field(default_factory = list )
210214 maximum: Optional[int ] = None
211215 minimum: Optional[int ] = None
212- format : Optional[str ] = None
216+ format_ : Optional[str ] = None
213217
214218
215219@dataclass
216220class Item :
217- ref: Optional[str ] = None
218221 title: Optional[str ] = None
219- type : Optional[str ] = None
222+ type_: Optional[str ] = None
223+ ref: Optional[str ] = None
220224 max_length: Optional[int ] = None
221225 min_length: Optional[int ] = None
222226
223227
224228@dataclass
225229class Parameter_SecurityDefinition :
226- name: str
227- in_: str
230+ name: Optional[ str ] = None
231+ in_: Optional[ str ] = None
228232 required: Optional[bool ] = None
229233 schema: Optional[' Item_Schema' ] = None
230- type : Optional[str ] = None
231234 description: Optional[str ] = None
235+ type_: Optional[str ] = None
232236
233237
234238@dataclass
@@ -253,10 +257,10 @@ class Response:
253257
254258@dataclass
255259class Definition_Schema :
256- ref: Optional[ str ] = None
260+ type_: str
257261 required: Optional[List[str ]] = field(default_factory = list )
258- type : Optional[str ] = None
259- properties : Optional[Dict[ str , Union[ ' Property_2E ' , ' Property ' ]]] = field( default_factory = dict )
262+ properties : Optional[Dict[ str , Union[ ' Property ' , ' Property_2E ' ]]] = field( default_factory = dict )
263+ ref : Optional[str ] = None
260264```
261265
262266</p >
0 commit comments