Comments (6)
Please, provide a reproducible example: handler spec + input data.
from aiohttp-swagger3.
Ok, tomorrow
from aiohttp-swagger3.
Hi,
Edited message. Actually it does behave incorrectly imho.
from aiohttp import web
from aiohttp_swagger3 import SwaggerDocs, SwaggerUiSettings
routes = web.RouteTableDef()
@routes.post("/bug60/addProp")
async def addProp(request: web.Request, body) -> web.Response:
"""
---
summary: Mixed type array as additionalProperties value
tags:
- bug60
requestBody:
required: true
content:
application/json:
schema:
type: object
additionalProperties:
type: array
items:
oneOf:
- type: string
- type: number
example:
key: ["abc", 1, 1.1]
responses:
'200':
description: Return original payload
"""
for key, val in body.items():
for idx, value in enumerate(val):
print('Value %d for "key" %s is %s (%s)' % (idx, key, value, value.__class__.__name__))
return web.json_response(body)
@routes.post("/bug60/array")
async def array(request: web.Request, body) -> web.Response:
"""
---
summary: Mixed type array
tags:
- bug60
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
oneOf:
- type: string
- type: number
example: ["abc", 1, 1.1]
responses:
'200':
description: Return original payload
"""
for idx, value in enumerate(body):
print("Value %d is %s (%s)" % (idx, value, value.__class__.__name__))
return web.json_response(body)
def main():
app = web.Application()
s = SwaggerDocs(app, swagger_ui_settings=SwaggerUiSettings(path="/"))
s.add_routes(routes)
web.run_app(app)
if __name__ == "__main__":
main()
Console will print:
Value 0 is abc (str)
Value 1 is 1.0 (float)
Value 2 is 1.1 (float)
Second value is expected to be an integer
from aiohttp-swagger3.
If you add - type: integer
to the allowed type, it ends up with:
400: {"body": {"1": "fail to validate oneOf"}}
from aiohttp-swagger3.
OpenAPI has two numeric types, number and integer, where number includes both integer and floating-point numbers.
https://swagger.io/docs/specification/data-models/data-types/#numbers
numbers include integers, so both checks are succeeded and this is not allowed by oneOf
.
oneOf – validates the value against exactly one of the subschemas
Your case is weird, indeed, but the library logic is correct.
Why don't you use anyOf
instead?
Value 0 is abc (str)
Value 1 is 1 (int)
Value 2 is 1.1 (float)
from aiohttp-swagger3.
The API is acting as REST bridge to another protocol, so I don't care about what the payload actually contents, it's up to the next protocol to deal with it (but it needs to receive properly typed items).
Thanks for your suggestion, I'll give anyOf a try
from aiohttp-swagger3.
Related Issues (20)
- Add prefix support for nested applications
- Python 3.11 - Swagger._handle_swagger_method_call() missing 1 required positional argument: 'route'
- Type is not required, but validators.py thinks it should be HOT 1
- 3.1.x openapi support? HOT 1
- bump to aiohttp 3.9.0+ HOT 1
- How to handle route prefix rewrite? HOT 2
- Re-use validation schema for marshalling ? HOT 4
- fix usage with with aiohttp 3.7 HOT 3
- Inject custom YAML to route ? HOT 5
- Combination of $ref with nullable: true: validation fails HOT 2
- readOnly: true forbid re-use of ref in valid context HOT 5
- Incomplete discriminator support ? HOT 4
- Can't define parameters in Link Object HOT 7
- Python 3.9 support ? HOT 3
- Allow PyYAML >=5.4 to be installed HOT 2
- IndexError when disabling security
- Correct openapi fails validation HOT 3
- pytest DeprecationWarning: Bare functions are deprecated, use async ones HOT 1
- Definitions with requestBody / required: false can not be used HOT 4
- Adding licence info to spec isn't being recognized by the SwaggerDocs class. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiohttp-swagger3.