From 4b1282f26ea36a280fb37a54b0bfdbab4a4ca1bc Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Fri, 16 Sep 2022 15:29:55 -0700 Subject: [PATCH] feat(ls): oas31 docs for request body object --- .../apidom-ls/src/config/openapi/config.ts | 2 ++ .../openapi/request-body/documentation.ts | 19 +++++++++++++++++++ .../src/config/openapi/request-body/meta.ts | 8 ++++++++ 3 files changed, 29 insertions(+) create mode 100644 packages/apidom-ls/src/config/openapi/request-body/documentation.ts create mode 100644 packages/apidom-ls/src/config/openapi/request-body/meta.ts diff --git a/packages/apidom-ls/src/config/openapi/config.ts b/packages/apidom-ls/src/config/openapi/config.ts index dd71a1b72e..a8cfc018dd 100644 --- a/packages/apidom-ls/src/config/openapi/config.ts +++ b/packages/apidom-ls/src/config/openapi/config.ts @@ -13,6 +13,7 @@ import operationMeta from './operation/meta'; import parameterMeta from './parameter/meta'; import pathItemMeta from './path-item/meta'; import pathsMeta from './paths/meta'; +import requestBodyMeta from './request-body/meta'; import responseMeta from './response/meta'; import responsesMeta from './responses/meta'; import securityRequirementMeta from './security-requirement/meta'; @@ -52,6 +53,7 @@ export default { parameter: parameterMeta, pathItem: pathItemMeta, paths: pathsMeta, + requestBody: requestBodyMeta, response: responseMeta, responses: responsesMeta, securityRequirement: securityRequirementMeta, diff --git a/packages/apidom-ls/src/config/openapi/request-body/documentation.ts b/packages/apidom-ls/src/config/openapi/request-body/documentation.ts new file mode 100644 index 0000000000..afbfcdf546 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/request-body/documentation.ts @@ -0,0 +1,19 @@ +const documentation = [ + { + target: 'description', + docs: 'A brief description of the request body. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.', + }, + { + target: 'content', + docs: 'Map[`string`, [Media Type Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#mediaTypeObject)]\n\\\n\\\n**REQUIRED**. The content of the request body. The key is a media type or [media type range](https://tools.ietf.org/html/rfc7231#appendix-D) and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*', + }, + { + target: 'required', + docs: 'Determines if the request body is required in the request. Defaults to `false`.', + }, + { + docs: '#### Request Body Object\n\nDescribes a single request body.\n\n##### Fixed Fields\nField Name | Type | Description\n---|:---:|---\ndescription | `string` | A brief description of the request body. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.\ncontent | Map[`string`, [Media Type Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#mediaTypeObject)] | **REQUIRED**. The content of the request body. The key is a media type or [media type range](https://tools.ietf.org/html/rfc7231#appendix-D) and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*\nrequired | `boolean` | Determines if the request body is required in the request. Defaults to `false`.\n\n\\\nThis object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specificationExtensions).\n\n##### Request Body Examples\n\nA request body with a referenced model definition.\n\n\\\nJSON\n```json\n{\n "description": "user to add to the system",\n "content": {\n "application/json": {\n "schema": {\n "$ref": "#/components/schemas/User"\n },\n "examples": {\n "user" : {\n "summary": "User Example", \n "externalValue": "https://foo.bar/examples/user-example.json"\n } \n }\n },\n "application/xml": {\n "schema": {\n "$ref": "#/components/schemas/User"\n },\n "examples": {\n "user" : {\n "summary": "User example in XML",\n "externalValue": "https://foo.bar/examples/user-example.xml"\n }\n }\n },\n "text/plain": {\n "examples": {\n "user" : {\n "summary": "User example in Plain text",\n "externalValue": "https://foo.bar/examples/user-example.txt" \n }\n } \n },\n "*/*": {\n "examples": {\n "user" : {\n "summary": "User example in other format",\n "externalValue": "https://foo.bar/examples/user-example.whatever"\n }\n }\n }\n }\n}\n```\n\n\n\\\nYAML\n```yaml\ndescription: user to add to the system\ncontent: \n \'application/json\':\n schema:\n $ref: \'#/components/schemas/User\'\n examples:\n user:\n summary: User Example\n externalValue: \'https://foo.bar/examples/user-example.json\'\n \'application/xml\':\n schema:\n $ref: \'#/components/schemas/User\'\n examples:\n user:\n summary: User example in XML\n externalValue: \'https://foo.bar/examples/user-example.xml\'\n \'text/plain\':\n examples:\n user:\n summary: User example in Plain text\n externalValue: \'https://foo.bar/examples/user-example.txt\'\n \'*/*\':\n examples:\n user: \n summary: User example in other format\n externalValue: \'https://foo.bar/examples/user-example.whatever\'\n```\n\nA body parameter that is an array of string values:\n```json\n{\n "description": "user to add to the system",\n "required": true,\n "content": {\n "text/plain": {\n "schema": {\n "type": "array",\n "items": {\n "type": "string"\n }\n }\n }\n }\n}\n```\n\n```yaml\ndescription: user to add to the system\nrequired: true\ncontent:\n text/plain:\n schema:\n type: array\n items:\n type: string\n```', + }, +]; + +export default documentation; diff --git a/packages/apidom-ls/src/config/openapi/request-body/meta.ts b/packages/apidom-ls/src/config/openapi/request-body/meta.ts new file mode 100644 index 0000000000..33a6f79694 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/request-body/meta.ts @@ -0,0 +1,8 @@ +import documentation from './documentation'; +import { FormatMeta } from '../../../apidom-language-types'; + +const meta: FormatMeta = { + documentation, +}; + +export default meta;