Closed naezeroth closed 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
path
: we can easily check if it's part of the pattern variables and then push the input as a path parameter.requestBody
: we can't totally assume the input to be a body param when the HTTP method is put|post
because some of the inputs might be query param like the way we do currently.query
: we can assume all inputs are query
param after removing the path param when the HTTP method is get
.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
@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
@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
outputExample
req
inputPerhaps 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;
};
}
@danielsharvey using the meta
sounds great and it gives room for more options. 👍
:tada: This issue has been resolved in version 3.2.3 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
My actions2 file has inputs described however upon using this tool, the json generated does not include the inputs as parameters for the endpoint.