Skip to content

Optional enum property not marked as nullable in generated OAS #33

Description

@barnabashomola

Hi,

I have an enum that looks like the one below. The package correctly generates it as a schema and uses the $ref in the enclosing struct.

However, in the enclosing struct, the enum property is optional, so it should be marked as nullable in the OpenAPI specification — but that’s not the case.
Am I doing something wrong?

For comparison, the other optional properties in the struct (that are not $refs) are correctly marked as nullable.

Enum:

import SwiftOpenAPI

enum TestEnum: String, CaseIterable {
    case testA = "TestA"
    case testB = "TestB"
}

extension TestEnum: OpenAPIType {
    static var openAPISchema: SchemaObject {
        .enum(of: .string, cases: allCases.map { .string($0.rawValue) })
            .with(\.description,
                  """
                    - "TestA": Description for TestA.
                    - "TestB": Description for TestB.
                  """)
    }
}

Struct that uses it:

import Vapor
import VaporToOpenAPI

struct TestStruct: Content {
    var boolProp: Bool?
    var enumProp: TestEnum?
}

Relevant OAS output:

"boolProp": {
  "type": "boolean",
  "nullable": true
},
"enumProp": {
  "$ref": "#/components/schemas/TestStruct"
},

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions