Skip to content

Commit

Permalink
Merge 24ebdb7 into 3806981
Browse files Browse the repository at this point in the history
  • Loading branch information
MingboPeng committed Jan 23, 2020
2 parents 3806981 + 24ebdb7 commit eb724e0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -9,3 +9,5 @@ test.db
test.py
out.txt
docs/*.json
.eggs
.pytest_cache
19 changes: 19 additions & 0 deletions honeybee_schema/_openapi.py
Expand Up @@ -81,6 +81,25 @@ def get_openapi(
}
tags.append(tag)

# sort properties order: put required parameters at begining of the list
s = schemas[name]
if 'required' in s:
props = s['properties']
required = s['required']

propKeys = props.keys()
sortedProps = {}
optional = {}
for r in propKeys:
if r in required:
sortedProps[r] = props[r]
else:
optional[r] = props[r]

sortedProps.update(optional)

s['properties'] = sortedProps

tag_names.sort()
open_api['tags'] = tags
open_api['x-tagGroups'][0]['tags'] = tag_names
Expand Down
37 changes: 37 additions & 0 deletions tests/test_sortProps.py
@@ -0,0 +1,37 @@

from honeybee_schema.model import Model
from pydantic.schema import schema
import pytest


def test_sort_required_params():
definitions = schema([Model], ref_prefix='#/components/schemas/')

schemas = definitions['definitions']
schema_names = list(schemas.keys())
schema_names.sort()

for name in schema_names:
s = schemas[name]

if 'required' in s:
props = s['properties']
required = s['required']

propKeys = props.keys()

sortedProps = {}
optional = {}
for r in propKeys:
if r in required:
sortedProps[r] = props[r]
else:
optional[r] = props[r]

sortedProps.update(optional)

s['properties'] = sortedProps

return schemas


0 comments on commit eb724e0

Please sign in to comment.