Skip to content

Commit

Permalink
feat(ls): add rules for OpenAPI 2.0 Responses Definitions Object (#3661)
Browse files Browse the repository at this point in the history
Refs #3617
  • Loading branch information
char0n committed Jan 12, 2024
1 parent 12303d9 commit 8bb660a
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
Expand Up @@ -769,6 +769,9 @@ enum ApilintCodes {
OPENAPI2_PARAMETERS_DEFINITIONS = 3150000,
OPENAPI2_PARAMETERS_DEFINITIONS_VALUES_TYPE = 3150100,

OPENAPI2_RESPONSES_DEFINITIONS = 3160000,
OPENAPI2_RESPONSES_DEFINITIONS_VALUES_TYPE = 3160100,

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
Expand Up @@ -29,6 +29,7 @@ import pathsMeta from './paths/meta';
import requestBodyMeta from './request-body/meta';
import responseMeta from './response/meta';
import responsesMeta from './responses/meta';
import responsesDefinitionsMeta from './responses-definitions/meta';
import securityRequirementMeta from './security-requirement/meta';
import securitySchemeMeta from './security-scheme/meta';
import serverMeta from './server/meta';
Expand Down Expand Up @@ -83,6 +84,7 @@ export default {
requestBody: requestBodyMeta,
response: responseMeta,
responses: responsesMeta,
responsesDefinitions: responsesDefinitionsMeta,
securityRequirement: securityRequirementMeta,
securityScheme: securitySchemeMeta,
server: serverMeta,
Expand Down
@@ -0,0 +1,10 @@
import { OpenAPI2 } from '../target-specs';

const documentation = [
{
docs: '#### [Responses Definitions Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#responsesDefinitionsObject)\n\nAn object to hold responses to be reused across operations. Response definitions can be referenced to the ones defined here.\n\nThis does *not* define global operation responses.\n\n##### Patterned Fields\n\nField Pattern | Type | Description\n---|:---:|---\n{name} | [Response Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#responseObject) | A single response definition, mapping a "name" to the response it defines.\n\n##### Responses Definitions Object Example\n\n```js\n{\n "NotFound": {\n "description": "Entity not found."\n },\n "IllegalInput": {\n \t"description": "Illegal input for operation."\n },\n "GeneralError": {\n \t"description": "General Error",\n \t"schema": {\n \t\t"$ref": "#/definitions/GeneralError"\n \t}\n }\n}\n```\n\n\n\\\nYAML\n```yaml\nNotFound:\n description: Entity not found.\nIllegalInput:\n description: Illegal input for operation.\nGeneralError:\n description: General Error\n schema:\n $ref: \'#/definitions/GeneralError\'\n```',
targetSpecs: OpenAPI2,
},
];

export default documentation;
@@ -0,0 +1,5 @@
import valuesTypeLint from './values--type';

const lints = [valuesTypeLint];

export default lints;
@@ -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_RESPONSES_DEFINITIONS_VALUES_TYPE,
source: 'apilint',
message: 'Responses Definitions Object values must be of Response Object shape',
severity: DiagnosticSeverity.Error,
linterFunction: 'apilintChildrenOfElementsOrClasses',
linterParams: [['response']],
marker: 'key',
data: {},
targetSpecs: OpenAPI2,
};

export default valuesTypeLint;
@@ -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 8bb660a

Please sign in to comment.