Skip to content

Commit 049186d

Browse files
authored
feat(ls): add rules for OpenAPI 2.0 Definitions Object (#3658)
Refs #3615
1 parent 04bf77a commit 049186d

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
@@ -763,6 +763,9 @@ enum ApilintCodes {
763763
OPENAPI2_HEADERS = 3130000,
764764
OPENAPI2_HEADERS_VALUES_TYPE = 3130100,
765765

766+
OPENAPI2_DEFINITIONS = 3140000,
767+
OPENAPI2_DEFINITIONS_VALUES_TYPE = 3140100,
768+
766769
OPENAPI3_0 = 5000000,
767770

768771
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
@@ -8,6 +8,7 @@ import componentsMeta from './components/meta';
88
import contactMeta from './contact/meta';
99
import contentMeta from './content/meta';
1010
import discriminatorMeta from './discriminator/meta';
11+
import definitionsMeta from './definitions/meta';
1112
import encodingMeta from './encoding/meta';
1213
import exampleMeta from './example/meta';
1314
import externalDocumentationMeta from './external-documentation/meta';
@@ -60,6 +61,7 @@ export default {
6061
contact: contactMeta,
6162
content: contentMeta,
6263
discriminator: discriminatorMeta,
64+
definitions: definitionsMeta,
6365
encoding: encodingMeta,
6466
example: exampleMeta,
6567
externalDocumentation: externalDocumentationMeta,
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: '#### [Definitions Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#definitions-object)\n\nAn object to hold data types that can be consumed and produced by operations. These data types can be primitives, arrays or models.\n\n##### Patterned Fields\n\nField Pattern | Type | Description\n---|:---:|---\n{name} | [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#schemaObject) | A single definition, mapping a "name" to the schema it defines.\n\n##### Definitions Object Example\n\n```js\n{\n "Category": {\n "type": "object",\n "properties": {\n "id": {\n "type": "integer",\n "format": "int64"\n },\n "name": {\n "type": "string"\n }\n }\n },\n "Tag": {\n "type": "object",\n "properties": {\n "id": {\n "type": "integer",\n "format": "int64"\n },\n "name": {\n "type": "string"\n }\n }\n }\n}\n```\n\n\n\\\nYAML\n```yaml\nCategory:\n type: object\n properties:\n id:\n type: integer\n format: int64\n name:\n type: string\nTag:\n type: object\n properties:\n id:\n type: integer\n format: int64\n name:\n type: string\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_DEFINITIONS_VALUES_TYPE,
9+
source: 'apilint',
10+
message: 'Definitions Object values must be of Schema Object shape',
11+
severity: DiagnosticSeverity.Error,
12+
linterFunction: 'apilintChildrenOfElementsOrClasses',
13+
linterParams: [['schema']],
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)