Skip to main content

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 optional
  • schema_: the schema for parsing the parameter
  • description: 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+

Metadata

Release files for godto 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for godto 0.0.5
File Size Uploaded
godto-0.0.5.tar.gz 18.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for godto 0.0.5
File Interpreter ABI Platform
godto-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 38.0 kB

Release files / godto-0.0.5.tar.gz

Download URL godto-0.0.5.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c1d7f7b78a6841a05eb3fff7f6940bda3396ad8041a3be9d0d22518362b42b6e
BLAKE2b-256 checksum
How to use checksums
497f10cfd31573fe510033eb8067a5ef43a3faaeae72b601a74ace8b0fc47edb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release files / godto-0.0.5-py3-none-any.whl

Download URL godto-0.0.5-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f24115fd5c0f01cd2079bbc50cbc18ad66c7e447f7e7f72d1c591c072d525de
BLAKE2b-256 checksum
How to use checksums
dfb5ec144873a5da2b5a18a4eb3295c9221d68d7b70ac34e841a4002a1ec486a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page