swagger-api / swagger-api/swagger-codegen
Add default headers for every request in generated api (typescript-fetch)
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Code-gen language: typescript-fetch
In Configuration I can only set the following attributes:
export interface ConfigurationParameters {
apiKey?: string | ((name: string) => string);
username?: string;
password?: string;
accessToken?: string | ((name: string, scopes?: string[]) => string);
basePath?: string;
}
But adding a set of default headers would be nice, currently I have to add this always when calling the api operation:
let requestHeaders: any = {
'Accept': 'application/json',
'Content-Type': 'application/json'
};
myApi.myOperation(myParam1, myParam2, requestHeaders)
.then(...);
I saw that there were some investigations in Go language but not in typescript-fetch.
With the current situation I have to wrap each operation in a separate service api class, which is not so nice (especially to maintain these operations etc.)
Is there a way?
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 by locating the typescript-fetch Configuration definition and the generated operation request path. Add a configurable set of default headers that applies to every generated request, then verify that callers no longer need to pass the same headers to each operation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100