Skip to content

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

Closed

Description

@jeff9finger

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?

Activity

  1. nickcmaynard commented on Jan 27, 2016

    @nickcmaynard
    Contributor

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

  2. nickcmaynard commented on Jan 31, 2016

    @nickcmaynard
    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.

  3. nickcmaynard commented on Jan 31, 2016

    @nickcmaynard
    Contributor

    See PR #1120, #1094.

  4. modified the milestone: v2.3.0 on Jul 7, 2016
  5. wing328 commented on Jul 19, 2016

    @wing328
    Contributor

    @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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions