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
  • #10256
Closed
Open
Issue created Aug 25, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [Java] Request parameters examples are invalid and ignore a given spec

Created by: artemitin

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

We use a lot of custom .mustache templates and statements like {{{dataType}}} {{paramName}} = {{{example}}}; We have problems with values produced by {{{example}}} :

  • UUID uuidDefault = new UUID(); - doesn't compile
  • LocalDate dateDefault = new LocalDate(); - doesn't compile
  • String enumInline = "enumInline_example"; - not allowable value for enum
  • OffsetDateTime timeExample = OffsetDateTime.now() - ignores spec example
  • BigDecimal bigNumberExample = new BigDecimal(78); - ignores spec example
openapi-generator version
  • master 5.3.0-snapshot
  • tag 5.2.1

Steps to reproduce

Although we use custom templates, the issue could be reproduced in generated README.md

1. Run generator task with gradle config:

openApiGenerate {
    generatorName = "java"
    inputSpec = "$projectDir/src/main/resources/specWithRequestParams.yaml"
}

The specWithRequestParams.yaml spec: https://gist.github.com/artemitin/5c9646e84019488d9599d16ab47db6ed

2. Navigate to build/generate-resources/main/README.md, see generated request parameters under the public static void main(String[] args) {

3. Expected:

    GeneratorTypeId enumReferenced = GeneratorTypeId.fromValue("serverProject"); // GeneratorTypeId | 
    String enumInline = "available"; // String | 
    List<String> enumInlineArray = Arrays.asList(); // List<String> | 
    Integer integerDefault = 56; // Integer | 
    Integer integerExample = 50; // Integer | 
    String stringDefault = "stringDefault_example"; // String | 
    String stringExample = "hello"; // String | 
    LocalDate dateDefault = LocalDate.now(); // LocalDate | 
    LocalDate dateExample = LocalDate.parse("Sun Jan 01 03:00:00 MSK 2017"); // LocalDate | 
    OffsetDateTime timeDefault = OffsetDateTime.now(); // OffsetDateTime | 
    OffsetDateTime timeExample = OffsetDateTime.parse("2007-12-03T10:15:30+01:00"); // OffsetDateTime | 
    BigDecimal bigNumberDefault = new BigDecimal(78); // BigDecimal | 
    BigDecimal bigNumberExample = new BigDecimal("123456789"); // BigDecimal | 
    UUID uuidDefault = UUID.randomUUID(); // UUID | 
    UUID uuidExample = UUID.fromString("13b48713-b931-45ea-bd60-b07491245960");

4. Actual:

    GeneratorTypeId enumReferenced = GeneratorTypeId.fromValue("serverProject"); // GeneratorTypeId | 
    String enumInline = "enumInline_example"; // String | 
    List<String> enumInlineArray = Arrays.asList(); // List<String> | 
    Integer integerDefault = 56; // Integer | 
    Integer integerExample = 50; // Integer | 
    String stringDefault = "stringDefault_example"; // String | 
    String stringExample = "hello"; // String | 
    LocalDate dateDefault = new LocalDate(); // LocalDate | 
    LocalDate dateExample = new LocalDate(); // LocalDate | 
    OffsetDateTime timeDefault = OffsetDateTime.now(); // OffsetDateTime | 
    OffsetDateTime timeExample = OffsetDateTime.now(); // OffsetDateTime | 
    BigDecimal bigNumberDefault = new BigDecimal(78); // BigDecimal | 
    BigDecimal bigNumberExample = new BigDecimal(78); // BigDecimal | 
    UUID uuidDefault = new UUID(); // UUID | 
    UUID uuidExample = new UUID(); // UUID | 
Suggest a fix
Assignee
Assign to
Time tracking