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 Operation Object #3561

Merged
merged 2 commits into from
Dec 19, 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
20 changes: 19 additions & 1 deletion packages/apidom-ls/src/config/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,24 @@ enum ApilintCodes {
OPENAPI2_PATH_ITEM_FIELD_PARAMETERS_TYPE = 3070900,
OPENAPI2_PATH_ITEM_FIELD_PARAMETERS_ITEMS_TYPE = 3071000,

OPENAPI2_OPERATION = 3080000,
OPENAPI2_OPERATION_FIELD_TAGS_TYPE = 3080100,
OPENAPI2_OPERATION_FIELD_SUMMARY_TYPE = 3080200,
OPENAPI2_OPERATION_FIELD_DESCRIPTION_TYPE = 3080300,
OPENAPI2_OPERATION_FIELD_EXTERNAL_DOCS_TYPE = 3080400,
OPENAPI2_OPERATION_FIELD_OPERATION_ID_TYPE = 3080500,
OPENAPI2_OPERATION_FIELD_OPERATION_ID_UNIQUE,
OPENAPI2_OPERATION_FIELD_CONSUMES_TYPE = 3080600,
OPENAPI2_OPERATION_FIELD_PRODUCES_TYPE = 3080700,
OPENAPI2_OPERATION_FIELD_PARAMETERS_TYPE = 3080800,
OPENAPI2_OPERATION_FIELD_PARAMETERS_ITEMS_TYPE = 3080900,
OPENAPI2_OPERATION_FIELD_RESPONSES_TYPE = 3081000,
OPENAPI2_OPERATION_FIELD_RESPONSES_REQUIRED,
OPENAPI2_OPERATION_FIELD_SCHEMES_TYPE = 3081100,
OPENAPI2_OPERATION_FIELD_DEPRECATED_TYPE = 3081200,
OPENAPI2_OPERATION_FIELD_SECURITY_TYPE = 3081300,
OPENAPI2_OPERATION_FIELD_SECURITY_ITEMS_TYPE,

OPENAPI3_0 = 5000000,

OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100,
Expand Down Expand Up @@ -801,7 +819,7 @@ enum ApilintCodes {
OPENAPI3_0_OPERATION_FIELD_CALLBACKS_VALUES_TYPE = 5130900,
OPENAPI3_0_OPERATION_FIELD_DEPRECATED_TYPE = 5131000,
OPENAPI3_0_OPERATION_FIELD_SECURITY_TYPE = 5131100,
OPENAPI3_0_OPERATION_FIELD_SECURITY_VALUES_TYPE,
OPENAPI3_0_OPERATION_FIELD_SECURITY_ITEMS_TYPE,
OPENAPI3_0_OPERATION_FIELD_SERVERS_TYPE = 5131200,
OPENAPI3_0_OPERATION_FIELD_SERVERS_ITEMS_TYPE,

Expand Down
160 changes: 157 additions & 3 deletions packages/apidom-ls/src/config/openapi/operation/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
CompletionFormat,
CompletionType,
} from '../../../apidom-language-types';
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';

const completion: ApidomCompletionItem[] = [
{
Expand All @@ -18,7 +18,21 @@ const completion: ApidomCompletionItem[] = [
value:
'[`string`]\n\\\n\\\nA list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.',
},
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
},
{
label: 'summary',
insertText: 'summary',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'A short summary of what the operation does. For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.',
},
targetSpecs: OpenAPI2,
},
{
label: 'summary',
Expand All @@ -33,6 +47,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI3,
},
{
label: 'description',
insertText: 'description',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'A verbose explanation of the operation behavior. [GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) can be used for rich text representation.',
},
targetSpecs: OpenAPI2,
},
{
label: 'description',
insertText: 'description',
Expand All @@ -47,6 +75,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI3,
},
{
label: 'externalDocs',
insertText: 'externalDocs',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[External Documentation](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#externalDocumentationObject)\n\\\n\\\nAdditional external documentation for this operation.',
},
targetSpecs: OpenAPI2,
},
{
label: 'externalDocs',
insertText: 'externalDocs',
Expand Down Expand Up @@ -75,6 +117,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'operationId',
insertText: 'operationId',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'Unique string used to identify the operation. The id MUST be unique among all operations described in the API. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is recommended to follow common programming naming conventions.',
},
targetSpecs: OpenAPI2,
},
{
label: 'operationId',
insertText: 'operationId',
Expand All @@ -89,6 +145,48 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI3,
},
{
label: 'consumes',
insertText: 'consumes',
kind: 14,
format: CompletionFormat.ARRAY,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[`string`]\n\\\n\\\nA list of MIME types the operation can consume. This overrides the [`consumes`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerConsumes) definition at the Swagger Object. An empty value MAY be used to clear the global definition. Value MUST be as described under [Mime Types](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#mimeTypes).',
},
targetSpecs: OpenAPI2,
},
{
label: 'produces',
insertText: 'produces',
kind: 14,
format: CompletionFormat.ARRAY,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[`string`]\n\\\n\\\nA list of MIME types the operation can produce. This overrides the [`produces`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerProduces) definition at the Swagger Object. An empty value MAY be used to clear the global definition. Value MUST be as described under [Mime Types](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#mimeTypes).',
},
targetSpecs: OpenAPI2,
},
{
label: 'parameters',
insertText: 'parameters',
kind: 14,
format: CompletionFormat.ARRAY,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[[Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#referenceObject)]\n\\\n\\\nA list of parameters that are applicable for this operation. If a parameter is already defined at the [Path Item](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#pathItemParameters), the new definition will override it, but can never remove it. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a [name](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterName) and [location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterIn). The list can use the [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#referenceObject) to link to parameters that are defined at the [Swagger Object\'s parameters](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerParameters). There can be one "body" parameter at most.',
},
targetSpecs: OpenAPI2,
},
{
label: 'parameters',
insertText: 'parameters',
Expand Down Expand Up @@ -145,6 +243,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'responses',
insertText: 'responses',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[Responses Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#responsesObject)\n\\\n\\\n**Required.** The list of possible responses as they are returned from executing this operation.',
},
targetSpecs: OpenAPI2,
},
{
label: 'responses',
insertText: 'responses',
Expand Down Expand Up @@ -173,6 +285,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'schemes',
insertText: 'schemes',
kind: 14,
format: CompletionFormat.ARRAY,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[`string`]\n\\\n\\\nThe transfer protocol for the operation. Values MUST be from the list: `"http"`, `"https"`, `"ws"`, `"wss"`. The value overrides the Swagger Object [`schemes`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerSchemes) definition.',
},
targetSpecs: OpenAPI2,
},
{
label: 'callbacks',
insertText: 'callbacks',
Expand Down Expand Up @@ -211,10 +337,38 @@ const completion: ApidomCompletionItem[] = [
documentation: {
kind: 'markdown',
value:
'Declares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is `false`.',
'`boolean`\n\\\n\\\nDeclares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is `false`.',
},
targetSpecs: OpenAPI2,
},
{
label: 'deprecated',
insertText: 'deprecated',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`boolean`\n\\\n\\\nDeclares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is `false`.',
},
targetSpecs: OpenAPI3,
},
{
label: 'security',
insertText: 'security',
kind: 14,
format: CompletionFormat.ARRAY,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[[Security Requirement Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#serverObject)]\n\\\n\\\nA declaration of which security schemes are applied for this operation. The list of values describes alternative security schemes that can be used (that is, there is a logical OR between the security requirements). This definition overrides any declared top-level [`security`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#swaggerSecurity). To remove a top-level security declaration, an empty array can be used.',
},
targetSpecs: OpenAPI2,
},
{
label: 'security',
insertText: 'security',
Expand Down
Loading
Loading