OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][SPRING] Openapi generator does not work properly with array example when use 3.1.1 specification format
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
I use openapi generator with spring boot. I have specification of api and i want use 3.1.1 Openapi version. I have a model with arrays and want to provide example.
when I set into spec 3.1.1 version i have a such code in generated files (incorrect):
@Schema(name = "nodes", example = "[{name=Node1}, {name=Node2}, {name=Node3}]", description = "List of nodes in the EventGraph.", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
when i set 3.0.1 version in spec file i have this (correct):
@Schema(name = "nodes", example = "[{\"name\":\"Node1\"},{\"name\":\"Node2\"},{\"name\":\"Node3\"}]", description = "List of nodes in the EventGraph.", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
openapi-generator version
gradle plugin id "org.openapi.generator" version "7.12.0"
generator: spring
OpenAPI declaration file content or url
openapi: 3.1.1
info:
title: EventGraph API
version: 1.0.0
paths:
/simplePost:
post:
summary: Simple post request
description: description
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/SomeDTO'
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/SomeDTO"
components:
schemas:
SomeDTO:
type: object
properties:
name:
type: string
nodes:
description: List of nodes in the EventGraph.
type: array
items:
$ref: '#/components/schemas/NodeDTO'
example:
- name: Node1
- name: Node2
- name: Node3
NodeDTO:
type: object
properties:
name:
type: string
required:
- name
Generation Details
generator - spring
openApiGenerate {
generatorName = "spring"
inputSpec = "${project.projectDir}/src/main/resources/error-test.yml".replace("\\","/")
outputDir = "${buildDir}/generated"
apiPackage = "pro.axenix_innovation.axenapi.web.api"
modelPackage = "pro.axenix_innovation.axenapi.web.model"
configOptions = [
useSpringBoot3: "true",
interfaceOnly: "true",
useTags: "true",
generateBuilders: "true",
generatedConstructorWithRequiredArgs: "true",
generateConstructorWithAllArgs: "true"
]
}
Steps to reproduce
Use my specification(i thing any spec with array example). Use gradle plugin with specification in the issue
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
Reproduce the issue with the supplied 3.1.1 specification and the Spring generator configuration, then compare it with the 3.0.1 output. Trace how the array example is converted into the generated Java @Schema annotation. Done means the 3.1.1 output preserves the JSON object syntax shown by the 3.0.1 output and the relevant generator tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100