swagger-api / swagger-api/swagger-codegen
[TypeScript] Use interfaces for fetch request parameters
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Request parameters should be in interfaces, same as for general object definitions.
I am using http://swagger.io/specification/#parametersDefinitionsObject and would like to be able to use the typed parameter definitions.
Swagger-codegen version
2.2.1
Swagger declaration file content or url
swagger: '2.0'
paths:
/foo
get:
parameters:
- $ref: '#/parameters/skipParam'
- $ref: '#/parameters/limitParam'
skipParam:
name: skip
in: query
description: number of items to skip
required: true
type: integer
format: int32
limitParam:
name: limit
in: query
description: max records to return
required: true
type: integer
format: int32
Should produce
export interface FooApiParams {
/** number of items to skip */
skip: number;
/** max records to return */
query: number;
}
export class FooApi extends BaseApi {
fooGet(params: FooApiParams) {
...
}
}
instead of what it currently produces:
export class FooApi extends BaseApi {
fooGet(params: { skip: number, limit: number }) {
...
}
}
Command line used for generation
java -jar ${jarPath} generate -i swagger.yaml -l typescript-fetch -o ${dir}
Steps to reproduce
Generate any typescript-fetch api where the swagger file has a parameters object with definitions used in some path.
Related issues
Suggest a Fix
Fixing shouldn't be hard; all the information is already available, this line and the similar lines in the same file could simply be changed to something like
{{nickname}}({{#hasParams}}params: {{nickname}}Params }, {{/hasParams}}options?: any): FetchArgs {
where {{nickname}}Params is defined alongside the regular object definitions with something like
{{#operations}}
{{#operation}}
export interface {{nickname}}Params {
{{#allParams}}
{{paramName}}"{{^required}}?{{/required}}: {{{dataType}}};
{{/allParams}}
{{/operation}}
{{/operations}}
I don't actually know mustache so the above is just a guess based on the existing template!
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 modules/swagger-codegen/src/main/resources/TypeScript-Fetch/api.mustache, especially the referenced operation and object-definition sections. Generate a typescript-fetch API from the supplied Swagger parameters example using the documented command, then verify that the output defines a per-operation params interface and uses it in the API method instead of an inline object type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100