-
-
Notifications
You must be signed in to change notification settings - Fork 178
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
Always use openapi-spec-validator in utils.validate_spec #299
Conversation
ddf9c05
to
0cc2746
Compare
Looks like maybe flex is more reliable so we could keep it for 2.0. (See #282). Concerning flex:
|
Why not let the user choose by making it a def validate_spec(spec, backend=None):
if backend is None:
if spec.openapi_version.major < 3:
backend = 'flex'
else:
backend = 'openapi-spec-validation'
prance.BaseParser(
spec_string=json.dumps(spec.to_dict()),
backend=backend,
) |
Fine by me. @lafrech Would you like to change this PR? |
I've been applying the change to my branch, and now that I'm considering what to change in setup.py and docs, I'm realizing the whole point of If the user can use his backend of choice, then he must install it manually and we should not force installation of an unused backend, then def validate_spec(spec, backend=None):
"""Validate the output of an :class:`APISpec` object against the
OpenAPI specification.
Note: Requires installing apispec with the ``[validation]`` extras.
::
pip install 'apispec[validation]'
:param str backend: prance backend to use # <--- prance specific parameter
:raise: apispec.exceptions.OpenAPIError if validation fails.
"""
if backend is None:
if spec.openapi_version.major < 3:
backend = 'flex'
else:
backend = 'openapi-spec-validation'
try:
import prance
except ImportError as error: # re-raise with a more verbose message
exc_class = type(error)
raise exc_class(
'validate_spec requires prance to be installed. '
'You can install all validation requirements using:\n'
" pip install 'apispec[validation]'",
)
try:
prance.BaseParser(
spec_string=json.dumps(spec.to_dict()),
backend='openapi-spec-validator',
)
except prance.ValidationError as err:
raise exceptions.OpenAPIError(*err.args)
else:
return True Maybe the details of validation (discrepancies between validators) are too important to the user to be hidden in apispec. We could remove the whole feature and add a note in the docs showing how to proceed with prance. Kinda sucks, but oh well... |
Both good points. Adding the prance-specific parameter certainly makes the abstraction leak.
Perhaps. I don't feel strongly either way, but I hesitate to remove it because the current implementation should be fine for most users. If it works for 80% of users, should we really remove it for the 20%? Those few users can still use prance directly if they want. So maybe for now, we close this PR, continue to help @lbeaufort resolve her issue in #282, and open a new issue to discuss removing |
Yes. |
Closes #282