Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #3908
Closed
Open
Issue created Sep 18, 2019 by Administrator@rootContributor

[BUG] [Java Spring] Illegal date format in generated delegate examples

Created by: j0th

Description

The generated code (generator v4.1.2) for the example responses in an api delegate has illegal date formats for the properties of type "string" and format "date".

public interface DummyApiDelegate {

    default Optional<NativeWebRequest> getRequest() {
        return Optional.empty();
    }

    /**
     * @see DummyApi#dummyGet
     */
    default ResponseEntity<Result> dummyGet() {
        getRequest().ifPresent(request -> {
            for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
                if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
                    ApiUtil.setExampleResponse(request, "application/json", "{  \"attr1\" : \"2019-09-18T00:00:00.000+0000\"}");
                    break;
                }
            }
        });
        return new ResponseEntity<>(HttpStatus.valueOf(200));
    }
}
openapi-generator version

4.1.2

OpenAPI declaration file content or url
openapi: 3.0.2

info:
  title: Test for illegal date format in delegate examples
  version: 1.0.0

paths:
  /dummy:
    get:
      summary: just a dummy
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                  $ref: '#/components/schemas/result'

components:
  schemas:
    result:
      description: the result with the illegal date format
      type: object
      properties:
        attr1:
          type: string
          format: date
          example: "2019-09-18"
Command line used for generation

docker run --rm -v %CD%:/local openapitools/openapi-generator-cli:v4.1.2 generate -i /local/test.yaml -g spring -o /local/testexample -c /local/config-test.json

The config-test.json looks like this:

{
  "library": "spring-boot",
  "delegatePattern": true,
  "returnSuccessCode": true,
  "hideGenerationTimestamp": true
}
Steps to reproduce

Just run the generator, you'll see

Related issues/PRs

Nothing found.

Suggest a fix

Not a fix , but a hint: The generated code have the expected date format:

  • if I use version 3.3.4 of the generator-cli
  • if I remove example: "2019-09-18" from attr1 (best solution for me, because I want to use version 4.x of the generator)
  • if I remove type: string from attr1 (but the the type of the generated getter and setter is just object, not so good)
    /**
     * @see DummyApi#dummyGet
     */
    default ResponseEntity<Result> dummyGet() {
        getRequest().ifPresent(request -> {
            for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
                if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
                    ApiUtil.setExampleResponse(request, "application/json", "{  \"attr1\" : \"2019-09-18\"}");
                    break;
                }
            }
        });
        return new ResponseEntity<>(HttpStatus.valueOf(200));

    }
Assignee
Assign to
Time tracking