-
Notifications
You must be signed in to change notification settings - Fork 7
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
discussion: Semantic validation checklist #54
Comments
In Apiary and our surrounding tooling and OpenAPI parsers/validators, we are trying to follow the robustness principle in the sense that we lean towards warnings over errors wherever possible. We will not emit an error unless absolutely necessary. For us the semantics for error is that an error would cause our parsers and tooling to exit and not continue. Which is similar to most compilers (clang, gcc etc). For example, in Apiary you cannot save an API Description Document that contains any errors. Thus, unless absolutely necessary (such as the parser cannot continue) we will lean towards a warning. Here's some examples:
We've seen that some of our users who are using OpenAPI 2 generators that end up with semantically invalid specifications which hinder the user's ability to use them in Apiary if we was to outright treat every validation failure as an error. We attempt to be lenient on the user where possible so they can continue to use their API Description Documents in Apiary. We've found cases in the past where users will discover that their (supposedly valid OpenAPI 2.0 document) could be used in other tooling but could not be used in Apiary due to more strict validation which prevented the user using Apiary without altering their (possibly very large and generated) OpenAPI specification. Another reason behind this behaviour in our stack comes from API Blueprint, we attempt to never break compatibility with a document that has previously been parsable in Apiary. Thus we rarely attempt to add validations that cause an error to our existing parsers unless absolutely necessary for new functionality. In OpenAPI that's less likely to be possible as it is a more rigid YAML/JSON structure and new features would be added in new properties of an object. Perhaps an example of this in OpenAPI 3 (at least for us), is that we don't fully support the complete spec in regards to some of the optional properties. I wanted to bring this design point from Apiary for discussion and propose that some of these items above that are specified as type error may not need to be errors. For example:
Parser's can implicitly create a parameter definition in its parse result for the path parameter if missing.
If the reference is in an optional property (or optional tree of properties) in an object it can be discarded. |
The solution to this problem is not to be more lenient but to encourage tools to respect the rules of the specification. If tooling wants to implement "fix my description" mechanisms they are encouraged to do so. However I would absolutely not recommend that tools attempt to implicitly correct descriptions nor ignore errors. This approach severely hinders learning and leads to poor interoperability. |
I'm going to move this to the OASComply project, as it is addressing this sort of thing. |
I think it would be great to keep a running list of all "semantic validation" (validation not performed via JSON Schema either due to bugs, like 2.0's array
items
, or due to runtime processing) As I rewrite sway for 3.x support, I've come up with the following validations (of the OpenAPI Specification Document itself, not runtime processing likereadOnly
). Below is this list and I would like to verify my findings, fill in any gaps and eventually turn this into it's own documentation file for tooling authors.Semantic Validation
Semantic validation is performing validations on top of the structural validation provided by JSON Schema.
Common
name
+in
combination) parametersoperationId
in
+name
combination) at their definition path (path-scoped parameters can be overridden at the operation-scope)/path/{}
is not valid)/pet/{petId}
and/pet/{petId2}
are equivalently the same and would generate an error)default
property for Schema Objects, or schema-like objects (non-body parameters), must validate against the respective JSON Schemadiscriminator
property for Schema Objects must be arequired
fielditems
property (where available) must be anObject
(Unlike JSON Schema whichArray
or anObject
)required
properties for a Schema Object must be defined in the object or one of its ancestorsOpenAPI 3.0.x
#/components/*
must match the following regex^[a-zA-Z0-9\.\-_]+$
$request.{parameter}
must have matching parameter defined on its parentproperties
entry for theschema
operationId
property of the Link Objects must have a matching Operation ObjectoperationRef
property of Link Objects must point to an Operation ObjectSwagger 2.0
body
parameter and aformData
parameterbody
parametertype
default
property whenrequired
istrue
type
offile
must have aconsumes
ofmultipart/form-data
orapplication/x-www-form-urlencoded
type
ofarray
must have anitems
propertyThe text was updated successfully, but these errors were encountered: