How to use serverless-openapi-documentation with serverless Typescript template?

1.2k views Asked by At

The issue is the following:

I aim to document a AWS serverless API using Serverless framework with the open API plugin for API documentation.

The issue I am facing is that the Serverless configuration created on serverless.ts file do not have a documentation field, it only has this definition:

interface Http {
    path: string;
    method: string;
    cors?: boolean | HttpCors;
    private?: boolean;
    async?: boolean;
    authorizer?: HttpAuthorizer;
    request?: HttpRequestValidation;
}

Steps to reproduce the issue:

  • Create Serverless project with Typescript template:

    $ sls create -t aws-nodejs-typescript --path testName -n appName

  • Add openapi plugin

    plugins: ['serverless-webpack', 'serverless-openapi-documentation'],
    
  • Replace functions section on serverless.ts with this:

    functions: {
      hello: {
        handler: 'handler.hello',
        events: [
          {
            http: {
              method: 'get',
              path: 'hello',
              documentation: {
                summary: "Create something"
              },
            }
          }
        ]
      }
    }
    

An error on the documentation line such as this will appear:

Type '{ http: { method: string; path: string; }; documentation: { summary: string; }; }' is not assignable to type 'Event'. Object literal may only specify known properties, and 'documentation' does not exist in type 'Event'.

However, if instead of using the typescript template(i.e.: aws-nodejs-typescript) we use yml template(i.e.: aws-python) the documentation key can be added and the open API plugin works properly.

Does it means Open API plugin do not support Typescript yet? or rather, I am missing any configuration?

Thanks!

0

There are 0 answers