From 10381d61b8ecd2409f483cab34dc3c9f9689d282 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 13 Sep 2022 13:25:24 -0700 Subject: [PATCH] feat(ls): oas31 docs for callback object --- .../src/config/openapi/callback/documentation.ts | 8 ++++++++ packages/apidom-ls/src/config/openapi/callback/meta.ts | 8 ++++++++ packages/apidom-ls/src/config/openapi/config.ts | 2 ++ 3 files changed, 18 insertions(+) create mode 100644 packages/apidom-ls/src/config/openapi/callback/documentation.ts create mode 100644 packages/apidom-ls/src/config/openapi/callback/meta.ts diff --git a/packages/apidom-ls/src/config/openapi/callback/documentation.ts b/packages/apidom-ls/src/config/openapi/callback/documentation.ts new file mode 100644 index 0000000000..5f16bdc2d4 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/callback/documentation.ts @@ -0,0 +1,8 @@ +const documentation = [ + { + docs: "#### [Callback Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object)\n\nA map of possible out-of band callbacks related to the parent operation. Each value in the map is a [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) that describes a set of requests that may be initiated by the API provider and the expected responses. The key value used to identify the path item object is an expression, evaluated at runtime, that identifies a URL to use for the callback operation.\n\n\\\nTo describe incoming requests from the API provider independent from another API call, use the [`webhooks`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oasWebhooks) field.\n\n##### Patterned Fields\n\nField Pattern | Type | Description\n---|:---:|---\n{expression} | [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) | [Reference Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject) | A Path Item Object, or a reference to one, used to define a callback request and expected responses. A [complete example](https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/callback-example.yaml) is available.\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##### Key Expression\n\nThe key that identifies the [Path Item Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#pathItemObject) is a [runtime expression](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#runtimeExpression) that can be evaluated in the context of a runtime HTTP request/response to identify the URL to be used for the callback request. A simple example might be `$request.body#/url`. However, using a [runtime expression](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#runtimeExpression) the complete HTTP message can be accessed. This includes accessing any part of a body that a JSON Pointer [RFC6901](https://tools.ietf.org/html/rfc6901) can reference.\n\n\\\nFor example, given the following HTTP request:\n\n\\\nYAML\n```yaml\nPOST /subscribe/myevent?queryUrl=https://clientdomain.com/stillrunning HTTP/1.1\nHost: example.org\nContent-Type: application/json\nContent-Length: 187\n\n{\n \"failedUrl\" : \"https://clientdomain.com/failed\",\n \"successUrls\" : [\n \"https://clientdomain.com/fast\",\n \"https://clientdomain.com/medium\",\n \"https://clientdomain.com/slow\"\n ] \n}\n\n201 Created\nLocation: https://example.org/subscription/1\n```\n\n\\\nThe following examples show how the various expressions evaluate, assuming the callback operation has a path parameter named `eventType` and a query parameter named `queryUrl`.\n\nExpression | Value\n---|:---\n$url | https://example.org/subscribe/myevent?queryUrl=https://clientdomain.com/stillrunning\n$method | POST\n$request.path.eventType | myevent\n$request.query.queryUrl | https://clientdomain.com/stillrunning\n$request.header.content-Type | application/json\n$request.body#/failedUrl | https://clientdomain.com/failed\n$request.body#/successUrls/2 | https://clientdomain.com/medium\n$response.header.Location | https://example.org/subscription/1\n##### Callback Examples\n\nThe following example uses the user provided `queryUrl` query string parameter to define the callback URL. This is an example of how to use a callback object to describe a WebHook callback that goes with the subscription operation to enable registering for the WebHook.\n\n\\\nYAML\n```myCallback:\n '{ $request.query.queryUrl }':\n post:\n requestBody:\n description: Callback payload\n content:\n 'application/json':\n schema:\n $ref: '#/components/schemas/SomePayload'\n responses:\n '200':\n description: callback successfully processed\n```\n\n\\\nThe following example shows a callback where the server is hard-coded, but the query string parameters are populated from the `id` and `email` property in the request body.\n\n\\\nYAML\n```transactionCallback:\n 'http://notificationServer.com?transactionId={$request.body#/id}&email={$request.body#/email}':\n post:\n requestBody:\n description: Callback payload\n content:\n 'application/json':\n schema:\n $ref: '#/components/schemas/SomePayload'\n responses:\n '200':\n description: callback successfully processed\n```\n", + targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }], + }, +]; + +export default documentation; diff --git a/packages/apidom-ls/src/config/openapi/callback/meta.ts b/packages/apidom-ls/src/config/openapi/callback/meta.ts new file mode 100644 index 0000000000..33a6f79694 --- /dev/null +++ b/packages/apidom-ls/src/config/openapi/callback/meta.ts @@ -0,0 +1,8 @@ +import documentation from './documentation'; +import { FormatMeta } from '../../../apidom-language-types'; + +const meta: FormatMeta = { + documentation, +}; + +export default meta; diff --git a/packages/apidom-ls/src/config/openapi/config.ts b/packages/apidom-ls/src/config/openapi/config.ts index 60b1ba007a..a8238b1b74 100644 --- a/packages/apidom-ls/src/config/openapi/config.ts +++ b/packages/apidom-ls/src/config/openapi/config.ts @@ -1,3 +1,4 @@ +import callbackMeta from './callback/meta'; import contactMeta from './contact/meta'; import exampleMeta from './example/meta'; import externalDocumentationMeta from './external-documentation/meta'; @@ -30,6 +31,7 @@ export default { }, ], }, + callback: callbackMeta, contact: contactMeta, example: exampleMeta, externalDocumentation: externalDocumentationMeta,