swagger-api / swagger-api/swagger-codegen

[general] date examples are converted and output as date-time in generated json

Open
#7,146 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Using yaml input, we among other things also generate json.
Adding an example to a date results in the date being parsed and serialized back to string as date-time

Swagger-codegen version

2.2.3, generator cxf-jaxrs-client

Swagger declaration file content or url

yaml input

swagger: '2.0'
info:
  title: Member
  version: '2.0'
basePath: /education-group/v2
paths:
  /:
    get:
      responses:
        '200':
          description: members
          schema:
            $ref: '#/definitions/Member'
definitions:
  Member:
    type: object
    properties:
      endDate:
        type: string
        format: date
        example: 2117-01-01

json output

        "endDate" : {
          "type" : "string",
          "format" : "date",
          "example" : "2117-01-01T00:00:00.000+0000",
        }
Command line used for generation

swagger-codegen-cli doesn't support json, but html works as well so this seems to be a general problem rather than java or html

java -jar swagger-codegen-cli.jar generate -i input.yaml -l html

Steps to reproduce
  1. save input.yaml from the issue
  2. java -jar swagger-codegen-cli.jar generate -i input.yaml -l html
  3. grep '"endDate"' index.html
    "endDate" : "2117-01-01T00:00:00.000+0000"
Related issues/PRs

N/A

Suggest a fix/enhancement

Either parse and return date as date instead of date-time, or simply treat the example an opaque string.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with input.yaml using swagger-codegen-cli.jar and the cxf-jaxrs-client generator, then inspect the generated index.html output for the endDate example. The fix is complete when the date example remains "2117-01-01" or is represented as a date rather than being converted to date-time.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, yaml
Domain
api, documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.