-
Notifications
You must be signed in to change notification settings - Fork 18
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
OpenAPI 3.1.0 lint and completion rules for openapi
object
#2106
Conversation
@char0n fyi, in keeping with producing smaller PRs, I'm thinking of limiting this PR as-is (subject to review feedback), while moving the following item to a separate smaller PR:
|
packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--type.ts
Outdated
Show resolved
Hide resolved
You should finish coverying
How did you come up with this requirement? I don't see it in the specification document. Can you explain please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're missing bunch of field validations. Please have a look at https://github.com/swagger-api/apidom/tree/09248f68c65129425a8224bcda450399c91ec25d/packages/apidom-ls/src/config/openapi/openapi3_0/lint.
openapi3_0
and openapi3_1
are distinct elements. This means they don't share any logic. These two elements are the exception the the rules productions. Other elements only need rules for that divergees between spec versions, but these two needs they own (duplicated) rules.
release notes in 3.1.0-rc0
|
Ok thanks for explanation. Will fix |
de77726
to
f758bca
Compare
resolved |
What we can theoretically do to save some code is to import the lint rules from |
Right. The single source of truth for us is the specification - its markdown version. I found this rule specified by the JSON Schemas. Whenever there is a conflict between the specification and schemas, the specification always takes precedence. This has been already stipulated in multiple discussions like this one: OAI/OpenAPI-Specification#2666 Anyway I found this information within the specification itself here: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-document, which means we're fine and should implement this lint rule. In order to implement it you don't necessarily need a new linting function. You can create 3 linting rules with conditional logic as demonstrated here: apidom/packages/apidom-ls/src/config/asyncapi/bindings/ibmmq/channel-binding/lint/topic--required.ts Line 12 in 1591cfe
The logic of the condition for each of these rules will be: if other two fields don't exist, this field must be defined. This makes it possible to create overall linting logic as aggregate of 3 separate linting rules. |
up to you. For me the size of this is still comfortable to review as we only deal with |
I haven't been able to get this condition example to apply to the openapi object. Latest commit in c599710, with commented out condition. At the moment, each of In the meantime, I think all other requested changes have been made. Thanks. |
Did some experimenting and the easiest solution I could come up with seems to be introduction new rule called import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
const requiredFieldsLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_1_OPEN_API_REQUIRED_FIELDS,
source: 'apilint',
message: 'OpenAPI Object must contain one the following fields: paths, components, webhooks',
severity: 1,
linterFunction: 'hasRequiredField',
linterParams: ['paths'],
marker: 'key',
conditions: [
{
targets: [{ path: 'root' }],
function: 'missingFields',
params: [['paths', 'components', 'webhooks']],
},
],
data: {
quickFix: [
{
message: "add 'paths' section",
action: 'addChild',
snippetYaml: 'paths: \n \n',
snippetJson: '"paths": {\n \n },\n',
},
],
},
};
export default requiredFieldsLint; |
This solution works for me. Implemented in 6d2d7c3 |
…openapi-lint-completion
packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts
Outdated
Show resolved
Hide resolved
packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts
Outdated
Show resolved
Hide resolved
packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts
Outdated
Show resolved
Hide resolved
packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're almost done here. Added couple of requests for changes.
packages/apidom-ls/src/config/openapi/openapi3_1/lint/webhooks--type.ts
Outdated
Show resolved
Hide resolved
…er-api/apidom into feat/oas31-openapi-lint-completion
@char0n FYI updated tests in this commit 5e4ad6d, applies to adding the Separately, more test fixes incoming for @frantuma FYI, this change alleviates the need to be knowledgeable (deepEqual) about specific completion items. We could build out more fixtures and test scenarios if it's really needed, or if there is more that you had originally intended for
|
This change looks strange. Why would you change the the assertion? The assertions must stay the same; in order to fix the tests that stopped passing by introducing new rules, you have to add the expected structures into fixtures. And then the assertion will pass. If you want help, I can issue a PR with the test fixes.
ApiDOM originally supported only OpenAPI 3.1 in very limited way. Effort of supporting OpenAPI 3.0.x has started during last month and is being finalized now by providing rules in apidom-ls packages. Tests that are failing for you were originally created by @frantuma for OpenAPI 3.1.0. There is also a problem with the tests in apidom-ls: when they fail - they will hang instead of failing with error code of 1. That manifests in CI as never ending test job. When we have more time, I plan to look into those tests and transform them into snapshot based tests with auto generating capability, which will make much easier to fix them in future. OpenAPI 3.0.x support in apidom-ls has very limited test coverage, as that is something I want to address when we have snapshot testing in place and all the old tests reorganized. |
* also revert 5e4ad6d to favor passing bulk CI tests * running individual openapi-json and openapi-yaml tests will now fail (again) * some cleanup of duplicate/unused code
@char0n Tests updated and are now passing on GA CI. One caveat... the latest commit eb13b1a includes a change that reverts the change from 5e4ad6d. My local observation is that |
done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments/questions regarding tests. The rest of the code looks LEGIT.
…openapi-lint-completion
Description
Full lint and completion rules for OpenAPI 3.1.0
openapi
Object.openapi
object fieldsinfo
should be an object, and is requiredwebhooks
should be a Map ofPathItem
ObjectsjsonSchemaDialect
should be astring
openapi3_0
rules but withopenapi3_1
codes. Per commentThis means they don't share any logic.
openapi
contains at least oneOfpaths
,components
,webhooks
also,
OPENAPI3_1_INFO
andOPENAPI3_1_INFO_FIELD_SUMMARY_TYPE
to be consistent with equivalentOPENAPI_3_1_INFO_XXX
codescontact
object instead ofcontext
objectMotivation and Context
Ref: #2062
Ref: #2063
How Has This Been Tested?
local testing.
info
object should display an errorinfo
object should not be a string (should display error)info
object should be an objectinfo
object should inherit requiredtitle
andversion
fields from OpenAPI 3.0.x rules (should display error if not present)webhooks
should not have an error if it contains a PathItem Object (see fixture)webhooks
should display error if not a Map of PathItem Objects, e.g. user write error as stringjsonSchemaDialect
should be astringURIjsonSchemaDialect
should display error if not aURI
, e.g. user write error as objectopenapi3_0
rules now work foropenapi3_1
.components--type
,external-docs--type
,info--type
,paths--type
,security-items-type
,security--type
,servers--items
,servers--type
,tags--items-type
,tags--type
openapi
contains at least oneOfpaths
,components
,webhooks
Screenshots (if appropriate):
Checklist
My PR contains...
src/
is unmodified: changes to documentation, CI, metadata, etc.)package.json
)My changes...
Documentation
Automated tests