OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Java][Spring] Model composition does not work for string type
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
It is sometimes useful to have a base type which is derived from string with all constraints, refer this type using "ref" syntax and change just the description. The problem is that generation does not work correctly for the case shown below. @Size annotation will be not generated as expected.
openapi-generator version
I use 5.0.0-beta2 in my test
OpenAPI declaration file content or url
openapi: 3.0.0
info:
description: test
version: 1.0.0
title: OpenAPI Petstore
license:
name: Apache-2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
paths:
/pet:
post:
description: ''
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
Pet:
title: a Pet
description: A pet for sale in the pet store
type: object
properties:
test1:
allOf:
- $ref: '#/components/schemas/StringMinMax'
- description: "Property one description"
test2:
allOf:
- $ref: '#/components/schemas/StringMinMax'
- description: "Property two description"
StringMinMax:
type: string
minLength: 1
maxLength: 5
Generation Details
java -jar openapi-generator-cli-5.0.0-beta2.jar generate -i petstore.yaml -g spring
Steps to reproduce
- Generate classes
- Look inside Pet class. Size annotations are missing on getters
Related issues/PRs
Suggest a fix
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 by running the provided openapi-generator command with the YAML declaration and inspect the generated Pet class getters. Trace how the Spring generator handles the allOf composition for StringMinMax. Done means the generated getters include the expected @Size constraints for both test1 and test2.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100