swagger-api / swagger-api/swagger-codegen

[Java - Spring refer to properties in $ref get Compilation error in generated class although it is valid swagger yml ]

Open
#9,165 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Q&A (please complete the following information)
  • OS: [e.g. Windows 10 Enterprise]
  • Browser: [e.g. chrome]
  • Version: [e.g. 71.0.3578.98]
  • Method of installation: [use online swagger editor https://editor.swagger.io/]
  • Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0]
Content & configuration

Example Swagger/OpenAPI definition:

swagger: '2.0'
host: api.vodafone.com
basePath: '/{access}/eligibleProductOfferingAPI/v2'
schemes:
  - https
consumes:
  - application/json
produces:
  - application/json
info:
  title: 'Common Service Model API: EligibleProductOffering'
  version: 2.1.0
paths:
  /eligibleProductOffering:
    get:
      tags:
        - eligibleProductOffering
      description: >-
        A method that allows a consumer of the API to get-list a
        EligibleProductOffering representation.
      operationId: getList
      produces:
        - application/json
      responses:
        '204':
          description: '204, No Content.'
definitions:
  eligibleProductOfferingVBOProductOffering:
    properties:
      id:
        type: array
        minItems: 1
        items:
          $ref: '#/definitions/BasicComponents/properties/IDType'
      name:
        type: string
        description: ' The name of the instance of a business object or component.'
  BasicComponents:
    properties:
      IDType:
        type: object
        properties:
          value:
            type: string
            description: The value of the field.
          schemeID:
            type: string
          schemeName:
            type: string
          schemeAgencyName:
            type: string
        required:
          - value
`


### Describe the bug you're encountering

Bug is in class EligibleProductOfferingVBOProductOffering.java get id attribute
  private List<BasicComponentspropertiesIDType> id = null;
where class  BasicComponentspropertiesIDType not found. 
expected attribute id  with type BasicComponentsIDType

### To reproduce...

Steps to reproduce the behavior:
1. Go to 'https://editor.swagger.io/'
2. Paste above yml
4.Click on Generate Server then Spring
5.Spring-server-generated.zip downloaded,  open it and go to  spring-server\src\main\java\io\swagger\model\EligibleProductOfferingVBOProductOffering.java
6. Found compilation error in class generated.

### Expected behavior
expected that id attribute in  EligibleProductOfferingVBOProductOffering.java be
private List<BasicComponentsIDType> id = null;
instead of
private List<BasicComponentspropertiesIDType> id = null;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Swagger 2.0 YAML and reproduce the issue through Swagger Editor's Spring server generation. Inspect the generated spring-server/src/main/java/io/swagger/model/EligibleProductOfferingVBOProductOffering.java and the related generated model type; done means the project compiles and the id field uses BasicComponentsIDType rather than BasicComponentspropertiesIDType.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.