Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

468
Views
Swagger Annotation for enum as a component

I have an enum:

public enum UserType {
  ADMIN("Admin"),
  GUEST("Guest"),
  SUPERVIOR("Supervisor"),
  NORMAL("Normal");

  private final String type;

  UserType(final String type) {
    this.type = type;
  }

And I'm using it as a query parameter with Swagger annotation:

@GET
@AsyncTimed
@Path("/all")
void all(
    @ApiParam @PathParam(USER_ID) @Parameter(in = ParameterIn.PATH, name = USER_ID, required = true) final UserId userId,
    @QueryParam(TYPES) final Set<UserType> userTypes,
    @Suspended final AsyncResponse asyncResponse
);

The generated OpenAPI file, however, is not creating a component out of the enum and instead is giving:

get:
  parameters:
  - name: UserId
    in: path
    required: true
    schema:
      $ref: '#/components/schemas/UserId'
  - name: Types
    in: query
    schema:
      uniqueItems: true
      type: array
      items:
        type: string
        enum:
          - ADMIN
          - GUEST
          - SUPERVISOR
          - NORMAL

Is there a way to make the enum a component schema instead? If I use this enum in other components, those components also use enum: instead of a $ref.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to annotate the enum and/or the corresponding parameter with @Schema(..., enumAsRef=true).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!