Closed jmls closed 4 years ago
This was something by design in ng-openapi-gen. In ng-swagger-gen there's a configuration option for the minimum arguments to use a single object parameter. By default that is 3. In ng-openapi-gen a parameters object is always used. This made the generation much simpler. On the bright side, if the API adds new optional parameters, nothing changes in the client code. Sorry, but there's no plans to add this functionality to ng-openapi-gen for now.
Hi! Sorry but I think the question was not about the params: {...}
part, but about the body: ...
part. Can it be omitted?
I don't want to have an additional nesting level and call service.post({body: ...})
all the time.
Instead, I want to call it as: service.post({param1: ..., param2: ...})
.
And to have the params always as an object is totally fine :)
@luisfpg
Thank you!
@mtuzinskiy In Swagger 2 the body parameters were declared as part of the parameters
array.
In OpenAPI there's a separated requestBody
. It is not a separated parameter.
The generated code includes another parameter called body
for passing in the body parameter.
Remember the request body could be, besides object, a number or a string. And you could have other parameters as well.
What changed in ng-openapi-gen
in relation to ng-swagger-gen
is that there was a setting minParamsForContainer
for the number of parameters to be allowed as individual parameters (default 3). So, if you only had a request body param, you had the object directly.
Now, without this parameter, a parameters interface is always generated, and the name of the body parameter is body
.
So, what you wanted is that setting back minParamsForContainer
, so your generated method would look like: myService.myMethod(obj)
, or myService.myMethod(p1, p2, p3)
instead of myService.myMethod({body: obj})
, or myService.myMethod({queryParam1: p1, queryParam2: p2, body: p3})
.
However, there are no plans for now to add support for an equivalent of minParamsForContainer
in ng-openapi.gen.
You could create a new issue for it, but I don't know if that will be added. Of course, help on that would be appreciated.
Thank you for quick and detailed answer!
As you mentioned,
This made the generation much simpler.
And it's not that very major downside for our team :smile: Thank you very much for your precious work!
This may be a hangup of being a long-time ng-swagger-gen user, but I am confused about the difference between the post parameters of this lib and swagger-gen
Under swagger gen I had a service defined as
compared to openapi-gen
I would prefer not to have to go through the code base and change (in this case)
service.postLogin(options) to service.post(body:options}) if possible
is this just the way it is ?
Thanks