def _create_content_field(content_types: dict, root_spec: dict): return { content_type: { "schema": OpenApiSchemaConverter.convert(schema, root_spec) } for content_type, schema in content_types.items() }
def _add_query_parameters(method_spec: dict, method_object: object, root_spec: dict): method_spec["parameters"].extend([ { "name": query_parameter.name, "in": "query", "description": query_parameter.description, "required": query_parameter.field_type.required, "schema": OpenApiSchemaConverter.convert(query_parameter.field_type, root_spec) } for query_parameter in getattr(method_object, "__query_parameters__", []) ])
def test_nested_list(self): open_api_schema = OpenApiSchemaConverter.convert(SchemaWithNestedList(), {}) self.assertEqual({ 'description': None, 'properties': { 'nested_list': { 'description': 'I have a nested field', 'properties': { 'nested_field': { 'description': 'My ' 'simple ' 'schema.', 'properties': { 'field1': { 'default': 1, 'description': 'Doc ' 'of ' 'field1', 'exclusiveMaximum': False, 'exclusiveMinimum': False, 'maximum': 10, 'minimum': 1, 'type': 'integer' }, 'field2': { 'description': 'A ' 'string ' 'field.', 'maxLength': 100, 'minLength': 1, 'pattern': '\\w+', 'type': 'string' }, 'field3': { 'description': 'A ' 'UUID ' 'field.', 'format': 'uuid', 'type': 'string' } }, 'required': ['field1'], 'type': 'object' } }, 'required': ['nested_field'], 'type': 'object' } }, 'required': [], 'type': 'object' }, open_api_schema)
def test_mapping(self): open_api_schema = OpenApiSchemaConverter.convert(SchemaWithMapping(), {}) self.assertEqual({ 'description': None, 'properties': { 'mapping': { 'additionalProperties': {'type': 'integer'}, 'description': 'An abstract class for objects with ' 'key-value pairs.', 'type': 'object' } }, 'required': [], 'type': 'object' }, open_api_schema)
def test_integer_list(self): open_api_schema = OpenApiSchemaConverter.convert(SchemaWithIntegerList(), {}) self.assertEqual({ 'description': None, 'properties': { 'int_list': { 'items': { 'description': 'An integer field.', 'type': 'integer' }, 'type': 'array' } }, 'required': [], 'type': 'object' }, open_api_schema)