OpenAPITools / OpenAPITools/openapi-generator
spring-boot bad Model name generate in 4.3.1 ver.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
spring-boot library has generated badly Model name for Response Object in API class. It looks like the name is created from last referencing no referenced $ref segment for direct reference, one-of ... It is working correctly for array.
e.g. expect UserDto but it is Model1users1identDto or OneOfUserDto
A change ver. 4.3.0 to 4.3.1 brings that strange behavior.
api.yml
openapi: 3.0.3
info:
title: Spring JPA Sample User API Documentation
version: 1.0.0
servers:
- url: http://localhost:8080/
paths:
/v1/users/{ident}:
$ref: '../services/user-services.yml#/paths/~1users~1{ident}'
/v1/users/{userName}:
$ref: '../services/user-services.yml#/paths/~1users~1{firstName}'
referenced user-services.yml:
openapi: 3.0.3
info: { title: "<FRAGMENT>", version: "<FRAGMENT>" }
tags:
- name: users
description: User Services API
paths:
/users/{ident}:
get:
summary: Get the user by ID
operationId: getUserByIdent
tags:
- users
parameters:
- in: path
name: ident
required: true
schema:
type: string
responses:
200:
description: Return User by ID
content:
application/json:
schema:
$ref: '../components/users.yml#/components/schemas/User'
/users/{firstName}:
get:
operationId: getUserByFirstName
summary: Get the users with firstName
tags:
- users
parameters:
- in: path
name: userName
required: true
schema:
type: string
responses:
200:
description: Returns all found users
content:
application/json:
schema:
type: array
items:
$ref: '../components/users.yml#/components/schemas/User'
referenced users.yml looks like:
openapi: 3.0.3
info: { title: "<FRAGMENT>", version: "<FRAGMENT>" }
paths: { /: { get: { responses: { "418": { description: FRAGMENT } } } } }
components:
schemas:
CreateUserRequest:
title: CreateUserResponse
required:
- username
- password
allOf:
- $ref: '#/components/schemas/User'
- type: object
UserResponse:
title: UserResponse
required:
- id
- username
allOf:
- $ref: '#/components/schemas/User'
- type: object
User:
title: User
description: Object User Base
properties:
id:
type: integer
format: int64
description: Users's identifier
example: 1
dateTest:
type: string
validFrom:
type: string
format: 'date-time'
description: Record is valid from {date}
example: "2017-07-21T17:32:28Z"
# example: "2017-12-09"
userFirstName:
type: string
description: User First Name
example: John
userLastName:
type: string
description: User Last Name
example: Testersen
userMiddleName:
type: string
description: User Middle Name
example: von
userEmail:
type: string
format: email
description: User's email (shold be used for build username)
example: jtestersen@test.com
userName:
type: string
description: User's alias (or login) name
example:
jtestersen or jtestersen@test.com (means e.g. John von Testersen)
password:
type: string
description: User's password for login
example: $tR0nG_pA55vv0Rd
I've add public project for easy and quick reproduction https://github.com/vaclav-demcak/samples/tree/master/spring-jpa
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the public reproduction project at github.com/vaclav-demcak/samples/tree/master/spring-jpa and compare generated Spring Boot output between versions 4.3.0 and 4.3.1. Trace how the referenced api.yml, user-services.yml, and users.yml schemas produce response model names; done when direct and one-of references generate the expected model name rather than Model1users1identDto or OneOfUserDto, while array generation remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring-boot
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100