swagger-api / swagger-api/swagger-codegen
[typescript-angular] Pass parameters in an object
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I generated my first client and was disappointed to get a method with 15 arguments. This seems like it should be a single object conforming to an interface. It would be especially helpful when you have many optional arguments that you only want to pass one value for. It would also be less error prone if arguments were added, removed, or reordered.
Obviously this would break compatibility. And to be honest it's probably undesirable to people with services taking only a couple parameters. So it would need to be either an option or a second method. I like the idea of an option for code size and simplicity but a second method would allow flexibility for those calling the client.
I'm working on a change myself but would like feedback before submitting a pull request. The output looks like this:
namespace API.Client {
'use strict';
interface IresourcesGetParams {
/** This is a required parameter */
requiredParam: string;
/** This is an optional parameter */
optionalParam?: string;
}
export class DefaultApi {
...
/**
* Retrieve a list of resources
* @param params Parameters.
*/
public resourcesGet (params: IresourcesGetParams, extraHttpRequestParams?: any) : ng.IHttpPromise<ResponseModel> {
- The interface and params argument wouldn't be present if there are no parameters.
- IresourcesGetParams should be IResourcesGetParams but I'm not sure the best way to go about that since I'm just grabbing the nickname.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TypeScript Angular generator entry point and compare its current generated method signatures with the example output in this issue. Determine whether the change should be an option or a second method, then ensure parameter interfaces use the intended capitalization and that generated clients preserve the stated compatibility behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100