OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA] When adding examples for parameters in the openApi definition this is not added to the delegate interface.
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
When adding examples of usages of parameters, the code is not copied to the interface of the delegate.
openapi-generator version
Version: 6.2.1
OpenAPI declaration file content or url
Size:
in: query
name: size
required: false
schema:
type: integer
description: size of the page
Page:
in: query
name: page
required: false
schema:
type: integer
description: page number
Sort:
in: query
name: sort
required: false
explode: false
schema:
type: array
items:
type: string
description: sort by field and direction (asc or desc)
examples:
simple-default-order:
value: [ companyName ]
summary: Sort by companyName in ascending order
simple:
value: [ companyName,desc ]
summary: Sort by companyName in descending order
multiple:
value: [ companyName,asc,companyStatus,desc ]
summary: Sort by companyName in ascending order and companyStatus in descending order
wrong:
value: [ companyName,companyStatus,asc,desc ]
summary: WRONG - Sort by fields and then all directions
Generation Details
The output has nothing related to the examples
default ResponseEntity<FooEntityDto> getAllFooEntity(
@Parameter(name = "size", description = "size of the page") @Valid @RequestParam(value = "size", required = false) Integer size,
@Parameter(name = "page", description = "page number") @Valid @RequestParam(value = "page", required = false) Integer page,
@Parameter(name = "sort", description = "sort by field and direction (asc or desc)" @Valid @RequestParam(value = "sort", required = false) List<String> sort
) {
return getDelegate().getAllCompanyRegistrations(size, page, sort);
}
Expected something like this to be generated.
default ResponseEntity<FooEntityDto> getAllFooEntity(
@Parameter(name = "size", description = "size of the page") @Valid @RequestParam(value = "size", required = false) Integer size,
@Parameter(name = "page", description = "page number") @Valid @RequestParam(value = "page", required = false) Integer page,
@Parameter(name = "sort",
description = "sort by field and direction (asc or desc)",
examples = {
@ExampleObject(name="simple-default-order", summary = "Sort by companyName in ascending order", value = "[companyName]"),
@ExampleObject(name="simple", summary = "Sort by companyName in descending order", value = "[companyName,desc]"),
@ExampleObject(name="multiple", summary = "Sort by companyName in ascending order and companyStatus in descending order",
value = "[companyName,asc,companyStatus,desc]"),
@ExampleObject(name="wrong", summary = "WRONG - Sort by fields and then all directions",
value = "[companyName,companyStatus,asc,desc]")
})
@Valid @RequestParam(value = "sort", required = false) List<String> sort
) {
return getDelegate().getAllCompanyRegistrations(size, page, sort);
}
To match the output of the original openApi UI output form the definition:

And not something like this, based on the JAVA code generated:

Steps to reproduce
Create a component parameter, that contain an example or examples, and review the definition of Api interface to see if the code there has none of elements example or examples defined in the Swagger file.
Related issues/PRs
I not found anything similar or related.
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 provided OpenAPI parameter declaration and inspect Java delegate-interface generation, starting with how parameter examples are handled. Done means the generated delegate interface includes the parameter examples as annotation metadata, matching the expected Java output, with regression coverage for the supplied case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100