Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

385
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda