swagger-api / swagger-api/swagger-core

Explicit schema type specified on `@Parameter` annotation is always ignored

Open
#4,763 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
Dominant language
Java
Stars
7.5k
Forks
2.3k
Avg merge
18h 1m
Merged PRs (30d)
10

Description

I am accepting a query parameter within an object in an opaque form so that I can apply Jakarta validation constraints to it, rather than failing to create the object at all and generating a useless message about dependency injection not being able to build the object.

I'm declaring a query parameter as a String and then parsing it later, as follows:

    @PositiveOrZero
    @Parameter(description = "The offset at which to list items", schema = @Schema(type = "integer", format = "int32"))
    @QueryParam(OFFSET)
    public String offset;

Despite this, the schema for the query parameter continues to have string as its type:

      parameters:
      - name: offset
        in: query
        description: The offset at which to list items
        schema:
          type: string  # should be type: integer
          format: int32

Using schema = @Schema(implementation = Integer.class) also fails to attach the correct type to the query parameter.

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 by tracing how the @Parameter and nested @Schema annotations are processed for query parameters. Reproduce the example and verify that an explicit schema type or implementation is preserved instead of being replaced by the Java field type; done means the generated OpenAPI schema reports offset as an integer with format int32.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.