Skip to content

Commit 8bb660a

Browse files
authored
feat(ls): add rules for OpenAPI 2.0 Responses Definitions Object (#3661)
Refs #3617
1 parent 12303d9 commit 8bb660a

File tree

6 files changed

+49
-0
lines changed

6 files changed

+49
-0
lines changed

packages/apidom-ls/src/config/codes.ts

+3
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,9 @@ enum ApilintCodes {
769769
OPENAPI2_PARAMETERS_DEFINITIONS = 3150000,
770770
OPENAPI2_PARAMETERS_DEFINITIONS_VALUES_TYPE = 3150100,
771771

772+
OPENAPI2_RESPONSES_DEFINITIONS = 3160000,
773+
OPENAPI2_RESPONSES_DEFINITIONS_VALUES_TYPE = 3160100,
774+
772775
OPENAPI3_0 = 5000000,
773776

774777
OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100,

packages/apidom-ls/src/config/openapi/config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import pathsMeta from './paths/meta';
2929
import requestBodyMeta from './request-body/meta';
3030
import responseMeta from './response/meta';
3131
import responsesMeta from './responses/meta';
32+
import responsesDefinitionsMeta from './responses-definitions/meta';
3233
import securityRequirementMeta from './security-requirement/meta';
3334
import securitySchemeMeta from './security-scheme/meta';
3435
import serverMeta from './server/meta';
@@ -83,6 +84,7 @@ export default {
8384
requestBody: requestBodyMeta,
8485
response: responseMeta,
8586
responses: responsesMeta,
87+
responsesDefinitions: responsesDefinitionsMeta,
8688
securityRequirement: securityRequirementMeta,
8789
securityScheme: securitySchemeMeta,
8890
server: serverMeta,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { OpenAPI2 } from '../target-specs';
2+
3+
const documentation = [
4+
{
5+
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```',
6+
targetSpecs: OpenAPI2,
7+
},
8+
];
9+
10+
export default documentation;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import valuesTypeLint from './values--type';
2+
3+
const lints = [valuesTypeLint];
4+
5+
export default lints;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { DiagnosticSeverity } from 'vscode-languageserver-types';
2+
3+
import ApilintCodes from '../../../codes';
4+
import { LinterMeta } from '../../../../apidom-language-types';
5+
import { OpenAPI2 } from '../../target-specs';
6+
7+
const valuesTypeLint: LinterMeta = {
8+
code: ApilintCodes.OPENAPI2_RESPONSES_DEFINITIONS_VALUES_TYPE,
9+
source: 'apilint',
10+
message: 'Responses Definitions Object values must be of Response Object shape',
11+
severity: DiagnosticSeverity.Error,
12+
linterFunction: 'apilintChildrenOfElementsOrClasses',
13+
linterParams: [['response']],
14+
marker: 'key',
15+
data: {},
16+
targetSpecs: OpenAPI2,
17+
};
18+
19+
export default valuesTypeLint;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import lint from './lint';
2+
import documentation from './documentation';
3+
import { FormatMeta } from '../../../apidom-language-types';
4+
5+
const meta: FormatMeta = {
6+
lint,
7+
documentation,
8+
};
9+
10+
export default meta;

0 commit comments

Comments
 (0)