8000 Fixed array and relation types to show its child correct type, instea… by sneto · Pull Request #54 · core-api/python-openapi-codec · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Mar 18, 2019. It is now read-only.

Fixed array and relation types to show its child correct type, instea… #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions openapi_codec/encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,21 @@ def _get_field_type(field):
if field.schema is None:
return 'string'

return _get_field_type_name(field.schema.__class__)


def _get_field_type_name(type):
if type is None:
return 'string'

return {
coreschema.String: 'string',
coreschema.Integer: 'integer',
coreschema.Number: 'number',
coreschema.Boolean: 'boolean',
coreschema.Array: 'array',
coreschema.Object: 'object',
}.get(field.schema.__class__, 'string')
}.get(type, 'string')


def _get_parameters(link, encoding):
Expand Down Expand Up @@ -162,7 +169,14 @@ def _get_parameters(link, encoding):
'type': field_type,
}
if field_type == 'array':
schema_property['items'] = {'type': 'string'}
type_string = 'string'
if hasattr(field, "schema") and hasattr(field.schema, "items") and field.schema.items is not None:
if isinstance(field.schema.items, type):
model_type = field.schema.items
else:
model_type = field.schema.items.__class__
type_string = _get_field_type_name(model_type)
schema_property['items'] = {'type': type_string}
properties[field.name] = schema_property
if field.required:
required.append(field.name)
Expand Down
0