Skip to content

Commit

Permalink
Handle 'anyOf' specially
Browse files Browse the repository at this point in the history
nullable works differently for 'anyOf' and this commit introduces changes to reflect this OAI/OpenAPI-Specification#1368 (comment).
  • Loading branch information
sonicaj committed Jun 10, 2019
1 parent 3c0d1aa commit aae60f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/middlewared/middlewared/plugins/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ def validate(self, value):

def to_json_schema(self, parent=None):
schema = self.value.to_json_schema(parent)
schema['anyOf'] = [{'type': schema.pop('type')}, {'type': 'string', 'enum': ['INHERIT']}]
type_schema = schema.pop('type')
schema['nullable'] = 'null' in type_schema
if schema['nullable']:
type_schema.remove('null')
if len(type_schema) == 1:
type_schema = type_schema[0]
schema['anyOf'] = [{'type': type_schema}, {'type': 'string', 'enum': ['INHERIT']}]
return schema


Expand Down
1 change: 1 addition & 0 deletions src/middlewared/middlewared/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def to_json_schema(self, parent=None):
{'type': 'array'},
],
'title': self.title,
'nullable': True if self.null else False
}
if self.description:
schema['description'] = self.description
Expand Down

0 comments on commit aae60f1

Please sign in to comment.