refer to properties in $ref get Compilation error in generated class although it is valid swagger yml
From @noha-gamal on February 12, 2019 13:56
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
To reproduce...
Steps to reproduce the behavior:
- Go to 'https://editor.swagger.io/'
- 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
- Found compilation error in class generated.
Expected behavior
expected that id attribute in EligibleProductOfferingVBOProductOffering.java be
private List
Copied from original issue: swagger-api/swagger-ui#5175
I do have also a problem with generating the class name with Swagger-codegen 3.0.5. In my case I have different folders for parameter and definitions. When I'd like to address the $ref from another folder it is combining the full path of the $ref as class attribute:
swagger.yml:
openapi: 3.0.0
...
/alerts/query:
post:
...
requestBody:
$ref: ./parameters/alerts.yml#/AlertsQueryParameter
...
parameters/alerts.yml:
AlertsQueryParameter:
name: alertQueryPayload
content:
application/json:
schema:
$ref: ./definitions/alerts.yml#/AlertsQuery
...
definitions/alerts.yml:
AlertsQuery:
type: object
properties:
pageable:
$ref: "./app.yml#/Pageable"
...
definitions/app.yml:
Pageable:
type: object
properties:
pageNumber:
type: integer
format: int64
pageSize:
type: integer
format: int64
sortingInstructions:
type: array
items:
$ref: '#/SortingInstruction'
required:
- pageNumber
- pageSize
- sorts
The name of the class should be Pageable but it is creating DefinitionsappYmlPageable
@shockey, I'm also facing the similar issue when using swagger-codegen 3.x. Is there any way to overcome this? Compilation Error in the generated code when there is reference in the format:
$ref: '#/components/schemas/entry'
In the generated service code, it imports a class called ComponentsSchemasEntryModel which makes the compilation error.
I am using swagger-codegen-maven-plugin version 3.0.19 with language jaxrs-cxf-cdi