swagger-api / swagger-api/swagger-codegen
[TypeScript-Fetch] Invalid interface definition when using additionalProperties
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Compiling the following spec into a TypeScript-Fetch client results in invalid code.
Specifically, the generated code contains
export interface GenericMap extends null<String, number> {
}
which the TypeScript compiler rejects.
Swagger-codegen version
I tested it on 2.2.1 (latest stable) and 2.3.0 (7aebcfa).
Swagger declaration file content or url
...
definitions:
GenericMap:
additionalProperties:
type: integer
Container:
type: object
properties:
works:
type: object
additionalProperties:
type: string
breaks:
$ref: "#/definitions/GenericMap"
Command line used for generation
swagger-codegen generate -i test.yaml -l typescript-fetch
Steps to reproduce
Compile a swagger API containing the definitions mentioned above into a typescript-fetch client.
Suggest a Fix
The Container type shows that additionalProperties are correctly handled in some cases (when used for the anonymous type of the works member), but not when they are used for a type which is basically a map. I believe it would be sufficient to emit the following type, without inheriting from any other type:
export interface GenericMap {
[key: string]: number;
}
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
Reproduce the issue with the provided YAML and the swagger-codegen generate -i test.yaml -l typescript-fetch command, then trace the typescript-fetch generator's handling of named schemas with additionalProperties. The work is done when the generated GenericMap is valid TypeScript and the generated client compiles without the null<String, number> interface error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100