Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix openapi >=3 versions compatibility #91

Merged
merged 6 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions spectree/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,16 @@ async def async_validate(*args, **kwargs):
):
if model is not None:
assert issubclass(model, BaseModel)
self.models[model.__name__] = model.schema()
self.models[model.__name__] = model.schema(
ref_template="#/components/schemas/{model}"
)
setattr(validation, name, model.__name__)

if resp:
for model in resp.models:
self.models[model.__name__] = model.schema()
self.models[model.__name__] = model.schema(
ref_template="#/components/schemas/{model}"
)
validation.resp = resp

if tags:
Expand Down Expand Up @@ -214,8 +218,7 @@ def _generate_spec(self):
},
"tags": list(tags.values()),
"paths": {**routes},
"components": {"schemas": {**self.models}},
"definitions": self._get_model_definitions(),
"components": {"schemas": {**self.models, **self._get_model_definitions()}},
}
return spec

Expand Down
5 changes: 4 additions & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

@pytest.mark.parametrize("api", [flask_api, falcon_api, starlette_api])
def test_plugin_spec(api):
models = {m.__name__: m.schema() for m in (Query, JSON, Resp, Cookies, Headers)}
models = {
m.__name__: m.schema(ref_template="#/components/schemas/{model}")
for m in (Query, JSON, Resp, Cookies, Headers)
}
for name, schema in models.items():
assert api.spec["components"]["schemas"][name] == schema

Expand Down
4 changes: 3 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def test_parse_request():


def test_parse_params():
models = {"DemoModel": DemoModel.schema()}
models = {
"DemoModel": DemoModel.schema(ref_template="#/components/schemas/{model}")
}
assert parse_params(demo_func, [], models) == []
params = parse_params(demo_class.demo_method, [], models)
assert len(params) == 3
Expand Down