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

386
Vistas
Nullable enum parameter in C# code generated from OpenAPI v3 yml

The title is too stuffed and rather confusing, so here is a snippet of my yml:

openapi: 3.0.2
...
paths:
  /whatever:
    get:
      tags:
      - hi
      parameters:
      - name: status
        in: query
        schema:
          $ref: '#/components/schemas/Status'
  responses:
    200:
      description: Successful operation
...
components:
  schemas:
    Status:
      type: string
      enum:
      - One
      - Two

I have a enum that I want to reuse, so I use in multiple places, so I use $ref. The problem here is that if I generate c# code from this spec it will look like this:

public void WhateverGet (Status status = null)
{
     WhateverGetWithHttpInfo(status);
}

This code cannot be compiled, status must be nullable, so I want the generated code to be Status? status = null, and this is where I get stuck.

$ref does not allow any sibling values, so I cannot do something like nullable: true. I was trying to use anyOf and provide my enum OR null as options, but generated code came out even worse.

How can I define my yml so the generated code is correct and I my method has an optional parameter status?

over 4 years ago · Santiago Trujillo
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