Skip to content

Nullability of enum missing in openapi spec #194

Open
@DevNico

Description

Problem

Given the following smithy model:

$version: "2.0"

namespace api

use alloy#nullable

enum MyEnum {
  CASE_1
  CASE_2
}

structure MyDto {
  @nullable
  enum: MyEnum
}

We get the following openapi defintion

{
  "MyDto": {
      "type": "object",
      "properties": {
          "enum": {
              "$ref": "#/components/schemas/MyEnum"
          }
      }
  },
  "MyEnum": {
      "type": "string",
      "enum": [
          "CASE_1",
          "CASE_2"
      ]
  }
}

In the spec the nullability of the enum is missing. This happens because $ref and nullable are incompatible.

Proposed solution

Generate the spec using oneOf e.g.

{
  "enum": {
    "oneOf": [
      { "$ref": "#/components/schemas/MyEnum" },
      { "type": "null" }
    ]
  }
}

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions