1

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!

pafede2
  • 1,626
  • 4
  • 23
  • 40
  • 1
    The error message is generated from typescript linting, and not from the serverless-openapi-documentation plugin. – Benny Thomas Mar 01 '21 at 09:41
  • While that's true @BennyThomas, adding @ts-ignore then results in the `serverless openapi generate` command throwing the error: `"service" property is missing in serverless.ts`. Has anyone encountered a solution? – LeeCambl May 10 '21 at 19:29

0 Answers0