godto


Namegodto JSON
Version 0.0.5 PyPI version JSON
download
home_pagehttps://github.com/lmmx/godto
SummaryData Transfer Object (DTO) codegen from OpenAPI JSON schemas
upload_time2023-06-06 09:07:53
maintainerLouis Maddox
docs_urlNone
authorLouis Maddox
requires_python>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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).

```py
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][StopPoint_schema] in `tubeulator`.

[StopPoint_schema]: https://github.com/lmmx/tubeulator/blob/master/src/tubeulator/data/openapi/StopPoint/StopPoint.json

```py
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

```py
>>> 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+

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lmmx/godto",
    "name": "godto",
    "maintainer": "Louis Maddox",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "louismmx@gmail.com",
    "keywords": "",
    "author": "Louis Maddox",
    "author_email": "louismmx@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/49/7f/10cfd31573fe510033eb8067a5ef43a3faaeae72b601a74ace8b0fc47edb/godto-0.0.5.tar.gz",
    "platform": null,
    "description": "# godto\n\nData Transfer Object (DTO) codegen from JSON schemas following the OpenAPI spec \n\n## Usage\n\n### Full OpenAPI schema model\n\nTo work with an OpenAPI schema, load it with the `Model` class,\nwhich is a Pydantic model (however note that the class name 'Model' comes from the OpenAPI spec).\n\n```py\nfrom godto.openapi.v3 import Model\n\nmodel = Model.parse_raw(schema_json)\n```\n\nFor example the Transport for London `StopPoint` API schema\nis [shipped as package data][StopPoint_schema] in `tubeulator`.\n\n[StopPoint_schema]: https://github.com/lmmx/tubeulator/blob/master/src/tubeulator/data/openapi/StopPoint/StopPoint.json\n\n```py\nfrom pathlib import Path\n\npath_to_schema = Path(\"data/openapi/StopPoint/StopPoint.json\")\nschema_json = path_to_schema.read_text()\n```\n\n### Model helper functions\n\nYou can also work with partial views on the model, such as the paths and their parameters.\n\nThe examples in the following code block show `model_paths` which loads the schema for a given spec\n(by default OpenAPI v3) and returns its parameters for a specific method (by default GET):\n\n- `required`: whether the parameter is required or optional\n- `schema_`: the schema for parsing the parameter\n- `description`: the human-readable parameter docstring\n\n```py\n>>> from godto.api.model import model_paths\n>>> param_requirements = model_paths(schema_json, extract=\"required\")\n>>> pprint(param_requirements)                                                      \n{'/': {'categories': False,                                                         \n       'lat': True,                                                                 \n       'lon': True,                                                                 \n       'modes': False,                                                              \n       'radius': False,                                                             \n       'returnLines': False,                                                        \n       'stopTypes': True,                                                           \n       'useStopPointHierarchy': False},                                             \n '/*': {},\n '/Meta/Categories': {},\n '/Meta/Modes': {},\n...\n>>> param_schemas = model_paths(schema_json, extract=\"schema_\")\n>>> param_descs = model_paths(schema_json, extract=\"description\")            \n>>> pprint(param_descs)                                                        \n>>> pprint(param_descs)                                                             \n{'/': {'categories': 'an optional list of comma separated property categories '     \n                     \"to return in the StopPoint's property bag. If null or \"   \n                     'empty, all categories of property are returned. Pass the '    \n                     'keyword \"none\" to return no properties (a valid list of '     \n                     'categories can be obtained from the '                         \n                     '/StopPoint/Meta/categories endpoint)',                   \n       'lat': 'Format - double. the latitude of the centre of the bounding '    \n              'circle',                                                             \n       'lon': 'Format - double. the longitude of the centre of the bounding '  \n              'circle',                                                             \n       'modes': 'the list of modes to search (comma separated mode names e.g. '\n                'tube,dlr)',                                                        \n       'radius': 'Format - int32. the radius of the bounding circle in metres '     \n                 '(default : 200)',\n...                  \n```\n\n## Requirements\n\nPython 3.9+\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Data Transfer Object (DTO) codegen from OpenAPI JSON schemas",
    "version": "0.0.5",
    "project_urls": {
        "Bug Tracker": "https://github.com/lmmx/godto/issues",
        "Homepage": "https://github.com/lmmx/godto",
        "Source Code": "https://github.com/lmmx/godto"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dfb5ec144873a5da2b5a18a4eb3295c9221d68d7b70ac34e841a4002a1ec486a",
                "md5": "4c5b979e58ab2a2012f204a9e2c6154c",
                "sha256": "9f24115fd5c0f01cd2079bbc50cbc18ad66c7e447f7e7f72d1c591c072d525de"
            },
            "downloads": -1,
            "filename": "godto-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4c5b979e58ab2a2012f204a9e2c6154c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 19025,
            "upload_time": "2023-06-06T09:07:51",
            "upload_time_iso_8601": "2023-06-06T09:07:51.374893Z",
            "url": "https://files.pythonhosted.org/packages/df/b5/ec144873a5da2b5a18a4eb3295c9221d68d7b70ac34e841a4002a1ec486a/godto-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "497f10cfd31573fe510033eb8067a5ef43a3faaeae72b601a74ace8b0fc47edb",
                "md5": "86cb298caa402b3ee9231c22a5bb29ef",
                "sha256": "c1d7f7b78a6841a05eb3fff7f6940bda3396ad8041a3be9d0d22518362b42b6e"
            },
            "downloads": -1,
            "filename": "godto-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "86cb298caa402b3ee9231c22a5bb29ef",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 18939,
            "upload_time": "2023-06-06T09:07:53",
            "upload_time_iso_8601": "2023-06-06T09:07:53.308675Z",
            "url": "https://files.pythonhosted.org/packages/49/7f/10cfd31573fe510033eb8067a5ef43a3faaeae72b601a74ace8b0fc47edb/godto-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-06 09:07:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lmmx",
    "github_project": "godto",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "godto"
}
        
Elapsed time: 0.08558s