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

441
Views
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 answers
Answer question

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 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!