Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[JAXRS] Format not respected for primitive datatype Definition models #7754

Open
jraylee opened this issue Mar 2, 2018 · 8 comments
Open

Comments

@jraylee
Copy link

jraylee commented Mar 2, 2018

Description

The format for a primitive datatype definition is not respected when referenced from other definitions or responses.

Swagger-codegen version

Originally seen in 2.3.0 but also in master

Swagger declaration file content or url

sample api.yml

swagger: '2.0'
info:
  title: 'Test'
  description:
  version: 0.0.1
  contact:
    name: 'justine'
basePath: /api/

paths:
  /test:
    get:
      operationId: test_operation
      produces:
        - application/json
      parameters: []
      responses:
        '200':
          description: successful operation
          schema:
            $ref: '#/definitions/Test'

definitions:
  Test:
    type: object
    properties:
      Long1:
        $ref: "#/definitions/LongProperty"

      Long2:
        type: integer
        format: int64

  LongProperty:
    type: integer
    format: int64

Generated Test model class (partial)

public class Test   {
  @JsonProperty("Long1")
  private Integer long1 = null;

  @JsonProperty("Long2")
  private Long long2 = null;

  public Test long1(Integer long1) {
    this.long1 = long1;
    return this;
  }
...
}
Command line used for generation

swagger-codegen generate -i api.yml -l jaxrs

Steps to reproduce

Copy paste example api.yml file
Run command line
Go to src/gen/java/io/swagger/model/Test.java and the Long1 field will be an Integer but the Long2 field is a Long.

Suggest a fix/enhancement

The format property should be respected for primitive datatype Definitions.

@jmini
Copy link
Contributor

jmini commented Mar 3, 2018

Thank you for this issue.

I have tested it with 3.0.0-SNAPSHOT with spec in the Swagger v2 und Swagger v3 format.

openapi: 3.0.1
info:
  title: Test
  contact:
    name: justine
  version: 0.0.1
servers:
  - url: /api/
paths:
  /test:
    get:
      operationId: test_operation
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Test'
components:
  schemas:
    Test:
      type: object
      properties:
        Long1:
          $ref: '#/components/schemas/LongProperty'
        Long2:
          type: integer
          format: int64
    LongProperty:
      type: integer
      format: int64

The online editor http://editor.swagger.io/ computes the type correctly.

jmini added a commit to jmini/swagger-codegen-generators that referenced this issue Mar 3, 2018
jmini added a commit to jmini/swagger-codegen-generators that referenced this issue Mar 3, 2018
@jmini
Copy link
Contributor

jmini commented Mar 3, 2018

I have proposed a fix for the 3.0.0-SNAPSHOT version with this Pull Request: swagger-api/swagger-codegen-generators#30

@webron webron assigned HugoMario and unassigned HugoMario Mar 5, 2018
@jmini
Copy link
Contributor

jmini commented Mar 11, 2018

My PR was fixed in the 3.0.0-SNAPSHOT, maybe you can give it a try... (it is possible to use swagger spec in version 2.0 as input)

@jraylee
Copy link
Author

jraylee commented Mar 19, 2018

Thanks! I'll try it out

@jmini
Copy link
Contributor

jmini commented Mar 21, 2018

@webron, @wing328:
Could you add milestone v3.0.0 and following labels: Issue: Bug, Client: Java, Server:Java.

I think that this issue can be closed (unless someone wants to have a look at it for the 2.x version).

@webron
Copy link
Contributor

webron commented Mar 21, 2018

@jmini - I'll leave it up to @wing328 to decide if this should be looked at for 2.x.

@jmini
Copy link
Contributor

jmini commented Mar 21, 2018

@webron: thank you.

My strategy is to move forward with v3 as much as possible. I did a lot of work for that and I hope that my pull requests swagger-codegen and swagger-codegen-generators will be reviewed and merged soon. Having a lot of topics opened in parallel is not that easy for me.

@webron
Copy link
Contributor

webron commented Mar 21, 2018

@jmini Completely respect that. Trust me, we want to push v3 forward as much as possible as well. However, realistically, until a majority of the generators are migrated to v3 and we've made it stable enough, we'll have to support both equally. It's part of the transition period.

By the way, did you get the email I sent you? Just trying to make sure (used the one in your profile).

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants