Skip to content
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

feat(apidom-ls): create schema rule for missing core keywords #3554

Closed
wants to merge 2 commits into from

Conversation

frantuma
Copy link
Member

Refs #3549

Also fixes rules for JSON Schema type checks considering also boolean schemas

@frantuma frantuma requested a review from char0n December 18, 2023 18:17
@frantuma frantuma changed the title feat(apidom-ls): fix schema rules for boolean feat(apidom-ls): create schema rule for missing core keywords Dec 19, 2023
Copy link
Member

@char0n char0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! We need to sort some cross specs details before we go for a merge.

...AsyncAPI250,
...AsyncAPI260,
];
export const AsyncAPI = [...AsyncAPI2];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In light of 1e15838 can we remove this?

The reasoning is that we'd rather add target spec explicitly to what applies, then automatically activating existing rules for example for AsyncAPI 3.0 (when we're adding support for it). This total group of all AsyncAPI spec targets has no practical usage and causes more issues than it solves.

@@ -9,7 +9,7 @@ const additionalItemsTypeLint: LinterMeta = {
message: 'additionalItems must be a schema',
severity: DiagnosticSeverity.Error,
linterFunction: 'apilintElementOrClass',
linterParams: ['schema'],
linterParams: ['schema', 'boolean'],
Copy link
Member

@char0n char0n Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot really do that. OpenAPI 2.0/3.0.x use JSON Schema Draft 4/5 which doesn't support Boolean JSON Schema. Boolean JSON Schemas are supported since JSON Schema Draft 6 and applies to: AsyncAPI 2.x and OpenAPI 3.1.0 only.

We would have to fork this rule and use targetSpec to apply it to appropriate specification and their versions.

Important

This applies to all modified rules in /common/schema/

@@ -0,0 +1,91 @@
import { DiagnosticSeverity } from 'vscode-languageserver-types';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make naming consistent with the import symbol:

missing-core-fields-oas-3-0-asyncapi.ts -> missing-core-fields-openapi-3-0-asyncapi-2.ts

import { AsyncAPI } from '../../../asyncapi/target-specs';

// eslint-disable-next-line @typescript-eslint/naming-convention
const missingCoreFieldsOpenAPI3_0AndAsyncAPILint: LinterMeta = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this needs to be forked to multipe rules targeting different specs.

OpenAPI 2.0/3.0.x uses JSON Schema Draft 4/5 with following keywords: https://github.com/swagger-api/apidom/blob/main/packages/apidom-ns-json-schema-draft-4/src/elements/JSONSchema.ts#L35

AsyncAPI 2.x uses JSON Schema Draft 7 which:
Removes keywords: id
Add keywords: $id, contains, propertyNames, examples, $comment, if, then, else, contentEncoding, contentMediaType, media, writeOnly

OpenAPI 3.1 uses JSON Schema Draft 2020-12 with following keywords: https://github.com/swagger-api/apidom/blob/5b504e523c532a31aaf1b133a14ff3b76c126435/packages/apidom-ns-openapi-3-1/src/elements/Schema.ts

@char0n char0n added enhancement New feature or request ApiDOM JSON Schema JSON Schema related work labels Dec 19, 2023
@frantuma
Copy link
Member Author

frantuma commented Jan 8, 2024

replaced by #3640

@frantuma frantuma closed this Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ApiDOM enhancement New feature or request JSON Schema JSON Schema related work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants