Skip to content

[BUG] [Rust] fails to compile when multiple enum fields are used within discriminator #13020

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

Closed
5 of 6 tasks
aeneasr opened this issue Jul 26, 2022 · 1 comment
Closed
5 of 6 tasks

Comments

@aeneasr
Copy link
Contributor

aeneasr commented Jul 26, 2022

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When using a discriminator:

      "uiNodeAttributes": {
        "discriminator": {
          "mapping": {
            "a": "#/components/schemas/uiNodeAnchorAttributes",
            "img": "#/components/schemas/uiNodeImageAttributes",
            "input": "#/components/schemas/uiNodeInputAttributes",
            "script": "#/components/schemas/uiNodeScriptAttributes",
            "text": "#/components/schemas/uiNodeTextAttributes"
          },
          "propertyName": "node_type"
        },
        "oneOf": [
          {
            "$ref": "#/components/schemas/uiNodeInputAttributes"
          },
          {
            "$ref": "#/components/schemas/uiNodeTextAttributes"
          },
          {
            "$ref": "#/components/schemas/uiNodeImageAttributes"
          },
          {
            "$ref": "#/components/schemas/uiNodeAnchorAttributes"
          },
          {
            "$ref": "#/components/schemas/uiNodeScriptAttributes"
          }
        ],

with a type that has a required enum:

      "uiNodeInputAttributes": {
        "description": "InputAttributes represents the attributes of an input node",
        "properties": {
          // ...
          "autocomplete": {
            "description": "The autocomplete attribute for the input.",
            "enum": [
              "email",
              "tel",
              "url",
              "current-password",
              "new-password",
              "one-time-code"
            ],
            "type": "string"
          },
          "type": {
            "description": "The input's element type.",
            "type": "string",
            "enum": [
              "text",
              "password",
              "number",
              "checkbox",
              "hidden",
              "email",
              "tel",
              "submit",
              "button",
              "datetime-local",
              "date",
              "url"
            ],
          },
          // ...
        },
        "required": [
          // ...
          "type",
          // ...
        ],
        "type": "object"
      },

rust does not compile because the Type enum is missing from the UiNodeAttributes definition. It does exist in the UiNodeInputAttributes definition though! Interestingly, the AutoComplete enum works just fine:

error[E0412]: cannot find type `TypeEnum` in this scope
  --> src/models/ui_node_attributes.rs:66:16
   |
66 |         _type: TypeEnum,
   |                ^^^^^^^^ not found in this scope
   |
help: consider importing one of these items
   |
13 | use crate::models::expand_tree::TypeEnum;
   |
13 | use crate::models::ui_node::TypeEnum;
   |
13 | use crate::models::ui_node_input_attributes::TypeEnum;

If we remove the enum from type, this will work though.

openapi-generator version

5.4.0 to 6.0.1

OpenAPI declaration file content or url

Not working:

https://raw.githubusercontent.com/ory/sdk/master/spec/client/v0.2.0-alpha.3.json

Working:

https://raw.githubusercontent.com/ory/sdk/master/spec/client/v0.2.0-alpha.4.json

Generation Details
#rust yaml
packageName: ${RUST_PACKAGE_NAME}
packageVersion: $VERSION
library: reqwest
supportAsync: true
enumNameSuffix: Enum
  openapi-generator-cli version-manager set 6.0.1
  openapi-generator-cli generate -i "${SPEC_FILE}" \
    -g rust \
    -o "$dir" \
    --git-user-id ory \
    --git-repo-id sdk \
    --git-host github.com \
    -c ./config/client/rust.yml.proc.yml
@aeneasr aeneasr changed the title [BUG] [Rust] fails to compile when enum field is required within discriminator [BUG] [Rust] fails to compile when enum field is used within discriminator Jul 26, 2022
@aeneasr aeneasr changed the title [BUG] [Rust] fails to compile when enum field is used within discriminator [BUG] [Rust] fails to compile when multiple enum fields are used within discriminator Jul 26, 2022
@aeneasr
Copy link
Contributor Author

aeneasr commented Aug 23, 2022

Dupe #13257

@aeneasr aeneasr closed this as completed Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant