OpenAPITools / OpenAPITools/openapi-generator
[BUG] [typescript-fetch] Invalid handling of date return type
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
If you define the response type of an API to return something of "type":"string" and "format":"date" the generated exposes the value as Date but looking at the source the JSON-Content is used as is and hence the returned value is of type "string".
openapi-generator version
7.22-SNAPSHOT
OpenAPI declaration file content or url
{
"openapi": "3.0.1",
"info": {
"title": "RSD Test",
"version": "1.0.0"
},
"paths": {
"/api/date": {
"get": {
"description": "",
"parameters": [],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "string",
"format": "date"
}
}
}
}
}
}
}
}
}
Generation Details
I generated using
docker run --rm \
-v $PWD:/local openapitools/openapi-generator-cli:latest generate \
-i /local/openapi.json \
-g typescript-fetch --additional-properties=importFileExtension=.js \
-o /local/src
Steps to reproduce
- Run the generator
- Inspect the generated source
The relevant code part generated from above is
async apiDateGetRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Date>> {
const requestOptions = await this.apiDateGetRequestOpts();
const response = await this.request(requestOptions, initOverrides);
if (this.isJsonMime(response.headers.get('content-type'))) {
return new runtime.JSONApiResponse<Date>(response);
} else {
return new runtime.TextApiResponse(response) as any;
}
}
Related issues/PRs
None I'm aware of
Suggest a fix
If the return value is a "Date" a transformer has to be passed so the line should look like
return new runtime.JSONApiResponse<Date>(response, isoDate => new Date(isoDate));
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
Use the supplied OpenAPI declaration and Docker generation command to reproduce the typescript-fetch output. Start at the generated apiDateGetRaw method and the runtime.JSONApiResponse call; done means a date-formatted response is exposed as a Date value rather than the raw JSON string.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100