Skip to content
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

feat(ls): add rules for OpenAPI 2.0 Responses Definitions Object #3661

Merged
merged 1 commit into from
Jan 12, 2024
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
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 @@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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;
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;
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_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;
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;