Skip to content

[bug]: Array items with a string enum are generated as String, not an enum #33

Description

@playwmadness

Version or commit

0.6.0

Affected area

Generated models

Minimal OpenAPI fragment

{
  "openapi": "3.1.0",
  "info": { "title": "repro", "version": "1.0.0" },
  "paths": {
    "/profile": {
      "get": {
        "operationId": "getProfile",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "languages": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "enum": ["EN", "ES"]
                          }
                        },
                        { "type": "null" }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Configuration and command

[generator]
spec_path = "repro.json"
output_dir = "src/generated"
module_name = "api"

[features]
enable_async_client = true


`openapi-to-rust generate`

Actual behavior

In types.rs, languages are String types:

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct GetProfileResponse {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub languages: Option<Vec<String>>,
}

Expected behavior

languages are enum type:

#[derive(...)]
pub enum Whatever {
    #[serde(rename = "EN")] En,
    #[serde(rename = "ES")] Es,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct GetProfileResponse {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub languages: Option<Vec<Whatever>>,
}

Environment

cargo install --locked

Checks

  • I removed credentials and private API data.
  • I searched existing issues for this behavior.
  • This is not a security vulnerability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions