OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][SPRING-BOOT] How to describe endpoint 'users/{id}' in openapi 3.0 if id could be either number either uuid?
Open
Nobody has claimed this yet.
Issue: Bug
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
I have following schema:
/users/{id}:
get:
tags:
- User
operationId: getParticularUser
summary: Returns a user by id or by uuid
parameters:
- name: id
required: true
in: path
schema:
oneOf:
- $ref: '#/components/schemas/UserID'
- $ref: '#/components/schemas/UserGuid'
...
components:
schemas:
UserID:
type: integer
example: 1488
UserGuid:
type: string
format: uuid
example: acc84651-8913-4c6c-b3b6-7562b1344843
The generated code is:
@RequestMapping(
method = RequestMethod.GET,
value = "/users/{id}",
produces = { "application/json" }
)
ResponseEntity<UserDto> retrieveUser(
@Parameter(name = "id", description = "", required = true, in = ParameterIn.PATH) @PathVariable("id") GetParticularUserIdParameterDto id
);
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2023-07-31T15:59:31.035932800+03:00[Europe/Moscow]")
public interface GetParticularUserIdParameterDto {
}
The problem here that GetParticularUserIdParameterDto interface has no implementation so I can't implement this interface.
Is there way to fix it ?
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 OpenAPI schema in the issue and the generated SpringCodegen output for GetParticularUserIdParameterDto. Reproduce the generation and inspect how a path parameter using oneOf is represented; done means the generated Spring interface exposes a usable parameter type or clearly documents the limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring-boot
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100