swagger-api / swagger-api/swagger-codegen
[TypeScript-Fetch] Invalid interface definition while setting additionalProperties as true
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 yaml into a TypeScript-Fetch client results in an interface with an incorrect type.
Specifically when the additionalProperties is set to true.
Swagger-codegen version
SWAGGER_VERSION=3.0.55
Swagger declaration file content or url
Following is an example sample yaml file
/api/v1/classes/{className}:
post:
operationId: op1
tags:
- tag1
parameters:
- name: className
in: path
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
type: object
properties:
prop1:
type: string
prop2:
type: string
additionalProperties: true
For an example let's say we have 2 interfaces
interface Interface1 {
prop1: string,
prop2: string,
}
interface Interface2 {
[key: string]: any;
}
So in this case if I'm not passing additionalProperties flag the interface i.e. getting generated for requestBody is Interface1 else it is Interface2.
But I'm looking for a combination that incorporates elements from both the interfaces.
Command line used for generation
java -jar ./swagger-codegen-cli.jar generate -i ./server/out/example.yaml -l typescript-axios -o ./server/out/api-client --additional-properties modelPropertyNaming=original enumPropertyNaming=original
Steps to reproduce
Compile a swagger API containing the definitions mentioned above into a typescript-fetch client.
Suggest a fix/enhancement
I'm looking for a combination that incorporates elements from both the interfaces.
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 supplied OpenAPI YAML and the Swagger Codegen 3.0.55 generation command, comparing the stated TypeScript-Fetch target with the command's typescript-axios option. Inspect the generated request-body interface and reproduce the incorrect handling of additionalProperties: true. Done means the generated interface retains prop1 and prop2 while also allowing additional string-keyed values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100