Skip to content

Commit 5452100

Browse files
committed
Process OpenAPI components
This starts the process of handling complete OpenAPI specifications, iterating through the components and fixing thoses schemas. Related to pglass#8
1 parent ae4fc97 commit 5452100

File tree

6 files changed

+11266
-2
lines changed

6 files changed

+11266
-2
lines changed

openapi_schema_to_json_schema/to_jsonschema.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,33 @@ def convert(schema, options=None):
4343
if options['cloneSchema']:
4444
schema = json.loads(json.dumps(schema))
4545

46-
schema = convertSchema(schema, options)
46+
schema = convertDoc(schema, options)
4747
schema['$schema'] = 'http://json-schema.org/draft-04/schema#'
4848

4949
return schema
5050

5151

52+
def convertDoc(schema, options):
53+
components_schemas = schema.get('components', {}).get('schemas')
54+
if components_schemas:
55+
for name, struct in list(components_schemas.items()):
56+
components_schemas[name] = convertSchema(struct, options)
57+
58+
paths = schema.get('paths')
59+
if paths:
60+
for path, path_struct in paths.items():
61+
for operation, op_struct in path_struct.items():
62+
for param in op_struct.get('parameters', []):
63+
param_schema = param.get('schema')
64+
if param_schema:
65+
param['schema'] = convertSchema(
66+
param_schema, options)
67+
68+
# TODO requestBody & responses
69+
70+
return convertSchema(schema, options)
71+
72+
5273
def convertSchema(schema, options):
5374
structs = options['_structs']
5475
notSupported = options['_notSupported']

0 commit comments

Comments
 (0)