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

443
Vistas
Swagger bitwise enum flags handling

I have an enum like;

[Flags]
public enum MeteoType : ushort
{
    Wind = 1 << 0,
    Pressure = 1 << 1,
    Temperature = 1 << 2,
    Waves = 1 << 4,
    Currents = 1 << 9,
    Swell = 1 << 13,
    WindWave = 1 << 14,
}

and I have a model;

public class Params
{
    public List<MeteoType> Meteo { get; set; } = new List<MeteoType>()
    {
        MeteoType.Wind
    };
    ....
}

In my controller method, I ask for this model from query as such;

public async Task<IActionResult> Get(int z, int x, int y, [FromQuery] Params parameters)

Which gives me this view in swagger:

enter image description here

I'm using List because it's a flag and I want to be able to choose multiple elements. The problem starts here. When I choose multiple elements the link is created like:

https://localhost:44311?Meteo=1&Meteo=2&Meteo=4&...

rather than

https://localhost:44311?Meteo=7&...

How can I make it so that link is generated by sum of enum values, rather than all of them one by one?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

OpenAPI Specification does not support bitwise enum parameters. Your Meteo parameter needs to be defined as just type: integer in the OpenAPI definition, i.e. you need to tweak the annotations so that they produce type: integer instead of type: array for this parameter. The consumers will need to provide the correct summed value manually.

# OpenAPI definition generated from the code

openapi: 3.0.0
...

paths:
  /something:
    get:

      parameters:
        - in: query
          name: Meteo
          schema:
            type: integer
          example: 7
          description: >-
            One of the following values, or a sum of multiple values:

             * 1 - Wind
             * 2 - Pressure
             * ...

            For example, 7 means Wind (1) + Pressure (2) + Temperature (4).

Alternatively, you can try forking Swagger UI and change the code to send the selected list values as a single summed value instead of multi-value parameter.

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