Data Transfer Object (DTO) codegen from OpenAPI JSON schemas
Project description
godto
Data Transfer Object (DTO) codegen from JSON schemas following the OpenAPI spec
Usage
Full OpenAPI schema model
To work with an OpenAPI schema, load it with the Model
class,
which is a Pydantic model (however note that the class name 'Model' comes from the OpenAPI spec).
from godto.openapi.v3 import Model
model = Model.parse_raw(schema_json)
For example the Transport for London StopPoint
API schema
is shipped as package data in tubeulator
.
from pathlib import Path
path_to_schema = Path("data/openapi/StopPoint/StopPoint.json")
schema_json = path_to_schema.read_text()
Model helper functions
You can also work with partial views on the model, such as the paths and their parameters.
The examples in the following code block show model_paths
which loads the schema for a given spec
(by default OpenAPI v3) and returns its parameters for a specific method (by default GET):
required
: whether the parameter is required or optionalschema_
: the schema for parsing the parameterdescription
: the human-readable parameter docstring
>>> from godto.api.model import model_paths
>>> param_requirements = model_paths(schema_json, extract="required")
>>> pprint(param_requirements)
{'/': {'categories': False,
'lat': True,
'lon': True,
'modes': False,
'radius': False,
'returnLines': False,
'stopTypes': True,
'useStopPointHierarchy': False},
'/*': {},
'/Meta/Categories': {},
'/Meta/Modes': {},
...
>>> param_schemas = model_paths(schema_json, extract="schema_")
>>> param_descs = model_paths(schema_json, extract="description")
>>> pprint(param_descs)
>>> pprint(param_descs)
{'/': {'categories': 'an optional list of comma separated property categories '
"to return in the StopPoint's property bag. If null or "
'empty, all categories of property are returned. Pass the '
'keyword "none" to return no properties (a valid list of '
'categories can be obtained from the '
'/StopPoint/Meta/categories endpoint)',
'lat': 'Format - double. the latitude of the centre of the bounding '
'circle',
'lon': 'Format - double. the longitude of the centre of the bounding '
'circle',
'modes': 'the list of modes to search (comma separated mode names e.g. '
'tube,dlr)',
'radius': 'Format - int32. the radius of the bounding circle in metres '
'(default : 200)',
...
Requirements
Python 3.9+
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file godto-0.0.5.tar.gz
.
File metadata
- Download URL: godto-0.0.5.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1d7f7b78a6841a05eb3fff7f6940bda3396ad8041a3be9d0d22518362b42b6e |
|
MD5 | 86cb298caa402b3ee9231c22a5bb29ef |
|
BLAKE2b-256 | 497f10cfd31573fe510033eb8067a5ef43a3faaeae72b601a74ace8b0fc47edb |
File details
Details for the file godto-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: godto-0.0.5-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f24115fd5c0f01cd2079bbc50cbc18ad66c7e447f7e7f72d1c591c072d525de |
|
MD5 | 4c5b979e58ab2a2012f204a9e2c6154c |
|
BLAKE2b-256 | dfb5ec144873a5da2b5a18a4eb3295c9221d68d7b70ac34e841a4002a1ec486a |