Skip to content

Fix generation of null type for Option<T>#1468

Open
DanielleHuisman wants to merge 1 commit intojuhaku:masterfrom
DanielleHuisman:fix/option-generics
Open

Fix generation of null type for Option<T>#1468
DanielleHuisman wants to merge 1 commit intojuhaku:masterfrom
DanielleHuisman:fix/option-generics

Conversation

@DanielleHuisman
Copy link
Copy Markdown

Schema

#[derive(ToSchema)]
struct Top {
    bounds: Bounds<i32>,
}

#[derive(ToSchema)]
struct Bounds<T> {
    min: Option<T>,
}

Current behaviour
The Bounds_i32 schema lists min as a non-nullable integer.

{
  "components": {
    "schemas": {
      "Bounds_i32": {
        "type": "object",
        "properties": {
          "min": {
            "type": "integer",
            "format": "int32"
          }
        }
      },
      "Top": {
        "type": "object",
        "required": [
          "bounds"
        ],
        "properties": {
          "bounds": {
            "$ref": "#/components/schemas/Bounds_i32"
          }
        }
      }
    }
  }
}

Expected behaviour
The Bounds_i32 schema should list min as a nullable integer.

{
  "components": {
    "schemas": {
      "Bounds_i32": {
        "type": "object",
        "properties": {
          "min": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "integer",
                "format": "int32"
              }
            ]
          }
        }
      },
      "Top": {
        "type": "object",
        "required": [
          "bounds"
        ],
        "properties": {
          "bounds": {
            "$ref": "#/components/schemas/Bounds_i32"
          }
        }
      }
    }
  }
}

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

Successfully merging this pull request may close these issues.

1 participant