aiohttp-swagger icon indicating copy to clipboard operation
aiohttp-swagger copied to clipboard

oneOf validation failed for optional property

Open almaslov opened this issue 3 years ago • 0 comments

Hello! I have an issue with describing an optional property with oneOf keyword. Given a code:

from aiohttp import web
from aiohttp_swagger3 import SwaggerDocs, SwaggerUiSettings


async def handler(request: web.Request) -> web.Response:
    """
    Optional route description
    ---
    requestBody:
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              key:
                oneOf:
                  - type: string
                  - type: integer
    responses:
      '200':
        description: Expected response to a valid request
    """
    return web.json_response({})


def main():
    app = web.Application()
    swagger = SwaggerDocs(
        app,
        swagger_ui_settings=SwaggerUiSettings(path="/docs/"),
        version="1.0.0",
    )
    swagger.add_routes([
        web.post("/api/", handler),
    ])
    web.run_app(app, port=8081)

main()

When running curl -d '{}' -H "Content-Type: application/json" http://0.0.0.0:8081/api/ I expected 200 code, since key is not marked as required.But, instead, I get: 400: {"body": {"key": "fail to validate oneOf"}}

almaslov avatar May 31 '21 13:05 almaslov