-
-
Notifications
You must be signed in to change notification settings - Fork 767
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Body is already validated using jsonschema. There was also some type casting but it was wrong: e.g. not recurring deeply into dicts and lists, relying on existence of "type" in schema (which is not there e.g. if oneOf is used). Anyway, the only reason why types should be casted is converting integer values to float if the type is number. But this is in most cases irrelevant. Added an example, which did not work before this commit (echoed `{}`) e.g. for ``` curl localhost:8080/api/foo -H 'content-type: application/json' -d '{"foo": 1}' ``` but now the example works (echoes `{"foo": 1}`).
- Loading branch information
Showing
3 changed files
with
68 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import connexion | ||
import jsonschema | ||
import six | ||
from connexion.decorators.validation import RequestBodyValidator | ||
from connexion.json_schema import Draft4RequestValidator | ||
|
||
async def echo(body): | ||
return body | ||
|
||
if __name__ == '__main__': | ||
app = connexion.AioHttpApp( | ||
__name__, | ||
port=8080, | ||
specification_dir='.', | ||
options={'swagger_ui': True} | ||
) | ||
app.add_api('schema.yaml') | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
openapi: '3.0.0' | ||
info: | ||
version: '1' | ||
title: Custom Validator Example | ||
servers: | ||
- url: http://localhost:8080/{basePath} | ||
variables: | ||
basePath: | ||
default: api | ||
paths: | ||
/echo: | ||
post: | ||
operationId: oneof.echo | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
additionalProperties: false | ||
required: | ||
- foo | ||
properties: | ||
foo: | ||
oneOf: | ||
- {type: boolean} | ||
- {type: number} | ||
default: | ||
foo: false | ||
responses: | ||
'200': | ||
description: Echo the validated request. |