OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-axios] string property with date-time format results in string instead of Date
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Using typescript-axios generator, I'm getting some undesirable behavior:
For an API with a model property defined as type string with a format of date-time, the generated interface has a type of string instead of Date.
openapi-generator version
@openapitools/openapi-generator-cli: 2.2.6
generator-cli: 5.1.0
OpenAPI declaration file content or url
This yaml
type: object
required:
- timeSlotId
- screeningstationId
- datetime
properties:
timeSlotId:
$ref: "../types/id.yaml"
screeningstationId:
$ref: "../types/id.yaml"
datetime:
type: string
format: date-time
results in
/**
* @export
* @interface TimeSlot
*/
export interface TimeSlot {
/**
* @type {number}
* @memberof TimeSlot
*/
timeSlotId: number;
/**
* @type {number}
* @memberof TimeSlot
*/
screeningstationId: number;
/**
* @type {string}
* @memberof TimeSlot
*/
datetime: string;
}
Generation Details
This is the command used for generation
openapi-generator-cli generate -g typescript-axios -i ..\openapi-spec\openapi.yaml -o .\api
Steps to reproduce
- Have open api document with above defined property in a schema
- Generate typescript-axios
- See output interfaces for undesired results.
Related issues/PRs
This user experienced exactly the behavior that I would assume given my specification. However, he describes it as undesirable behavior. Could it be that the behavior was changed after this issue?
3842 typescript-axios generator string property with date-time format needs to remain a string
Suggest a fix
Add an option to the typescript-axios generator to choose between OpenAPI dates generating variables of datatype string and datatype date in the generated Typescript code.
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 reproducing the typescript-axios generation with the provided YAML and command, then review related issue 3842 to understand the existing date-time behavior. Done means the generator provides a documented choice between string and Date for OpenAPI date-time properties, with generated interfaces reflecting that choice.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100