Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

462
Vistas
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 Respuestas
Responde la pregunta

0

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

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda