Skip to content

Generate java model sub classes without the fields from the base class. #1556

New issue

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

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

Already on GitHub? Sign in to your account

Closed
jeff9finger opened this issue Nov 11, 2015 · 4 comments
Closed

Comments

@jeff9finger
Copy link

Is there a way to generate the model java classes that do not contain the fields and getters/setters for the base class?

For example:

swagger file model:

    definitions:
      TractPage:
        type: object
        x-swagger-router-model: com.gotransverse.tract.api.billing.dto.TractPage
        #x-swagger-router-model: TractPage
        required:
        - page_num
        - page_size
        properties:
          page_num:
            description: The page number of this page of the collection
            type: integer
            format: int32
            example: 1
          page_size:
            description: The page size of this page of the collection
            type: integer
            format: int32
            example: 50
          num_elements:
            description: The number of elements in this page of the collection
            type: integer
            format: int32
            example: 1
          total_num:
            description: The total number of elements in the complete collection
            type: integer
            format: int32
            example: 100
          links:
            description: The list of HATEOAS links for the page
            type: array
            items:
              $ref: '#/definitions/Link'

      PersonsPage:
        description: A page for person
        x-swagger-router-model: com.gotransverse.tract.api.billing.dto.PersonsPage
        #x-swagger-router-model: PersonsPage
        allOf:
        - $ref: '#/definitions/TractPage'
        - type: object
          required:
          - people
          properties:
            people:
              description: The list of people in this page
              type: array
              items:
                $ref: '#/definitions/Person'

The Java classes that get generated look like:

public class Page  {
  private Integer pageNum = null;
  private Integer pageSize = null;
  private Integer numElements = null;
  private Integer totalNum = null;
  private List<Link> links = new ArrayList<Link>();
 ...
}

public class PersonsPage extends Page {
  private Integer pageNum = null;
  private List<Link> links = new ArrayList<Link>();
  private Integer numElements = null;
  private List<Person> people = new ArrayList<Person>();
  private Integer pageSize = null;
  private Integer totalNum = null;
  ...
}

The PersonsPage class should not have the fields that are contained in the Page class - at least in the default case.

Is this by design? Or is this a defect?

@nickcmaynard
Copy link
Contributor

+1. This used to work without duplicating fields. Problem seems to have been introduced with the refactor of the JaxRS server codegen.

@nickcmaynard
Copy link
Contributor

And, of course, causes some unpredictable problems as you'd expect when properties are overriden in Java subclasses. This can cause potentially serious bugs.

@nickcmaynard
Copy link
Contributor

See PR #1120, #1094.

@wing328
Copy link
Contributor

wing328 commented Jul 19, 2016

@cbornet PR (#3393) has been merged into master. Please pull the latest to give it a try.

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

No branches or pull requests

3 participants