Skip to content

Commit

Permalink
feat(ls): add rules for OpenAPI 2.0 Headers Object
Browse files Browse the repository at this point in the history
Refs #3608
  • Loading branch information
char0n committed Jan 10, 2024
1 parent 75b567e commit 44d33ca
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/apidom-ls/src/config/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,9 @@ enum ApilintCodes {
OPENAPI2_RESPONSE_FIELD_HEADERS_TYPE = 3120300,
OPENAPI2_RESPONSE_FIELD_EXAMPLES_TYPE = 3120400,

OPENAPI2_HEADERS = 3130000,
OPENAPI2_HEADERS_VALUES_TYPE = 3130100,

OPENAPI3_0 = 5000000,

OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100,
Expand Down
2 changes: 2 additions & 0 deletions packages/apidom-ls/src/config/openapi/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import encodingMeta from './encoding/meta';
import exampleMeta from './example/meta';
import externalDocumentationMeta from './external-documentation/meta';
import headerMeta from './header/meta';
import headersMeta from './headers/meta';
import infoMeta from './info/meta';
import licenseMeta from './license/meta';
import linkMeta from './link/meta';
Expand Down Expand Up @@ -63,6 +64,7 @@ export default {
example: exampleMeta,
externalDocumentation: externalDocumentationMeta,
header: headerMeta,
headers: headersMeta,
info: infoMeta,
license: licenseMeta,
link: linkMeta,
Expand Down
10 changes: 10 additions & 0 deletions packages/apidom-ls/src/config/openapi/headers/documentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { OpenAPI2 } from '../target-specs';

const documentation = [
{
docs: '#### [Headers Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#headers-object)\n\nLists the headers that can be sent as part of a response.\n\n##### Patterned Fields\nField Pattern | Type | Description\n---|:---:|---\n{name} | [Header Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#headerObject) | The name of the property corresponds to the name of the header. The value describes the type of the header.\n\n##### Headers Object Example\n\nRate-limit headers:\n\n```js\n{\n "X-Rate-Limit-Limit": {\n "description": "The number of allowed requests in the current period",\n "type": "integer"\n },\n "X-Rate-Limit-Remaining": {\n "description": "The number of remaining requests in the current period",\n "type": "integer"\n },\n "X-Rate-Limit-Reset": {\n "description": "The number of seconds left in the current period",\n "type": "integer"\n }\n}\n```\n\n\n\\\nYAML\n```yaml\nX-Rate-Limit-Limit:\n description: The number of allowed requests in the current period\n type: integer\nX-Rate-Limit-Remaining:\n description: The number of remaining requests in the current period\n type: integer\nX-Rate-Limit-Reset:\n description: The number of seconds left in the current period\n type: integer\n```',
targetSpecs: OpenAPI2,
},
];

export default documentation;
5 changes: 5 additions & 0 deletions packages/apidom-ls/src/config/openapi/headers/lint/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import valuesTypeLint from './values--type';

const lints = [valuesTypeLint];

export default lints;
19 changes: 19 additions & 0 deletions packages/apidom-ls/src/config/openapi/headers/lint/values--type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI2 } from '../../target-specs';

const valuesTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI2_HEADERS_VALUES_TYPE,
source: 'apilint',
message: 'Headers Object values must be of Header Object shape',
severity: DiagnosticSeverity.Error,
linterFunction: 'apilintChildrenOfElementsOrClasses',
linterParams: [['header']],
marker: 'key',
data: {},
targetSpecs: OpenAPI2,
};

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

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

export default meta;

0 comments on commit 44d33ca

Please sign in to comment.