swagger-api / swagger-api/swagger-codegen-generators
typescript-fetch: unexpected behavior when creating "any" type
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
I want to generate a model with a property that has the "any" type.
According to the OAS 3 spec, "Any Type" can be achieved by omitting the type property. See the section "Any Type" of https://swagger.io/docs/specification/data-models/data-types/
But typescript-fetch produces some unexpected results.
This behavior can be reproduced by modifying the Pet Store example on https://editor.swagger.io and generating the typescript-fetch client. The Pet Store example was converted to OAS 3 first.
For example:
Pet:
type: object
properties:
value:
description: any value
When generating the typescript-fetch client the result is the following:
export interface Pet {
/**
* any value
* @type {ModelObject}
* @memberof Pet
*/
value?: ModelObject;
}
The type ModelObject does not exist and the client can't be used that way.
After some tests I found out, that by adding additionalProperties, the result changes.
Adding additionalProperties: true results in:
export interface Pet {
/**
* any value
* @type {{ [key: string]: any; }}
* @memberof Pet
*/
value?: { [key: string]: any; };
}
Adding additionalProperties: false results in:
export interface Pet {
/**
* any value
* @type {any}
* @memberof Pet
*/
value?: any;
}
Please correct me if I am wrong, but I thought when additionalProperties is omitted, it is treated as if it was present with the value true.
Some additional info: Having a property with any type, the TSOA framework generates the following OAS:
"value": {
"additionalProperties": true
}
Suggestion: If the type is omitted, typescript-fetch should create a property of type any. additionalProperties shouldn't influence the output if no type is provided.
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 by modifying the OAS 3 Pet Store example in editor.swagger.io and generating the typescript-fetch client. Compare output for an omitted type with the cases using additionalProperties true or false. Done means an omitted type generates a usable TypeScript property of type any without an undefined ModelObject reference.
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
- Mostly clear
- Newbie friendliness
- 45/100