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
#16,226 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.