openapi icon indicating copy to clipboard operation
openapi copied to clipboard

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

Open havok4u opened this issue 4 years ago • 0 comments

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'}) –

havok4u avatar Aug 19 '21 00:08 havok4u