Skip to content

Commit

Permalink
feat(ls): add completion rules for OpenAPI 2.0 Parameter Object (#3594)
Browse files Browse the repository at this point in the history
Refs #3104
  • Loading branch information
char0n committed Jan 1, 2024
1 parent 423d5dc commit 2f1f4a6
Showing 1 changed file with 325 additions and 4 deletions.
329 changes: 325 additions & 4 deletions packages/apidom-ls/src/config/openapi/parameter/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 @@ -17,7 +17,21 @@ const completion: ApidomCompletionItem[] = [
kind: 'markdown',
value: 'A reference to a Parameter.',
},
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
},
{
label: 'name',
insertText: 'name',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'**Required.** The name of the parameter. Parameter names are *case sensitive*.\n\n* If [`in`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterIn) is `"path"`, the `name` field MUST correspond to the associated path segment from the [path](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#pathsPath) field in the [Paths Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#pathsObject). See [Path Templating](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#pathTemplating) for further information.\n* For all other cases, the `name` corresponds to the parameter name used based on the [`in`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterIn) property.',
},
targetSpecs: OpenAPI2,
},
{
label: 'name',
Expand Down Expand Up @@ -47,6 +61,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'in',
insertText: 'in',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'**Required.** The location of the parameter. Possible values are "query", "header", "path", "formData" or "body".',
},
targetSpecs: OpenAPI2,
},
{
label: 'in',
insertText: 'in',
Expand All @@ -61,6 +89,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 brief description of the parameter. This could contain examples of use. [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 @@ -75,6 +117,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI3,
},
{
label: 'required',
insertText: 'required',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'Determines whether this parameter is mandatory. If the parameter is [`in`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterIn) "path", this property is **required** and its value MUST be `true`. Otherwise, the property MAY be included and its default value is `false`.',
},
targetSpecs: OpenAPI2,
},
{
label: 'required',
insertText: 'required',
Expand Down Expand Up @@ -127,7 +183,21 @@ const completion: ApidomCompletionItem[] = [
documentation: {
kind: 'markdown',
value:
'Sets the ability to pass empty-valued parameters. This is valid only for `query` parameters and allows sending a parameter with an empty value. Default value is `false`. If [`style`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterStyle) is used, and if behavior is `n/a` (cannot be serialized), the value of `allowEmptyValue` SHALL be ignored. Use of this property is NOT RECOMMENDED, as it is likely to be removed in a later revision.',
'`boolean`\n\\\n\\\nSets the ability to pass empty-valued parameters. This is valid only for either `query` or `formData` parameters and allows you to send a parameter with a name only or an empty value. Default value is `false`.',
},
targetSpecs: OpenAPI2,
},
{
label: 'allowEmptyValue',
insertText: 'allowEmptyValue',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`boolean`\n\\\n\\\nSets the ability to pass empty-valued parameters. This is valid only for `query` parameters and allows sending a parameter with an empty value. Default value is `false`. If [`style`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterStyle) is used, and if behavior is `n/a` (cannot be serialized), the value of `allowEmptyValue` SHALL be ignored. Use of this property is NOT RECOMMENDED, as it is likely to be removed in a later revision.',
},
targetSpecs: OpenAPI30,
},
Expand All @@ -141,10 +211,219 @@ const completion: ApidomCompletionItem[] = [
documentation: {
kind: 'markdown',
value:
'Sets the ability to pass empty-valued parameters. This is valid only for `query` parameters and allows sending a parameter with an empty value. Default value is `false`. If [`style`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterStyle) is used, and if behavior is `n/a` (cannot be serialized), the value of `allowEmptyValue` SHALL be ignored. Use of this property is NOT RECOMMENDED, as it is likely to be removed in a later revision.',
'`boolean`\n\\\n\\\nSets the ability to pass empty-valued parameters. This is valid only for `query` parameters and allows sending a parameter with an empty value. Default value is `false`. If [`style`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterStyle) is used, and if behavior is `n/a` (cannot be serialized), the value of `allowEmptyValue` SHALL be ignored. Use of this property is NOT RECOMMENDED, as it is likely to be removed in a later revision.',
},
targetSpecs: OpenAPI31,
},
{
label: 'items',
insertText: 'items',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[Items Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#itemsObject)\n\\\n\\\n**Required if [`type`](#parameterType) is "array".** Describes the type of items in the array.',
},
targetSpecs: OpenAPI2,
},
{
label: 'collectionFormat',
insertText: 'collectionFormat',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'Determines the format of the array if type array is used. Possible values are:\n\n* `csv` - comma separated values `foo,bar`.\n* `ssv` - space separated values `foo bar`.\n* `tsv` - tab separated values `foo\\tbar`.\n* `pipes` - pipe separated values `foo|bar`.\n*`multi` - corresponds to multiple parameter instances instead of multiple values for a single instance `foo=bar&foo=baz`. This is valid only for parameters [`in`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterIn) "query" or "formData".\n\nDefault value is `csv`.',
},
targetSpecs: OpenAPI2,
},
{
label: 'default',
insertText: 'default',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'Declares the value of the parameter that the server will use if none is provided, for example a "count" to control the number of results per page might default to 100 if not supplied by the client in the request. (Note: "default" has no meaning for required parameters.) See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2. Unlike JSON Schema this value MUST conform to the defined [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterType) for this parameter.',
},
targetSpecs: OpenAPI2,
},
{
label: 'maximum',
insertText: 'maximum',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`number`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.2.',
},
targetSpecs: OpenAPI2,
},
{
label: 'exclusiveMaximum',
insertText: 'exclusiveMaximum',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`boolean`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.2.',
},
targetSpecs: OpenAPI2,
},
{
label: 'minimum',
insertText: 'minimum',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`number`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.',
},
targetSpecs: OpenAPI2,
},
{
label: 'exclusiveMinimum',
insertText: 'exclusiveMinimum',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`boolean`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.',
},
targetSpecs: OpenAPI2,
},
{
label: 'maxLength',
insertText: 'maxLength',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`integer`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.1.',
},
targetSpecs: OpenAPI2,
},
{
label: 'minLength',
insertText: 'minLength',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`integer`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.2.',
},
targetSpecs: OpenAPI2,
},
{
label: 'pattern',
insertText: 'pattern',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value: 'See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.3.',
},
targetSpecs: OpenAPI2,
},
{
label: 'maxItems',
insertText: 'maxItems',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`integer`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.2.',
},
targetSpecs: OpenAPI2,
},
{
label: 'minItems',
insertText: 'minItems',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`integer`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.3.',
},
targetSpecs: OpenAPI2,
},
{
label: 'uniqueItems',
insertText: 'uniqueItems',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`boolean`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.4.',
},
targetSpecs: OpenAPI2,
},
{
label: 'enum',
insertText: 'enum',
kind: 14,
format: CompletionFormat.ARRAY,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`[*]`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.1.',
},
targetSpecs: OpenAPI2,
},
{
label: 'multipleOf',
insertText: 'multipleOf',
kind: 14,
format: CompletionFormat.UNQUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'`number`\n\\\n\\\nSee https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.1.',
},
targetSpecs: OpenAPI2,
},
{
label: 'style',
insertText: 'style',
Expand Down Expand Up @@ -201,6 +480,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI3,
},
{
label: 'schema',
insertText: 'schema',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#schemaObject)\n\\\n\\\n**Required.** The schema defining the type used for the body parameter.',
},
targetSpecs: OpenAPI2,
},
{
label: 'schema',
insertText: 'schema',
Expand Down Expand Up @@ -229,6 +522,34 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI31,
},
{
label: 'type',
insertText: 'type',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'**Required.** The type of the parameter. Since the parameter is not located at the request body, it is limited to simple types (that is, not an object). The value MUST be one of `"string"`, `"number"`, `"integer"`, `"boolean"`, `"array"` or `"file"`. If `type` is `"file"`, the [`consumes`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#operationConsumes) MUST be either `"multipart/form-data"`, `" application/x-www-form-urlencoded"` or both and the parameter MUST be [`in`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterIn) `"formData"`.',
},
targetSpecs: OpenAPI2,
},
{
label: 'format',
insertText: 'format',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'The extending format for the previously mentioned [`type`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#parameterType). See [Data Type Formats](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#dataTypeFormat) for further details.',
},
targetSpecs: OpenAPI2,
},
{
label: 'example',
insertText: 'example',
Expand Down

0 comments on commit 2f1f4a6

Please sign in to comment.