sphinx-contrib / openapi

OpenAPI (fka Swagger) spec renderer for Sphinx.
https://sphinxcontrib-openapi.readthedocs.io
BSD 2-Clause "Simplified" License
111 stars 80 forks source link

type = param['schema']['type'] breaks in newer spec #113

Closed havok4u closed 1 year ago

havok4u commented 3 years ago

PROBLEM: In the newest spec and pydantic capability you can give multiple types for validation. When I do a make html this breaks as there is not type key under param['schema']. Rather you now have anyof as a key and a list of types of which a type might have a format as an alternative.
In file sphinxcontrib/openapi/openapi30.py, starting on line 270

for param in filter(lambda p: p['in'] == 'path', parameters):
        yield indent + ':param {type} {name}:'.format(
           type=param['schema']['type'],
           name=param['name'])

This can be changed to the following to fix:

for param in filter(lambda p: p['in'] == 'path', parameters):
        if 'type' in param['schema'].keys():
            dtype = param['schema']['type']
        else:
            dtype = set()
            for t in param['schema']['anyOf']:
                if 'format' in t.keys():
                    dtype.add(t['format'])
                else:
                    dtype.add( t['type'])
        yield indent + ':param {type} {name}:'.format(
           type = dtype,
           name=param['name'])

This then gives an output of Parameters componentid ({'uuid', 'integer', 'string'}) –

stephenfin commented 1 year ago

Resolved via https://github.com/sphinx-contrib/openapi/pull/143