Skip to content

OpenAPI 3.0.x language server rules #2091

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 8 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/apidom-ls/src/config/asyncapi/tag/lint/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import allowedFieldsLint from './allowed-fields';
import nameTypeLint from './name--type';
import nameRequiredLint from './name--required';
import descriptionTypeLint from './description--type';
import externalDocsTypeLint from './external-docs--type';

const lints = [allowedFieldsLint, nameTypeLint, descriptionTypeLint, externalDocsTypeLint];
const lints = [
allowedFieldsLint,
nameTypeLint,
nameRequiredLint,
descriptionTypeLint,
externalDocsTypeLint,
];

export default lints;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { LinterMeta } from '../../../../apidom-language-types';
const nameTypeLint: LinterMeta = {
code: ApilintCodes.ASYNCAPI2_TAG_FIELD_NAME_TYPE,
source: 'apilint',
message: "'description' value must be a string",
message: "'name' value must be a string",
severity: 1,
linterFunction: 'apilintType',
linterParams: ['string'],
Expand Down
13 changes: 13 additions & 0 deletions packages/apidom-ls/src/config/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,19 @@ enum ApilintCodes {
OPENAPI3_O_SERVER_VARIABLE_FIELD_DEFAULT_REQUIRED,
OPENAPI3_O_SERVER_VARIABLE_FIELD_DESCRIPTION_TYPE = 5080300,

OPENAPI_3_0_PATHS = 5090000,
OPENAPI_3_0_PATHS_KEYS_PATTERN,
OPENAPI_3_0_PATHS_VALUES_PATTERN,

OPENAPI_3_0_SECURITY_REQUIREMENT = 5100000,
OPENAPI_3_0_SECURITY_REQUIREMENT_KEYS_DEFINED,

OPENAPI_3_0_TAG = 5110000,
OPENAPI_3_0_TAG_FIELD_NAME_TYPE = 5110100,
OPENAPI_3_0_TAG_FIELD_NAME_REQUIRED,
OPENAPI_3_0_TAG_FIELD_DESCRIPTION_TYPE = 5110200,
OPENAPI_3_0_TAG_FIELD_EXTERNAL_DOCS_TYPE = 5110300,

OPENAPI3_1 = 7000000,

OPENAPI3_1_OPENAPI_VALUE_PATTERN_3_1_0 = 7000100,
Expand Down
9 changes: 9 additions & 0 deletions packages/apidom-ls/src/config/openapi/paths/documentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
const documentation = [
{
docs: '#### [Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathsObject)\n\nHolds the relative paths to the individual endpoints and their operations.\nThe path is appended to the URL from the [`Server Object`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject) in order to construct the full URL. The Paths MAY be empty, due to [ACL constraints](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#securityFiltering).\n\n##### Patterned Fields\n\nField Pattern | Type | Description\n---|:---:|---\n/{path} | [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathItemObject) | A relative path to an individual endpoint. The field name MUST begin with a forward slash (`/`). The path is **appended** (no relative URL resolution) to the expanded URL from the [`Server Object`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject)\'s `url` field in order to construct the full URL. [Path templating](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathTemplating) is allowed. When matching URLs, concrete (non-templated) paths would be matched before their templated counterparts. Templated paths with the same hierarchy but different templated names MUST NOT exist as they are identical. In case of ambiguous matching, it\'s up to the tooling to decide which one to use.\n\nThis object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions).\n\n##### Path Templating Matching\n\nAssuming the following paths, the concrete definition, `/pets/mine`, will be matched first if used:\n\n```\n /pets/{petId}\n /pets/mine\n```\n\nThe following paths are considered identical and invalid:\n\n```\n /pets/{petId}\n /pets/{name}\n```\n\nThe following may lead to ambiguous resolution:\n\n```\n /{entity}/me\n /books/{id}\n```\n\n##### Paths Object Example\n\n\n\\\nJSON\n```json\n{\n "/pets": {\n "get": {\n "description": "Returns all pets from the system that the user has access to",\n "responses": {\n "200": {\n "description": "A list of pets.",\n "content": {\n "application/json": {\n "schema": {\n "type": "array",\n "items": {\n "$ref": "#/components/schemas/pet"\n }\n }\n }\n }\n }\n }\n }\n }\n}\n```\n\n\n\\\nYAML\n```yaml\n/pets:\n get:\n description: Returns all pets from the system that the user has access to\n responses:\n \'200\':\n description: A list of pets.\n content:\n application/json:\n schema:\n type: array\n items:\n $ref: \'#/components/schemas/pet\'\n```',
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
},
{
docs: '#### [Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathsObject)\n\nHolds the relative paths to the individual endpoints and their operations. The path is appended to the URL from the [`Server Object`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject) in order to construct the full URL. The Paths MAY be empty, due to [Access Control List (ACL) constraints](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securityFiltering).\n\n##### Patterned Fields\n\nField Pattern | Type | Description\n---|:---:|---\n/{path} | [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | A relative path to an individual endpoint. The field name MUST begin with a forward slash (`/`). The path is **appended** (no relative URL resolution) to the expanded URL from the [Server Object\'s](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject) `url` field in order to construct the full URL. [Path templating](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathTemplating) is allowed. When matching URLs, concrete(non-templated) paths would be matched before their templated counterparts. Templated paths with the same hierarchy but different templated names MUST NOT exist as they are identical.In case of ambiguous matching, it is up to the tooling to decide which one to use.\n\n\\\nThis object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specificationExtensions).\n\n##### Path Templating Matching\n\n\n\\\nAssuming the following paths, the concrete definition, `/pets/mine`, will be matched first if used:\n\n\n```yaml\n /pets/{petId}\n /pets/mine\n```\n\n\nThe following paths are considered identical and invalid:\n\n\n```yaml\n /pets/{petId}\n /pets/{name}\n```\n\n\nThe following may lead to ambiguous resolution:\n\n```yaml\n /{entity}/me\n /books/{id}\n```\n\n##### Paths Object Example\n\n\n\\\nJSON\n```json\n{\n "/pets": {\n "get": {\n "description": "Returns all pets from the system that the user has access to",\n "responses": {\n "200": {\n "description": "A list of pets.",\n "content": {\n "application/json": {\n "schema": {\n "type": "array",\n "items": {\n "$ref": "#/components/schemas/pet"\n }\n }\n }\n }\n }\n }\n }\n }\n}\n```\n\n\n\\\nYAML\n```yaml\n /pets:\n get:\n description: Returns all pets from the system that the user has access to\n responses:\n \'200\':\n description: A list of pets.\n content:\n application\\/ json:\n schema:\n type: array\n items:\n $ref: \'#/components/schemas/pet\'\n```\n',
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
Expand Down
6 changes: 6 additions & 0 deletions packages/apidom-ls/src/config/openapi/paths/lint/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import keysPatternLint from './keys--pattern';
import valuesTypeLint from './values--type';

const lints = [valuesTypeLint, keysPatternLint];

export default lints;
15 changes: 15 additions & 0 deletions packages/apidom-ls/src/config/openapi/paths/lint/keys--pattern.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const keysPatternLint: LinterMeta = {
code: ApilintCodes.OPENAPI_3_0_PATHS_KEYS_PATTERN,
source: 'apilint',
message: 'Paths Object keys must match the regular expression: `^/`',
severity: 1,
linterFunction: 'apilintKeysRegex',
linterParams: ['^/'],
marker: 'key',
data: {},
};

export default keysPatternLint;
15 changes: 15 additions & 0 deletions packages/apidom-ls/src/config/openapi/paths/lint/values--type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const valuesTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI_3_0_PATHS_VALUES_PATTERN,
source: 'apilint',
message: 'Paths Object values must be of Path Item Object shape',
severity: 1,
linterFunction: 'apilintChildrenOfElementsOrClasses',
linterParams: [['pathItem']],
marker: 'key',
data: {},
};

export default valuesTypeLint;
2 changes: 2 additions & 0 deletions packages/apidom-ls/src/config/openapi/paths/meta.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import lint from './lint';
import documentation from './documentation';
import { FormatMeta } from '../../../apidom-language-types';

const meta: FormatMeta = {
lint,
documentation,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
const documentation = [
{
docs: '#### [Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#securityRequirementObject)\n\nLists the required security schemes to execute this operation.\nThe name used for each property MUST correspond to a security scheme declared in the [Security Schemes](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsSecuritySchemes) under the [Components Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsObject).\n\nSecurity Requirement Objects that contain multiple schemes require that all schemes MUST be satisfied for a request to be authorized.\nThis enables support for scenarios where multiple query parameters or HTTP headers are required to convey security information.\n\nWhen a list of Security Requirement Objects is defined on the [OpenAPI Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oasObject) or [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject), only one of the Security Requirement Objects in the list needs to be satisfied to authorize the request.\n\n##### Patterned Fields\n\nField Pattern | Type | Description\n---|:---:|---\n{name} | [`string`] | Each name MUST correspond to a security scheme which is declared in the [Security Schemes](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsSecuritySchemes) under the [Components Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsObject). If the security scheme is of type `"oauth2"` or `"openIdConnect"`, then the value is a list of scope names required for the execution, and the list MAY be empty if authorization does not require a specified scope. For other security scheme types, the array MUST be empty.\n\n##### Security Requirement Object Examples\n\n###### Non-OAuth2 Security Requirement\n\n\n\\\nJSON\n```json\n{\n "api_key": []\n}\n```\n\n\n\\\nYAML\n```yaml\napi_key: []\n```\n\n###### OAuth2 Security Requirement\n\n```json\n{\n "petstore_auth": [\n "write:pets",\n "read:pets"\n ]\n}\n```\n\n```yaml\npetstore_auth:\n- write:pets\n- read:pets\n```\n\n###### Optional OAuth2 Security\n\nOptional OAuth2 security as would be defined in an [OpenAPI Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#openapi-object) or an [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object):\n\n```json\n{\n "security": [\n {},\n {\n "petstore_auth": [\n "write:pets",\n "read:pets"\n ]\n }\n ]\n}\n```\n\n```yaml\nsecurity:\n - {}\n - petstore_auth:\n - write:pets\n - read:pets\n```',
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
},
{
docs: '#### [Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securityRequirementObject)\n\nLists the required security schemes to execute this operation. The name used for each property MUST correspond to a security scheme declared in the Security Schemes under the [Components Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsObject).\n\n\\\nSecurity Requirement Objects that contain multiple schemes require that all schemes MUST be satisfied for a request to be authorized. This enables support for scenarios where multiple query parameters or HTTP headers are required to convey security information.\n\n\\\nWhen a list of Security Requirement Objects is defined on the [OpenAPI Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oasObject) or [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject), only one of the Security Requirement Objects in the list needs to be satisfied to authorize the request.\n\n##### Patterned Fields\n\nField Pattern | Type | Description\n---|:---:|---\n{name} | [`string`] | Each name MUST correspond to a security scheme which is declared in the Security Schemes under the [Components Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsObject). If the security scheme is of type `"oauth2"` or `"openIdConnect"`, then the value is a list of scope names required for the execution, and the list MAY be empty if authorization does not require a specified scope. For other security scheme types, the array MAY contain a list of role names which are required for the execution, but are not otherwise defined or exchanged in-band.\n\n##### Security Requirement Object Examples\n\n##### Non-OAuth2 Security Requirement\nJSON\n```json\n{\n "api_key": []\n}\n```\n\n\\\nYAML\n```yaml\napi_key: []\n```\n##### OAuth2 Security Requirement\nJSON\n```json\n{\n "petstore_auth": [\n "write:pets",\n "read:pets"\n ]\n}\n```\n\n\\\nYAML\n```yaml\npetstore_auth:\n- write:pets\n- read:pets\n```\n##### Optional OAuth2 Security\nOptional OAuth2 security as would be defined in an OpenAPI Object or an Operation Object:\n\n\\\nJSON\n```json\n{\n "security": [\n {},\n {\n "petstore_auth": [\n "write:pets",\n "read:pets"\n ]\n }\n ]\n}\n```\n\n\\\nYAML\n```yaml\nsecurity:\n - {}\n - petstore_auth:\n - write:pets\n - read:pets\n```\n',
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import keysDefinedLint from './keys--defined';

const lints = [keysDefinedLint];

export default lints;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

const keysDefinedLint: LinterMeta = {
code: ApilintCodes.OPENAPI_3_0_SECURITY_REQUIREMENT_KEYS_DEFINED,
source: 'apilint',
message: 'security keys must be included in defined security schemes',
severity: 1,
linterFunction: 'apilintKeysIncluded',
linterParams: ['root.components.securitySchemes'],
marker: 'key',
data: {},
};

export default keysDefinedLint;
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import lint from './lint';
import documentation from './documentation';
import { FormatMeta } from '../../../apidom-language-types';

const meta: FormatMeta = {
lint,
documentation,
};

Expand Down
54 changes: 54 additions & 0 deletions packages/apidom-ls/src/config/openapi/tag/completion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
ApidomCompletionItem,
CompletionFormat,
CompletionType,
} from '../../../apidom-language-types';

const completion: ApidomCompletionItem[] = [
{
label: 'name',
insertText: 'name',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value: '**REQUIRED**. The name of the tag.',
},
},
{
label: 'description',
insertText: 'description',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'A description for the tag. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.',
},
},
{
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.0.3.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation for this tag.',
},
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
},
];

export default completion;
Loading