@@ -286,6 +286,125 @@ class Definition_Schema:
286
286
</p >
287
287
</details >
288
288
289
+ ### Github-actions config files
290
+
291
+ <details ><summary >----- Show -----</summary >
292
+ <p >
293
+
294
+ Github-actions model based on files from [ starter-workflows] ( https://github.com/actions/starter-workflows/tree/main/ci )
295
+
296
+ ```
297
+ json2models -m Actions "./starter-workflows/ci/*.yml" -s flat -f pydantic -i yaml --dkf env with jobs
298
+ ```
299
+
300
+ ``` python
301
+ r """
302
+ generated by json2python-models v0.2.3 at Tue Jul 13 19:52:43 2021
303
+ command: /opt/projects/json2python-models/venv/bin/json2models -m Actions ./starter-workflows/ci/*.yml -s flat -f pydantic -i yaml --dkf env with jobs
304
+ """
305
+ from pydantic import BaseModel, Field
306
+ from typing import Dict, List, Optional, Union
307
+ from typing_extensions import Literal
308
+
309
+
310
+ class Actions (BaseModel ):
311
+ on: Union[' On' , List[Literal[" push" ]]]
312
+ jobs: Dict[str , ' Job' ]
313
+ name: Optional[str ] = None
314
+ env: Optional[Dict[str , Union[int , str ]]] = {}
315
+
316
+
317
+ class On (BaseModel ):
318
+ push: Optional[' Push' ] = None
319
+ pull_request: Optional[' PullRequest' ] = None
320
+ release: Optional[' Release' ] = None
321
+ schedule: Optional[List[' Schedule' ]] = []
322
+ workflow_dispatch: Optional[None ] = None
323
+
324
+
325
+ class Push (BaseModel ):
326
+ branches: List[Literal[" $default-branch" ]]
327
+ tags: Optional[List[Literal[" v*.*.*" ]]] = []
328
+
329
+
330
+ class PullRequest (BaseModel ):
331
+ branches: List[Literal[" $default-branch" ]]
332
+
333
+
334
+ class Release (BaseModel ):
335
+ types: List[Literal[" created" , " published" ]]
336
+
337
+
338
+ class Schedule (BaseModel ):
339
+ cron: Literal[" $cron-daily" ]
340
+
341
+
342
+ class Job (BaseModel ):
343
+ runson: Literal[" ${{ matrix.os }} " , " macOS-latest" , " macos-latest" , " ubuntu-18.04" , " ubuntu-latest" , " windows-latest" ] = Field(... , alias = " runs-on" )
344
+ steps: List[' Step' ]
345
+ name: Optional[str ] = None
346
+ environment: Optional[Literal[" production" ]] = None
347
+ outputs: Optional[' Output' ] = None
348
+ container: Optional[' Container' ] = None
349
+ needs: Optional[Literal[" build" ]] = None
350
+ permissions: Optional[' Permission' ] = None
351
+ strategy: Optional[' Strategy' ] = None
352
+ defaults: Optional[' Default' ] = None
353
+ env: Optional[Dict[str , str ]] = {}
354
+
355
+
356
+ class Step (BaseModel ):
357
+ uses: Optional[str ] = None
358
+ name: Optional[str ] = None
359
+ with_: Optional[Dict[str , Union[bool , float , str ]]] = Field({}, alias = " with" )
360
+ run: Optional[str ] = None
361
+ env: Optional[Dict[str , str ]] = {}
362
+ workingdirectory: Optional[str ] = Field(None , alias = " working-directory" )
363
+ id_: Optional[Literal[" build-image" , " composer-cache" , " deploy-and-expose" , " image-build" , " login-ecr" , " meta" , " push-to-registry" , " task-def" ]] = Field(None , alias = " id" )
364
+ if_: Optional[str ] = Field(None , alias = " if" )
365
+ shell: Optional[Literal[" Rscript {0} " ]] = None
366
+
367
+
368
+ class Output (BaseModel ):
369
+ route: str = Field(... , alias = " ROUTE" )
370
+ selector: str = Field(... , alias = " SELECTOR" )
371
+
372
+
373
+ class Container (BaseModel ):
374
+ image: Literal[" crystallang/crystal" , " erlang:22.0.7" ]
375
+
376
+
377
+ class Permission (BaseModel ):
378
+ contents: Literal[" read" ]
379
+ packages: Literal[" write" ]
380
+
381
+
382
+ class Strategy (BaseModel ):
383
+ matrix: Optional[' Matrix' ] = None
384
+ maxparallel: Optional[int ] = Field(None , alias = " max-parallel" )
385
+ failfast: Optional[bool ] = Field(None , alias = " fail-fast" )
386
+
387
+
388
+ class Matrix (BaseModel ):
389
+ rversion: Optional[List[float ]] = Field([], alias = " r-version" )
390
+ pythonversion: Optional[List[float ]] = Field([], alias = " python-version" )
391
+ deno: Optional[List[Literal[" canary" , " v1.x" ]]] = []
392
+ os: Optional[List[Literal[" macOS-latest" , " ubuntu-latest" , " windows-latest" ]]] = []
393
+ rubyversion: Optional[List[float ]] = Field([], alias = " ruby-version" )
394
+ nodeversion: Optional[List[Literal[" 12.x" , " 14.x" , " 16.x" ]]] = Field([], alias = " node-version" )
395
+ configuration: Optional[List[Literal[" Debug" , " Release" ]]] = []
396
+
397
+
398
+ class Default (BaseModel ):
399
+ run: ' Run'
400
+
401
+
402
+ class Run (BaseModel ):
403
+ shell: Literal[" bash" ]
404
+ ```
405
+
406
+ </p ></details >
407
+
289
408
## Installation
290
409
291
410
| ** Be ware** : this project supports only ` python3.7 ` and higher. |
@@ -315,24 +434,33 @@ json2models -m Car car_*.json -f attrs > car.py
315
434
316
435
Arguments:
317
436
* ` -h ` , ` --help ` - Show help message and exit
318
-
319
- * ` -m ` , ` --model ` - Model name and its JSON data as path or unix-like path pattern. ` * ` , ` ** ` or ` ? ` patterns symbols are supported.
437
+
438
+ * ` -m ` , ` --model ` - Model name and its JSON data as path or unix-like path pattern. ` * ` , ` ** ` or ` ? ` patterns symbols
439
+ are supported.
320
440
* ** Format** : ` -m <Model name> [<JSON files> ...] `
321
441
* ** Example** : ` -m Car audi.json reno.json ` or ` -m Car audi.json -m Car reno.json ` (results will be the same)
322
-
323
- * ` -l ` , ` --list ` - Like ` -m ` but given json file should contain list of model data (dataset).
324
- If this file contains dict with nested list than you can pass ` <JSON key> ` to lookup.
325
- Deep lookups are supported by dot-separated path. If no lookup needed pass ` - ` as ` <JSON key> ` .
442
+
443
+ * ` -l ` , ` --list ` - Like ` -m ` but given json file should contain list of model data (dataset). If this file contains dict
444
+ with nested list than you can pass ` <JSON key> ` to lookup. Deep lookups are supported by dot-separated path. If no
445
+ lookup needed pass ` - ` as ` <JSON key> ` .
326
446
* ** Format** : ` -l <Model name> <JSON key> <JSON file> `
327
447
* ** Example** : ` -l Car - cars.json -l Person fetch_results.items.persons result.json `
328
- * ** Note** : Models names under this arguments should be unique.
329
-
448
+ * ** Note** : Models names under these arguments should be unique.
449
+
450
+ * ` -i ` , ` --input-format ` - Input file format (parser). Default is JSON parser. Yaml parser requires PyYaml or
451
+ ruamel.yaml to be installed. Ini parser uses
452
+ builtin [ configparser] ( https://docs.python.org/3/library/configparser.html ) . To implement new one - add new method
453
+ to ` cli.FileLoaders ` (and create pull request :) )
454
+ * ** Format** : ` -i {json, yaml, ini} `
455
+ * ** Example** : ` -i yaml `
456
+ * ** Default** : ` -i json `
457
+
330
458
* ` -o ` , ` --output ` - Output file
331
459
* ** Format** : ` -o <FILE> `
332
460
* ** Example** : ` -o car_model.py `
333
-
334
- * ` -f ` , ` --framework ` - Model framework for which python code is generated.
335
- ` base ` (default) mean no framework so code will be generated without any decorators and additional meta-data.
461
+
462
+ * ` -f ` , ` --framework ` - Model framework for which python code is generated.
463
+ ` base ` (default) mean no framework so code will be generated without any decorators and additional meta-data.
336
464
* ** Format** : ` -f {base, pydantic, attrs, dataclasses, custom} `
337
465
* ** Example** : ` -f pydantic `
338
466
* ** Default** : ` -f base `
0 commit comments