Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullability of enum missing in openapi spec #194

Open
DevNico opened this issue Dec 31, 2024 · 0 comments
Open

Nullability of enum missing in openapi spec #194

DevNico opened this issue Dec 31, 2024 · 0 comments

Comments

@DevNico
Copy link

DevNico commented Dec 31, 2024

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" }
    ]
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant