I try to make a very simple API in flask with swagger, my swagger.yaml file is really not complex and don't use any oneOf or ref, but still get an error about refs and oneOf, I'm not familiar with swagger so I assume that I'm doing something wrong but can't find what.
there is my swagger config:
swagger: "2.0"
info:
title: Swagger Template
description: A Template API
version: "0.1"
paths:
/analyse_coordonates:
get:
operationId: app.core.analyse_coords
summary: Endpoint to receive coordonates and return bivouac zone
parameters:
- in: query
name: e
schema:
type: string
description: E coordonate
- in: query
name: n
schema:
type: string
description: N coordonate
produces:
- text/plain
responses:
200:
description: OK
schema:
type: array
items:
type: integer
there is the error:
[2022-07-20 09:51:40 0000] [8] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/back_end/run.py", line 6, in <module>
APP = flask.create_app()
File "/back_end/app/flask/__init__.py", line 15, in create_app
app.add_api("swagger.yaml", strict_validation=True, validate_responses=True)
File "/usr/local/lib/python3.8/site-packages/connexion/apps/flask_app.py", line 65, in add_api
api = super().add_api(specification, **kwargs)
File "/usr/local/lib/python3.8/site-packages/connexion/apps/abstract.py", line 149, in add_api
api = self.api_cls(specification,
File "/usr/local/lib/python3.8/site-packages/connexion/apis/abstract.py", line 81, in __init__
self.specification = Specification.load(specification, arguments=arguments)
File "/usr/local/lib/python3.8/site-packages/connexion/spec.py", line 152, in load
return cls.from_file(spec, arguments=arguments)
File "/usr/local/lib/python3.8/site-packages/connexion/spec.py", line 106, in from_file
return cls.from_dict(spec)
File "/usr/local/lib/python3.8/site-packages/connexion/spec.py", line 143, in from_dict
return Swagger2Specification(spec)
File "/usr/local/lib/python3.8/site-packages/connexion/spec.py", line 37, in __init__
self._validate_spec(raw_spec)
File "/usr/local/lib/python3.8/site-packages/connexion/spec.py", line 215, in _validate_spec
raise InvalidSpecification.create_from(e)
connexion.exceptions.InvalidSpecification: {'in': 'query', 'name': 'e', 'schema': {'type': 'string'}, 'description': 'E coordonate'} is not valid under any of the given schemas
Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^/']['properties']['get']['properties']['parameters']['items']:
{'oneOf': [{'$ref': '#/definitions/parameter'},
{'$ref': '#/definitions/jsonReference'}]}
On instance['paths']['/analyse_coordonates']['get']['parameters'][0]:
{'description': 'E coordonate',
'in': 'query',
'name': 'e',
'schema': {'type': 'string'}}
[2022-07-20 09:51:40 0000] [8] [INFO] Worker exiting (pid: 8)
Thanks.
CodePudding user response:
It looks like problem is here:
- in: query
name: e
schema:
type: string
description: E coordonate
this way of specifying type of param is allowed in OpenAPI 3, but not in Swagger (OpenAPI 2)
In Swagger, the schema: type:
form is only allowed for "body" params, not querystring.
See:
- https://swagger.io/docs/specification/describing-parameters/ (OpenAPI 3)
- https://swagger.io/docs/specification/2-0/describing-parameters/ (Swagger)
To fix it just change your schema to:
swagger: "2.0"
info:
title: Swagger Template
description: A Template API
version: "0.1"
paths:
/analyse_coordonates:
get:
operationId: app.core.analyse_coords
summary: Endpoint to receive coordonates and return bivouac zone
parameters:
- in: query
name: e
type: string
description: E coordonate
- in: query
name: n
type: string
description: N coordonate
produces:
- text/plain
responses:
200:
description: OK
schema:
type: array
items:
type: integer