theoomoregbee / sails-hook-swagger-generator

A tool to help generate Swagger specification documentation based on OAS 3.0 for Sails APIs
MIT License
78 stars 33 forks source link

Parameters not showing up despite actions2 having inputs detailed. #66

Closed naezeroth closed 4 years ago

naezeroth commented 4 years ago

My actions2 file has inputs described however upon using this tool, the json generated does not include the inputs as parameters for the endpoint.

image

image

theoomoregbee commented 4 years ago

Some of the problems with action2.inputs are fixed in the referenced PR above (basically we were not parsing action2 accurately).

The next problem is how do we want to handle the action2 inputs because with the above fix, we only take action 2 inputs as either path or query params which do not cover your use case.

For

Maybe solution

We stick with the way we handle path params, but for query and or requestBody we just assume for post|put we take inputs(that are not path params) as request body, then you can pass query parameters via swagger.actions.action2Name.parameters. While for routes with HTTP method get we just take all inputs as query params

wdyt @danielsharvey @naezeroth

danielsharvey commented 4 years ago

@theoomoregbee I will have a look. I had picked up some of the actions2 issues in https://github.com/theoomoregbee/sails-hook-swagger-generator/pull/67

danielsharvey commented 4 years ago

@theoomoregbee: Some thoughts...

The request body one is interesting in that OpenAPI deals with this type of parameter differently to path/query/header/cookie.

I am proposing in #67 to use the attribute meta property when defining models to provide Swagger extensions e.g. for an attribute id:

id: {
  type: 'number',
  autoIncrement: true,
  meta: {
    swagger: { readOnly: true }
  }
},

Perhaps a similar extension for inputs:

userId: {
  type: 'number',
  meta: {
    swagger: { in: 'body' }
  }
},

and support body as well as the standard OpenAPI body types.

Also need to consider

danielsharvey commented 4 years ago

Perhaps extend Sails.Actions2Input as follows:

export interface SwaggerSailsActions2Input extends Sails.Actions2Input {
  meta?: {
    swagger?: (OpenApi.Parameter | OpenApi.MediaType) & {
      in?: 'query' | 'header' | 'path' | 'cookie' | 'body';
      exclude?: boolean;
    };
    [name: string]: any;
  };
}
theoomoregbee commented 4 years ago

@danielsharvey using the meta sounds great and it gives room for more options. 👍

theoomoregbee commented 4 years ago

closed in https://github.com/theoomoregbee/sails-hook-swagger-generator/pull/72

theoomoregbee commented 4 years ago

:tada: This issue has been resolved in version 3.2.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket: