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 Paths Object #3553

Merged
merged 1 commit into from
Dec 18, 2023
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 @@ -668,6 +668,9 @@ enum ApilintCodes {
OPENAPI2_LICENSE_FIELD_NAME_REQUIRED = 3050200,
OPENAPI2_LICENSE_FIELD_URL_FORMAT_URI = 3050300,

OPENAPI2_PATHS = 3060000,
OPENAPI2_PATHS_VALUES_TYPE = 3060100,

OPENAPI3_0 = 5000000,

OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100,
Expand Down
6 changes: 5 additions & 1 deletion packages/apidom-ls/src/config/openapi/paths/documentation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { OpenAPI30, OpenAPI31 } from '../target-specs';
import { OpenAPI2, OpenAPI30, OpenAPI31 } from '../target-specs';

const documentation = [
{
docs: '#### [Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#paths-object)\n\nHolds the relative paths to the individual endpoints. The path is appended to the [`basePath`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerBasePath) in order to construct the full URL.\nThe Paths may be empty, due to [ACL constraints](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#securityFiltering).\n\n##### Patterned Fields\n\nField Pattern | Type | Description\n---|:---:|---\n/{path} | [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#pathItemObject) | A relative path to an individual endpoint. The field name MUST begin with a slash. The path is appended to the [`basePath`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerBasePath) in order to construct the full URL. [Path templating](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#pathTemplating) is allowed.\n^x- | Any | Allows extensions to the Swagger Schema. The field name MUST begin with `x-`, for example, `x-internal-id`. The value can be `null`, a primitive, an array or an object. See [Vendor Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#vendorExtensions) for further details.\n\n##### Paths Object Example\n\n```js\n{\n "/pets": {\n "get": {\n "description": "Returns all pets from the system that the user has access to",\n "produces": [\n "application/json"\n ],\n "responses": {\n "200": {\n "description": "A list of pets.",\n "schema": {\n "type": "array",\n "items": {\n "$ref": "#/definitions/pet"\n }\n }\n }\n }\n }\n }\n}\n```\n\n\n\\\nYAML\n```yaml\n/pets:\n get:\n description: Returns all pets from the system that the user has access to\n produces:\n - application/json\n responses:\n \'200\':\n description: A list of pets.\n schema:\n type: array\n items:\n $ref: \'#/definitions/pet\'\n```',
targetSpecs: OpenAPI2,
},
{
docs: '#### [Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathsObject)\n\nHolds the relative paths to the individual endpoints and their operations.\nThe path is appended to the URL from the [`Server Object`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject) in order to construct the full URL. The Paths MAY be empty, due to [ACL constraints](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#securityFiltering).\n\n##### Patterned Fields\n\nField Pattern | Type | Description\n---|:---:|---\n/{path} | [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathItemObject) | A relative path to an individual endpoint. The field name MUST begin with a forward slash (`/`). The path is **appended** (no relative URL resolution) to the expanded URL from the [`Server Object`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject)\'s `url` field in order to construct the full URL. [Path templating](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathTemplating) is allowed. When matching URLs, concrete (non-templated) paths would be matched before their templated counterparts. Templated paths with the same hierarchy but different templated names MUST NOT exist as they are identical. In case of ambiguous matching, it\'s up to the tooling to decide which one to use.\n\nThis object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions).\n\n##### Path Templating Matching\n\nAssuming the following paths, the concrete definition, `/pets/mine`, will be matched first if used:\n\n```\n /pets/{petId}\n /pets/mine\n```\n\nThe following paths are considered identical and invalid:\n\n```\n /pets/{petId}\n /pets/{name}\n```\n\nThe following may lead to ambiguous resolution:\n\n```\n /{entity}/me\n /books/{id}\n```\n\n##### Paths Object Example\n\n\n\\\nJSON\n```json\n{\n "/pets": {\n "get": {\n "description": "Returns all pets from the system that the user has access to",\n "responses": {\n "200": {\n "description": "A list of pets.",\n "content": {\n "application/json": {\n "schema": {\n "type": "array",\n "items": {\n "$ref": "#/components/schemas/pet"\n }\n }\n }\n }\n }\n }\n }\n }\n}\n```\n\n\n\\\nYAML\n```yaml\n/pets:\n get:\n description: Returns all pets from the system that the user has access to\n responses:\n \'200\':\n description: A list of pets.\n content:\n application/json:\n schema:\n type: array\n items:\n $ref: \'#/components/schemas/pet\'\n```',
targetSpecs: OpenAPI30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

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

const valuesTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_PATHS_VALUES_TYPE,
code: ApilintCodes.OPENAPI2_PATHS_VALUES_TYPE,
source: 'apilint',
message: 'Paths Object values must be of Path Item Object shape',
severity: DiagnosticSeverity.Error,
linterFunction: 'apilintChildrenOfElementsOrClasses',
linterParams: [['pathItem']],
marker: 'key',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
};

export default valuesTypeLint;