diff --git a/README.md b/README.md index 56bcadd..cc0dc22 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Works well with [Stoplight.io](https://stoplight.io/) - [`cookieParams`](#cookieparams) - [`requestModels`](#requestmodels) - [`methodResponses`](#methodresponses-and-responsemodels) + - [`webhooks`](#webhooks) - [Install](#install) --- @@ -114,6 +115,7 @@ The `documentation` section of the event configuration can contain the following * `pathParams`: a list of path parameters (see [pathParams](#pathparams) below) - **these _can_ be autogenerated for you from TypeScript** * `cookieParams`: a list of cookie parameters (see [cookieParams](#cookieparams) below) * `methodResponses`: an array of response models and applicable status codes (see [methodResponses](#methodresponses-and-responsemodels)) - **these _will_ be autogenerated for you from TypeScript** +* `webhooks`: an object with all the webhooks with descriptions (see [webhooks](#webhooks)) - **these _will_ be autogenerated for you from TypeScript** ```yml functions: @@ -435,6 +437,68 @@ functions: Endpoints that are not attached to a custom tag, are still attached to the title ( which is the default tag ). +#### `webhooks` +OpenAPI have an option to add your application `webhooks`, while this feature isn't supported by `serverless`. + +For those the plugin will look for the webhooks under `custom.documentation.webhooks`. + +For example + +```yaml +custom: + documentation: + apiNamespace: MyApi + webhooks: + WebhookName: + post: + requestBody: + description: | + This is a request body description + responses: + 200: + description: | + This is a expected response description +``` + +this will generate the next OpenAPI file + +```yaml +components: + schemas: + MyApi.Webhooks.WebhookName: + type: object +webhooks: + WebhookName: + post: + requestBody: + description: | + This is a request body description + content: + application/json: + schema: + $ref: '#/components/schemas/MyApi.Webhooks.WebhookName' + responses: + '200': + description: | + This is a expected response description +``` + +With the next `api.d.ts`: + +```typescript +export namespace MyApi { + export namespace Webhooks { + export type WebhookName = { + id: string, + name: string, + age: number + // ... + } + } +} +``` + + ## Install This plugin is **an extension**. diff --git a/package.json b/package.json index be82676..592164a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-openapi-typescript", - "version": "2.0.0", + "version": "2.1.0", "description": "An extension of @conqa/serverless-openapi-documentation that also generates your OpenAPI models from TypeScript", "main": "dist/index.js", "scripts": { @@ -14,6 +14,7 @@ "ts-json-schema-generator": "^1.1.2" }, "devDependencies": { + "@types/node": "20.12.11", "@conqa/serverless-openapi-documentation": "^1.1.0", "@types/jest": "^27.0.1", "@types/serverless": "^1.78.35", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 52a2b6f..392c3fe 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,8 +1,9 @@ -lockfileVersion: 5.3 +lockfileVersion: 5.4 specifiers: '@conqa/serverless-openapi-documentation': ^1.1.0 '@types/jest': ^27.0.1 + '@types/node': 20.12.11 '@types/serverless': ^1.78.35 deepdash: ^5.3.9 jest: ^27.0.6 @@ -22,10 +23,11 @@ dependencies: devDependencies: '@conqa/serverless-openapi-documentation': 1.1.0 '@types/jest': 27.5.2 + '@types/node': 20.12.11 '@types/serverless': 1.78.44 jest: 27.5.1 serverless: 2.72.3 - ts-jest: 27.1.5_3e98952c91d0ad38e7beba6fb8181295 + ts-jest: 27.1.5_h2mjkler2cwtrz56xjx3qgassu typescript: 4.8.4 packages: @@ -203,6 +205,8 @@ packages: resolution: {integrity: sha512-qpVT7gtuOLjWeDTKLkJ6sryqLliBaFpAtGeqw5cs5giLldvh+Ch0plqnUMKoVAUS6ZEueQQiZV+p5pxtPitEsA==} engines: {node: '>=6.0.0'} hasBin: true + dependencies: + '@babel/types': 7.19.4 dev: true /@babel/plugin-syntax-async-generators/7.8.4_@babel+core@7.19.3: @@ -407,7 +411,7 @@ packages: engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} dependencies: '@jest/types': 27.5.1 - '@types/node': 18.8.4 + '@types/node': 20.12.11 chalk: 4.1.2 jest-message-util: 27.5.1 jest-util: 27.5.1 @@ -428,7 +432,7 @@ packages: '@jest/test-result': 27.5.1 '@jest/transform': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 18.8.4 + '@types/node': 20.12.11 ansi-escapes: 4.3.2 chalk: 4.1.2 emittery: 0.8.1 @@ -465,7 +469,7 @@ packages: dependencies: '@jest/fake-timers': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 18.8.4 + '@types/node': 20.12.11 jest-mock: 27.5.1 dev: true @@ -475,7 +479,7 @@ packages: dependencies: '@jest/types': 27.5.1 '@sinonjs/fake-timers': 8.1.0 - '@types/node': 18.8.4 + '@types/node': 20.12.11 jest-message-util: 27.5.1 jest-mock: 27.5.1 jest-util: 27.5.1 @@ -504,7 +508,7 @@ packages: '@jest/test-result': 27.5.1 '@jest/transform': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 18.8.4 + '@types/node': 20.12.11 chalk: 4.1.2 collect-v8-coverage: 1.0.1 exit: 0.1.2 @@ -588,7 +592,7 @@ packages: dependencies: '@types/istanbul-lib-coverage': 2.0.4 '@types/istanbul-reports': 3.0.1 - '@types/node': 18.8.4 + '@types/node': 20.12.11 '@types/yargs': 16.0.4 chalk: 4.1.2 dev: true @@ -1067,14 +1071,14 @@ packages: dependencies: '@types/http-cache-semantics': 4.0.1 '@types/keyv': 3.1.4 - '@types/node': 18.8.4 + '@types/node': 20.12.11 '@types/responselike': 1.0.0 dev: true /@types/graceful-fs/4.1.5: resolution: {integrity: sha512-anKkLmZZ+xm4p8JWBf4hElkM4XR+EZeA2M9BAkkTldmcyDY4mbdIJnRghDJH3Ov5ooY7/UAoENtmdMSkaAd7Cw==} dependencies: - '@types/node': 18.8.4 + '@types/node': 20.12.11 dev: true /@types/http-cache-semantics/4.0.1: @@ -1111,7 +1115,7 @@ packages: /@types/keyv/3.1.4: resolution: {integrity: sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==} dependencies: - '@types/node': 18.8.4 + '@types/node': 20.12.11 dev: true /@types/lodash/4.14.186: @@ -1122,8 +1126,10 @@ packages: resolution: {integrity: sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA==} dev: true - /@types/node/18.8.4: - resolution: {integrity: sha512-WdlVphvfR/GJCLEMbNA8lJ0lhFNBj4SW3O+O5/cEGw9oYrv0al9zTwuQsq+myDUXgNx2jgBynoVgZ2MMJ6pbow==} + /@types/node/20.12.11: + resolution: {integrity: sha512-vDg9PZ/zi+Nqp6boSOT7plNuthRugEKixDv5sFTIpkE89MmNtEArAShI4mxuX2+UrLEe9pxC1vm2cjm9YlWbJw==} + dependencies: + undici-types: 5.26.5 dev: true /@types/prettier/2.7.1: @@ -1133,7 +1139,7 @@ packages: /@types/responselike/1.0.0: resolution: {integrity: sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==} dependencies: - '@types/node': 18.8.4 + '@types/node': 20.12.11 dev: true /@types/serverless/1.78.44: @@ -2104,12 +2110,22 @@ packages: /debug/2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true dependencies: ms: 2.0.0 dev: true /debug/3.1.0: resolution: {integrity: sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true dependencies: ms: 2.0.0 dev: true @@ -2398,6 +2414,7 @@ packages: yeast: 0.1.2 transitivePeerDependencies: - bufferutil + - supports-color - utf-8-validate dev: true @@ -3104,6 +3121,8 @@ packages: dependencies: '@sindresorhus/is': 0.14.0 '@szmarczak/http-timer': 1.1.2 + '@types/keyv': 3.1.4 + '@types/responselike': 1.0.0 cacheable-request: 6.1.0 decompress-response: 3.3.0 duplexer3: 0.1.5 @@ -3637,7 +3656,7 @@ packages: '@jest/environment': 27.5.1 '@jest/test-result': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 18.8.4 + '@types/node': 20.12.11 chalk: 4.1.2 co: 4.6.0 dedent: 0.7.0 @@ -3762,7 +3781,7 @@ packages: '@jest/environment': 27.5.1 '@jest/fake-timers': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 18.8.4 + '@types/node': 20.12.11 jest-mock: 27.5.1 jest-util: 27.5.1 jsdom: 16.7.0 @@ -3780,7 +3799,7 @@ packages: '@jest/environment': 27.5.1 '@jest/fake-timers': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 18.8.4 + '@types/node': 20.12.11 jest-mock: 27.5.1 jest-util: 27.5.1 dev: true @@ -3796,7 +3815,7 @@ packages: dependencies: '@jest/types': 27.5.1 '@types/graceful-fs': 4.1.5 - '@types/node': 18.8.4 + '@types/node': 20.12.11 anymatch: 3.1.2 fb-watchman: 2.0.2 graceful-fs: 4.2.10 @@ -3818,7 +3837,7 @@ packages: '@jest/source-map': 27.5.1 '@jest/test-result': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 18.8.4 + '@types/node': 20.12.11 chalk: 4.1.2 co: 4.6.0 expect: 27.5.1 @@ -3873,7 +3892,7 @@ packages: engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} dependencies: '@jest/types': 27.5.1 - '@types/node': 18.8.4 + '@types/node': 20.12.11 dev: true /jest-pnp-resolver/1.2.2_jest-resolve@27.5.1: @@ -3929,7 +3948,7 @@ packages: '@jest/test-result': 27.5.1 '@jest/transform': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 18.8.4 + '@types/node': 20.12.11 chalk: 4.1.2 emittery: 0.8.1 graceful-fs: 4.2.10 @@ -3986,7 +4005,7 @@ packages: resolution: {integrity: sha512-jZCyo6iIxO1aqUxpuBlwTDMkzOAJS4a3eYz3YzgxxVQFwLeSA7Jfq5cbqCY+JLvTDrWirgusI/0KwxKMgrdf7w==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} dependencies: - '@types/node': 18.8.4 + '@types/node': 20.12.11 graceful-fs: 4.2.10 dev: true @@ -4025,7 +4044,7 @@ packages: engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} dependencies: '@jest/types': 27.5.1 - '@types/node': 18.8.4 + '@types/node': 20.12.11 chalk: 4.1.2 ci-info: 3.5.0 graceful-fs: 4.2.10 @@ -4050,7 +4069,7 @@ packages: dependencies: '@jest/test-result': 27.5.1 '@jest/types': 27.5.1 - '@types/node': 18.8.4 + '@types/node': 20.12.11 ansi-escapes: 4.3.2 chalk: 4.1.2 jest-util: 27.5.1 @@ -4061,7 +4080,7 @@ packages: resolution: {integrity: sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==} engines: {node: '>= 10.13.0'} dependencies: - '@types/node': 18.8.4 + '@types/node': 20.12.11 merge-stream: 2.0.0 supports-color: 8.1.1 dev: true @@ -4263,6 +4282,8 @@ packages: uuid: 3.4.0 optionalDependencies: snappy: 6.3.5 + transitivePeerDependencies: + - supports-color dev: true /keyv/3.1.0: @@ -5168,7 +5189,7 @@ packages: '@protobufjs/pool': 1.1.0 '@protobufjs/utf8': 1.1.0 '@types/long': 4.0.2 - '@types/node': 18.8.4 + '@types/node': 20.12.11 long: 4.0.0 dev: true @@ -5739,6 +5760,7 @@ packages: to-array: 0.1.4 transitivePeerDependencies: - bufferutil + - supports-color - utf-8-validate dev: true @@ -5748,6 +5770,8 @@ packages: component-emitter: 1.3.0 debug: 3.1.0 isarray: 2.0.1 + transitivePeerDependencies: + - supports-color dev: true /sort-keys-length/1.0.1: @@ -6228,7 +6252,7 @@ packages: resolution: {integrity: sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==} dev: true - /ts-jest/27.1.5_3e98952c91d0ad38e7beba6fb8181295: + /ts-jest/27.1.5_h2mjkler2cwtrz56xjx3qgassu: resolution: {integrity: sha512-Xv6jBQPoBEvBq/5i2TeSG9tt/nqkbpcurrEG1b+2yfBrcJelOZF9Ml6dmyMh7bcW9JyFbRYpR5rxROSlBLTZHA==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} hasBin: true @@ -6357,6 +6381,10 @@ packages: through: 2.3.8 dev: true + /undici-types/5.26.5: + resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + dev: true + /uni-global/1.0.0: resolution: {integrity: sha512-WWM3HP+siTxzIWPNUg7hZ4XO8clKi6NoCAJJWnuRL+BAqyFXF8gC03WNyTefGoUXYc47uYgXxpKLIEvo65PEHw==} dependencies: diff --git a/src/serverless-openapi-typescript.ts b/src/serverless-openapi-typescript.ts index 09d9ffb..2474a4e 100644 --- a/src/serverless-openapi-typescript.ts +++ b/src/serverless-openapi-typescript.ts @@ -23,6 +23,7 @@ export default class ServerlessOpenapiTypeScript { private typescriptApiModelPath: string; private tsconfigPath: string; private schemaGenerator: SchemaGenerator; + private webhookEntries: Record = {}; constructor(private serverless: Serverless, private options: Options) { this.assertPluginOrder(); @@ -64,6 +65,10 @@ export default class ServerlessOpenapiTypeScript { return this.serverless.service.functions || {}; } + get webhooks() { + return this.serverless.service.custom.documentation.webhooks || {}; + } + log(msg) { this.serverless.cli.log(`[serverless-openapi-typescript] ${msg}`); } @@ -77,7 +82,7 @@ export default class ServerlessOpenapiTypeScript { if (httpEvent.documentation) { this.log(`Generating docs for ${functionName}`); - this.setModels(httpEvent, functionName); + this.setHttpMethodModels(httpEvent, functionName); const paths = get(httpEvent, 'request.parameters.paths', []); const querystrings = get(httpEvent, 'request.parameters.querystrings', {}); @@ -94,6 +99,16 @@ export default class ServerlessOpenapiTypeScript { }); }); + this.log('Scanning webhooks for documentation attribute'); + Object.keys(this.webhooks).forEach(webhookName => { + const webhook = this.webhooks[webhookName]; + const methodDefinition = webhook['post']; + if (methodDefinition) { + this.setWebhookModels(methodDefinition, webhookName); + this.log(`Generating docs for webhook ${webhookName}`); + } + }); + this.assertAllFunctionsDocumented(); } @@ -138,7 +153,7 @@ export default class ServerlessOpenapiTypeScript { }); } - setModels(httpEvent, functionName) { + setHttpMethodModels(httpEvent, functionName) { const definitionPrefix = `${this.serverless.service.custom.documentation.apiNamespace}.${upperFirst(camelCase(functionName))}`; const method = httpEvent.method.toLowerCase(); switch (method) { @@ -179,10 +194,21 @@ export default class ServerlessOpenapiTypeScript { } } + setWebhookModels(webhook, webhookName: string) { + const webhookModelName = `${this.serverless.service.custom.documentation.apiNamespace}.Webhooks.${upperFirst(camelCase(webhookName))}`; + this.setModel(webhookModelName); + this.webhookEntries[webhookName] = { + post: webhook + }; + // Since the original plugin doesn't read `webhooks` property and handle it we need to help it + set(this.webhookEntries[webhookName], 'post.requestBody.content', { 'application/json': { schema: { '$ref': `#/components/schemas/${webhookModelName}` } } }); + } + postProcessOpenApi() { // @ts-ignore const outputFile = this.serverless.processedInput.options.output; const openApi = yaml.load(fs.readFileSync(outputFile)); + openApi['webhooks'] = this.webhookEntries; this.patchOpenApiVersion(openApi); this.enrichMethodsInfo(openApi); const encodedOpenAPI = this.encodeOpenApiToStandard(openApi); diff --git a/test/fixtures/expect-openapi-custom-tags.yml b/test/fixtures/expect-openapi-custom-tags.yml index 1a7981d..65f2c86 100644 --- a/test/fixtures/expect-openapi-custom-tags.yml +++ b/test/fixtures/expect-openapi-custom-tags.yml @@ -61,6 +61,7 @@ paths: $ref: '#/components/schemas/ProjectApi.GetFunc.Response' tags: - BazTitle +webhooks: {} tags: - name: Project description: DummyDescription diff --git a/test/fixtures/expect-openapi-full.yml b/test/fixtures/expect-openapi-full.yml index ecb38e9..d2ffd30 100644 --- a/test/fixtures/expect-openapi-full.yml +++ b/test/fixtures/expect-openapi-full.yml @@ -37,7 +37,7 @@ components: type: string generic: $ref: >- - #/components/schemas/ProjectApi.GenericType_structure-1448918441-633-661-1448918441-620-662-1448918441-599-663-1448918441-547-673-1448918441-515-674-1448918441-283-680-1448918441-250-680-1448918441-104-1213-1448918441-75-1213-1448918441-0-1214_ + #/components/schemas/ProjectApi.GenericType_structure-1448918441-758-786-1448918441-745-787-1448918441-724-788-1448918441-672-798-1448918441-640-799-1448918441-408-805-1448918441-376-805-1448918441-104-1338-1448918441-75-1338-1448918441-0-1339_ required: - id - uuid @@ -70,7 +70,18 @@ components: required: - data additionalProperties: false - ProjectApi.GenericType_structure-1448918441-633-661-1448918441-620-662-1448918441-599-663-1448918441-547-673-1448918441-515-674-1448918441-283-680-1448918441-250-680-1448918441-104-1213-1448918441-75-1213-1448918441-0-1214_: + ProjectApi.Webhooks.OnCreateWebhook: + type: object + properties: + id: + type: string + name: + type: string + required: + - id + - name + additionalProperties: false + ProjectApi.GenericType_structure-1448918441-758-786-1448918441-745-787-1448918441-724-788-1448918441-672-798-1448918441-640-799-1448918441-408-805-1448918441-376-805-1448918441-104-1338-1448918441-75-1338-1448918441-0-1339_: type: array items: type: object @@ -83,6 +94,7 @@ components: - key - name additionalProperties: false + info: title: Project description: > @@ -220,6 +232,21 @@ paths: $ref: '#/components/schemas/ProjectApi.GetFunc.Response' tags: - Project +webhooks: + OnCreateWebhook: + post: + requestBody: + description: | + This is a request body description + content: + application/json: + schema: + $ref: >- + #/components/schemas/ProjectApi.Webhooks.OnCreateWebhook + responses: + '200': + description: | + This is a expected response description tags: - name: Project description: > diff --git a/test/fixtures/expect-openapi-hyphenated-functions.yml b/test/fixtures/expect-openapi-hyphenated-functions.yml index 7c5c0a6..24a857c 100644 --- a/test/fixtures/expect-openapi-hyphenated-functions.yml +++ b/test/fixtures/expect-openapi-hyphenated-functions.yml @@ -61,6 +61,7 @@ paths: $ref: '#/components/schemas/ProjectApi.GetFunc.Response' tags: - BazTitle +webhooks: {} tags: - name: Project description: DummyDescription diff --git a/test/fixtures/expect-openapi-query-param-type.yml b/test/fixtures/expect-openapi-query-param-type.yml index 5a77bb0..d5558f1 100644 --- a/test/fixtures/expect-openapi-query-param-type.yml +++ b/test/fixtures/expect-openapi-query-param-type.yml @@ -48,6 +48,7 @@ paths: $ref: '#/components/schemas/ProjectApi.Func.Response' tags: - Project +webhooks: {} tags: - name: Project description: DummyDescription diff --git a/test/fixtures/expect-openapi-webhooks.yml b/test/fixtures/expect-openapi-webhooks.yml new file mode 100644 index 0000000..98b9b3a --- /dev/null +++ b/test/fixtures/expect-openapi-webhooks.yml @@ -0,0 +1,40 @@ +openapi: 3.1.0 +components: + schemas: + ProjectApi.Webhooks.OnCreateWebhook: + type: object + properties: + id: + type: string + name: + type: string + required: + - id + - name + additionalProperties: false +info: + title: Project + description: DummyDescription +paths: { } +webhooks: + OnCreateWebhook: + post: + requestBody: + description: | + This is a request body description + content: + application/json: + schema: + $ref: >- + #/components/schemas/ProjectApi.Webhooks.OnCreateWebhook + responses: + '200': + description: | + This is a expected response description +tags: + - name: Project + description: DummyDescription + - name: FooBarTitle + description: FooBarDescription + - name: BazTitle + description: BazDescription diff --git a/test/serverless-full/api.d.ts b/test/serverless-full/api.d.ts index 1c2cc84..8d54730 100644 --- a/test/serverless-full/api.d.ts +++ b/test/serverless-full/api.d.ts @@ -8,7 +8,12 @@ export namespace ProjectApi { export type Number = number export type String = string; export type GenericType = T[]; - + export namespace Webhooks { + export type OnCreateWebhook = { + id: string; + name: string; + } + } export namespace CreateFunc { export namespace Request { export type Body = { diff --git a/test/serverless-full/resources/serverless.yml b/test/serverless-full/resources/serverless.yml index 23e8bde..27d3833 100644 --- a/test/serverless-full/resources/serverless.yml +++ b/test/serverless-full/resources/serverless.yml @@ -20,6 +20,16 @@ custom: More on https://google.com apiNamespace: ProjectApi + webhooks: + OnCreateWebhook: + post: + requestBody: + description: | + This is a request body description + responses: + 200: + description: | + This is a expected response description functions: createFunc: diff --git a/test/serverless-openapi-typescript.spec.ts b/test/serverless-openapi-typescript.spec.ts index b74e331..644eb62 100644 --- a/test/serverless-openapi-typescript.spec.ts +++ b/test/serverless-openapi-typescript.spec.ts @@ -16,6 +16,7 @@ describe('ServerlessOpenapiTypeScript', () => { ${'Custom Tags'} | ${'custom-tags'} ${'Hyphenated Functions'} | ${'hyphenated-functions'} ${'Full Project'} | ${'full'} + ${'Webhooks'} | ${'webhooks'} `('when using $testCase', ({projectName}) => { beforeEach(async () => { diff --git a/test/serverless-webhooks/api.d.ts b/test/serverless-webhooks/api.d.ts new file mode 100644 index 0000000..10fd014 --- /dev/null +++ b/test/serverless-webhooks/api.d.ts @@ -0,0 +1,8 @@ +export namespace ProjectApi { + export namespace Webhooks { + export type OnCreateWebhook = { + id: string; + name: string; + } + } +} diff --git a/test/serverless-webhooks/resources/serverless.yml b/test/serverless-webhooks/resources/serverless.yml new file mode 100644 index 0000000..48070c7 --- /dev/null +++ b/test/serverless-webhooks/resources/serverless.yml @@ -0,0 +1,30 @@ +service: serverless-openapi-typescript-demo +provider: + name: aws + +plugins: + - ../node_modules/@conqa/serverless-openapi-documentation + - ../src/index + +custom: + documentation: + title: 'Project' + description: DummyDescription + apiNamespace: ProjectApi + tags: + - name: FooBarTitle + description: FooBarDescription + - name: BazTitle + description: BazDescription + webhooks: + OnCreateWebhook: + post: + requestBody: + description: | + This is a request body description + responses: + 200: + description: | + This is a expected response description + +