3

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?

user3272018
  • 2,309
  • 5
  • 26
  • 48

0 Answers0