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

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