-
Notifications
You must be signed in to change notification settings - Fork 20
OpenAPI 3.1.0 lint and completion rules for openapi
object
#2106
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
7ff19e4
fix(ls): oas31 docs formatting
tim-lai 32d2b20
feat(ls): oas31 completion rules for top level objects
tim-lai 9a54801
fix(ls): update comment for info object docs
tim-lai 0af1d23
feat(ls): oas31 top level lint rules
tim-lai e4a91d7
feat(ls): oas31 lint add info object required
tim-lai 766f74a
fix(ls): oas31 lint and completion rules for
tim-lai f758bca
feat(ls): additional oas31 lint rules
tim-lai c599710
feat(ls): oas31 lint required for paths, components, webhooks
tim-lai 6d2d7c3
fix(ls): oas31 lint rules require oneOf paths, components, webhooks
tim-lai 90d9ed2
Merge branch 'main' into feat/oas31-openapi-lint-completion
tim-lai 55dec1f
fix(ls): oas31 docs formatting
tim-lai f4344cb
feat(ls): oas31 completion rules for top level objects
tim-lai 32f8f35
fix(ls): update comment for info object docs
tim-lai 9c8d05f
feat(ls): oas31 top level lint rules
tim-lai e7d02c0
feat(ls): oas31 lint add info object required
tim-lai f48edad
fix(ls): oas31 lint and completion rules for
tim-lai a98ca84
feat(ls): additional oas31 lint rules
tim-lai fe3c144
feat(ls): oas31 lint required for paths, components, webhooks
tim-lai 6f7c148
fix(ls): oas31 lint rules require oneOf paths, components, webhooks
tim-lai 956262f
Merge branch 'feat/oas31-openapi-lint-completion' of github.com:swagg…
tim-lai b029d73
Merge branch 'main' of github.com:swagger-api/apidom into feat/oas31-…
tim-lai 07ec7b1
fix(ls): oas31 lint feedback changes
tim-lai 255e5b9
test(ls): align tests with updated documentation rules
tim-lai 64b8f3d
feat(ls): OpenAPI 3.1.0 lint rules for components object (#2118)
tim-lai 3c54663
fix(ls): oas31 lint feedback changes
tim-lai 5e4ad6d
test(ls): align tests with updated completion rules
tim-lai be4458f
Merge branch 'feat/oas31-openapi-lint-completion' of github.com:swagg…
tim-lai 78f41ba
test(ls): align tests with updated oas31 lint rules
tim-lai eb13b1a
test(ls): apply proper expected values for oas31 assertions
tim-lai 75b2c5c
test(ls): cleanup comments
tim-lai 1e1cf2c
Merge branch 'main' of github.com:swagger-api/apidom into feat/oas31-…
tim-lai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
packages/apidom-ls/src/config/openapi/openapi3_1/completion.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { | ||
ApidomCompletionItem, | ||
CompletionFormat, | ||
CompletionType, | ||
} from '../../../apidom-language-types'; | ||
|
||
const completion: ApidomCompletionItem[] = [ | ||
tim-lai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
label: 'openapi', | ||
insertText: 'openapi', | ||
kind: 14, | ||
format: CompletionFormat.QUOTED, | ||
type: CompletionType.PROPERTY, | ||
insertTextFormat: 2, | ||
documentation: { | ||
kind: 'markdown', | ||
value: | ||
'**REQUIRED**. This string MUST be the [semantic version number](https://semver.org/spec/v2.0.0.html) of the [OpenAPI Specification version](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#versions) that the OpenAPI document uses. The `openapi` field SHOULD be used by tooling specifications and clients to interpret the OpenAPI document. This is *not* related to the API [`info.version`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoVersion) string', | ||
}, | ||
}, | ||
{ | ||
label: 'info', | ||
insertText: 'info', | ||
kind: 14, | ||
format: CompletionFormat.OBJECT, | ||
type: CompletionType.PROPERTY, | ||
insertTextFormat: 2, | ||
documentation: { | ||
kind: 'markdown', | ||
value: | ||
'[Info Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#infoObject)\n\\\n\\\n**REQUIRED**. Provides metadata about the API. The metadata MAY be used by tooling as required.', | ||
}, | ||
}, | ||
{ | ||
label: 'servers', | ||
insertText: 'servers', | ||
kind: 14, | ||
format: CompletionFormat.ARRAY, | ||
type: CompletionType.PROPERTY, | ||
insertTextFormat: 2, | ||
documentation: { | ||
kind: 'markdown', | ||
value: | ||
'[[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject)]\n\\\n\\\nAn array of Server Objects, which provide connectivity information to a target server. If the `servers` property is not provided, or is an empty array, the default value would be a [Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject) with a [url](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverUrl) value of `/`.', | ||
}, | ||
}, | ||
{ | ||
label: 'paths', | ||
insertText: 'paths', | ||
kind: 14, | ||
format: CompletionFormat.OBJECT, | ||
type: CompletionType.PROPERTY, | ||
insertTextFormat: 2, | ||
documentation: { | ||
kind: 'markdown', | ||
value: | ||
'[Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathsObject)\n\\\n\\\n**REQUIRED**. The available paths and operations for the API.', | ||
}, | ||
}, | ||
{ | ||
label: 'components', | ||
insertText: 'components', | ||
kind: 14, | ||
format: CompletionFormat.OBJECT, | ||
type: CompletionType.PROPERTY, | ||
insertTextFormat: 2, | ||
documentation: { | ||
kind: 'markdown', | ||
value: | ||
'[Components Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsObject)\n\\\n\\\nAn element to hold various schemas for the specification.', | ||
}, | ||
}, | ||
{ | ||
label: 'security', | ||
insertText: 'security', | ||
kind: 14, | ||
format: CompletionFormat.ARRAY, | ||
type: CompletionType.PROPERTY, | ||
insertTextFormat: 2, | ||
documentation: { | ||
kind: 'markdown', | ||
value: | ||
'[[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securityRequirementObject)]\n\\\n\\\nA declaration of which security mechanisms can be used across the API. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. Individual operations can override this definition. To make security optional, an empty security requirement (`{}`) can be included in the array.', | ||
}, | ||
}, | ||
{ | ||
label: 'tags', | ||
insertText: 'tags', | ||
kind: 14, | ||
format: CompletionFormat.ARRAY, | ||
type: CompletionType.PROPERTY, | ||
insertTextFormat: 2, | ||
documentation: { | ||
kind: 'markdown', | ||
value: | ||
"[[Tag Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#tagObject)]\n\\\n\\\nA list of tags used by the specification with additional metadata. The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject) must be declared. The tags that are not declared MAY be organized randomly or based on the tools' logic. Each tag name in the list MUST be unique.", | ||
}, | ||
}, | ||
{ | ||
label: 'externalDocs', | ||
insertText: 'externalDocs', | ||
kind: 14, | ||
format: CompletionFormat.OBJECT, | ||
type: CompletionType.PROPERTY, | ||
insertTextFormat: 2, | ||
documentation: { | ||
kind: 'markdown', | ||
value: | ||
'[External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation.', | ||
}, | ||
}, | ||
{ | ||
label: 'webhooks', | ||
insertText: 'webhooks', | ||
kind: 14, | ||
format: CompletionFormat.OBJECT, | ||
type: CompletionType.PROPERTY, | ||
insertTextFormat: 2, | ||
documentation: { | ||
kind: 'markdown', | ||
value: | ||
'Map[`string`, [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)]\n\\\n\\\nThe incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml) is available.', | ||
}, | ||
}, | ||
{ | ||
label: 'jsonSchemaDialect', | ||
insertText: 'jsonSchemaDialect', | ||
kind: 14, | ||
format: CompletionFormat.UNQUOTED, | ||
tim-lai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type: CompletionType.PROPERTY, | ||
insertTextFormat: 2, | ||
documentation: { | ||
kind: 'markdown', | ||
value: | ||
'The default value for the `$schema` keyword within [Schema Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject) contained within this OAS document. This MUST be in the form of a URI.', | ||
}, | ||
}, | ||
]; | ||
|
||
export default completion; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/apidom-ls/src/config/openapi/openapi3_1/lint/allowed-fields.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import ApilintCodes from '../../../codes'; | ||
import { LinterMeta } from '../../../../apidom-language-types'; | ||
|
||
const allowedFieldsLint: LinterMeta = { | ||
code: ApilintCodes.NOT_ALLOWED_FIELDS, | ||
source: 'apilint', | ||
message: 'Object includes not allowed fields', | ||
severity: 1, | ||
linterFunction: 'allowedFields', | ||
linterParams: [ | ||
[ | ||
'openapi', | ||
'info', | ||
'servers', | ||
'paths', | ||
'components', | ||
'security', | ||
'tags', | ||
'externalDocs', | ||
'jsonSchemaDialect', | ||
'webhooks', | ||
], | ||
'x-', | ||
], | ||
marker: 'key', | ||
}; | ||
|
||
export default allowedFieldsLint; |
32 changes: 32 additions & 0 deletions
32
packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--required.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import ApilintCodes from '../../../codes'; | ||
import { LinterMeta } from '../../../../apidom-language-types'; | ||
|
||
const componentsRequiredLint: LinterMeta = { | ||
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_COMPONENTS_REQUIRED, | ||
source: 'apilint', | ||
message: "should always have a 'components' section", | ||
severity: 1, | ||
linterFunction: 'hasRequiredField', | ||
linterParams: ['components'], | ||
marker: 'key', | ||
// conditions: [ | ||
// { | ||
// // todo: fix setup so oas31 consists at least oneOf paths, components, webhooks | ||
// targets: [{ path: 'openApi3_1' }], | ||
// function: 'apilintContainsValue', | ||
// params: ['components'], | ||
// }, | ||
// ], | ||
data: { | ||
quickFix: [ | ||
{ | ||
message: "add 'components' section", | ||
action: 'addChild', | ||
snippetYaml: 'components: \n \n', | ||
snippetJson: '"components": {\n \n },\n', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export default componentsRequiredLint; |
16 changes: 16 additions & 0 deletions
16
packages/apidom-ls/src/config/openapi/openapi3_1/lint/components--type.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import ApilintCodes from '../../../codes'; | ||
import { LinterMeta } from '../../../../apidom-language-types'; | ||
|
||
const componentsTypeLint: LinterMeta = { | ||
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_COMPONENTS_TYPE, | ||
source: 'apilint', | ||
message: 'components must be an object', | ||
severity: 1, | ||
linterFunction: 'apilintElementOrClass', | ||
linterParams: ['components'], | ||
marker: 'value', | ||
target: 'components', | ||
data: {}, | ||
}; | ||
|
||
export default componentsTypeLint; |
16 changes: 16 additions & 0 deletions
16
packages/apidom-ls/src/config/openapi/openapi3_1/lint/external-docs--type.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import ApilintCodes from '../../../codes'; | ||
import { LinterMeta } from '../../../../apidom-language-types'; | ||
|
||
const externalDocsTypeLint: LinterMeta = { | ||
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_EXTERNAL_DOCS_TYPE, | ||
source: 'apilint', | ||
message: 'externalDocs must be an object', | ||
severity: 1, | ||
linterFunction: 'apilintElementOrClass', | ||
linterParams: ['externalDocumentation'], | ||
marker: 'value', | ||
target: 'externalDocs', | ||
data: {}, | ||
}; | ||
|
||
export default externalDocsTypeLint; |
39 changes: 39 additions & 0 deletions
39
packages/apidom-ls/src/config/openapi/openapi3_1/lint/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import allowedFieldsLint from './allowed-fields'; | ||
import componentsTypeLint from './components--type'; | ||
import componentsRequiredLint from './components--required'; | ||
import externalDocsTypeLint from './external-docs--type'; | ||
import infoRequiredLint from './info--required'; | ||
import infoTypeLint from './info--type'; | ||
import jsonSchemaDialectFormatURILint from './jsonSchemaDialect--format-uri'; | ||
import pathsTypeLint from './paths--type'; | ||
import pathsRequiredLint from './paths--required'; | ||
import securityItemsTypeLint from './security--items-type'; | ||
import securityTypeLint from './security--type'; | ||
import serversItemsTypeLint from './servers--items-type'; | ||
import serversTypeLint from './servers--type'; | ||
import tagsItemsTypeLint from './tags--items-type'; | ||
import tagsTypeLint from './tags--type'; | ||
import webhooksLint from './webhooks--type'; | ||
import webhooksRequiredLint from './webhooks--required'; | ||
|
||
const lints = [ | ||
allowedFieldsLint, | ||
componentsTypeLint, | ||
componentsRequiredLint, | ||
externalDocsTypeLint, | ||
infoRequiredLint, | ||
infoTypeLint, | ||
jsonSchemaDialectFormatURILint, | ||
pathsTypeLint, | ||
pathsRequiredLint, | ||
securityItemsTypeLint, | ||
securityTypeLint, | ||
serversItemsTypeLint, | ||
serversTypeLint, | ||
tagsItemsTypeLint, | ||
tagsTypeLint, | ||
webhooksLint, | ||
webhooksRequiredLint, | ||
]; | ||
|
||
export default lints; |
24 changes: 24 additions & 0 deletions
24
packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--required.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import ApilintCodes from '../../../codes'; | ||
import { LinterMeta } from '../../../../apidom-language-types'; | ||
|
||
const infoRequiredLint: LinterMeta = { | ||
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE_REQUIRED, | ||
source: 'apilint', | ||
message: "should always have a 'info' section", | ||
severity: 1, | ||
linterFunction: 'hasRequiredField', | ||
linterParams: ['info'], | ||
marker: 'key', | ||
data: { | ||
quickFix: [ | ||
{ | ||
message: "add 'info' section", | ||
action: 'addChild', | ||
snippetYaml: 'info: \n \n', | ||
snippetJson: '"info": {\n \n },\n', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export default infoRequiredLint; |
16 changes: 16 additions & 0 deletions
16
packages/apidom-ls/src/config/openapi/openapi3_1/lint/info--type.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import ApilintCodes from '../../../codes'; | ||
import { LinterMeta } from '../../../../apidom-language-types'; | ||
|
||
const infoTypeLint: LinterMeta = { | ||
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_INFO_TYPE, | ||
source: 'apilint', | ||
message: 'info must be an object', | ||
severity: 1, | ||
linterFunction: 'apilintElementOrClass', | ||
linterParams: ['info'], | ||
marker: 'value', | ||
target: 'info', | ||
data: {}, | ||
}; | ||
|
||
export default infoTypeLint; |
15 changes: 15 additions & 0 deletions
15
packages/apidom-ls/src/config/openapi/openapi3_1/lint/jsonSchemaDialect--format-uri.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import ApilintCodes from '../../../codes'; | ||
tim-lai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { LinterMeta } from '../../../../apidom-language-types'; | ||
|
||
const jsonSchemaDialectFormatURILint: LinterMeta = { | ||
code: ApilintCodes.OPENAPI3_1_OPEN_API_FIELD_JSON_SCHEMA_FORMAT_URI, | ||
tim-lai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
source: 'apilint', | ||
message: "'jsonSchemaDialect' value MUST be in the form of a URI.", | ||
severity: 1, | ||
linterFunction: 'apilintValidURI', | ||
marker: 'value', | ||
target: 'jsonSchemaDialect', | ||
data: {}, | ||
}; | ||
|
||
export default jsonSchemaDialectFormatURILint; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.