swagger-api / swagger-api/swagger-codegen
swagger-codegen interprets class named "DateTime" as string date-time value and ignores it's schema
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
swagger-codegen contains a hack that interprets class named "DateTime" as DateTime value and ignores it's schema
Swagger-codegen version
3.0.20
Swagger declaration file content or url
dt_test.yml
openapi: 3.0.0
info:
title: DateTime DataObject Test
version: version.version0
components:
schemas:
DateTime:
description: "DateTime test"
type: object
properties: {}
paths:
/test_fail:
summary: "DateTime test"
post:
operationId: DateTimeFail
responses:
'200':
description: success
content:
"application/json":
schema:
$ref: '#/components/schemas/DateTime'
/test_ok:
summary: "DateTime test"
post:
operationId: DateTimeOk
responses:
'200':
description: success
content:
"application/json":
schema:
type: string
format: date-time
Command line used for generation
$ java -jar swagger-codegen-cli.jar generate -l go -i dt_test.yml -o test/go -c swagger.json
$ cat swagger.json
{
"packageName": "main"
}
Steps to reproduce
Create a class named DateTime and use it as a result of an operation. Instead of generating proper model class/structure "date and time" type will be used.
This reproduces for both Java and go binding resulting in sgiantures like
func (a *DefaultApiService) DateTimeFail(ctx context.Context) (time.Time, *http.Response, error) {
public OffsetDateTime dateTimeFail() throws ApiException {
Related issues/PRs
I could not find any
Suggest a fix/enhancement
Remove the hack that interprets DateTime named class into date and time value.
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 provided dt_test.yml and run the swagger-codegen-cli command for the Go and Java bindings. Trace the schema type mapping for the referenced DateTime component, then compare the generated DateTimeFail signatures with the expected model-based output while preserving the explicit string date-time case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100