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

[BUG][Rust] Serde tag of enum has different identifier than specified in spec #14745

Closed
5 of 6 tasks
NickUfer opened this issue Feb 18, 2023 · 0 comments · Fixed by #14746
Closed
5 of 6 tasks

[BUG][Rust] Serde tag of enum has different identifier than specified in spec #14745

NickUfer opened this issue Feb 18, 2023 · 0 comments · Fixed by #14746

Comments

@NickUfer
Copy link
Contributor

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

The rust generator contains this piece of code

// TODO: figure out how to properly have the original property type that didn't go through toVarName
String vendorExtensionTagName = cm.discriminator.getPropertyName().replace("_", "");
cm.vendorExtensions.put("x-tag-name", vendorExtensionTagName);
cm.vendorExtensions.put("x-mapped-models", discriminatorVars);

The replace("_", "") alters the name of the tag which is used to figure out the type of enums and makes it incompatible with the api which implements the openapi spec.

Here an example output of the API

{
  "type": "input",
  "group": "default",
  "attributes": {
    "name": "identifier",
    "type": "text",
    "value": "",
    "required": true,
    "disabled": false,
    "node_type": "input"
  },
  "messages": [],
  "meta": {
    "label": {
      "id": 1070004,
      "text": "ID",
      "type": "info"
    }
  }
}

Here is what the generator generates

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "nodetype")] 
pub enum UiNodeAttributes {
    #[serde(rename="a")]
    UiNodeAnchorAttributes {
        /// The link's href (destination) URL.  format: uri
        #[serde(rename = "href")]
        // true, false, , String, false
        href: String,
        /// A unique identifier
        #[serde(rename = "id")]
        // true, false, , String, false
        id: String,
        #[serde(rename = "title")]
        // true, false, , crate::models::UiText, true
        title: Box<crate::models::UiText>,
    },
    #[serde(rename="img")]
    UiNodeImageAttributes {
        /// Height of the image
        #[serde(rename = "height")]
        // true, false, , i64, false
        height: i64,
    // ...

In the second line, #[serde(tag = "nodetype")] is wrong, it should be #[serde(tag = "node_type")], but it isn't because of the replacement.

Here is where mustache inserts the wrong value

#[serde(tag = "{{{vendorExtensions.x-tag-name}}}")]

openapi-generator version

6.3.0

OpenAPI declaration file content or url

https://github.com/ory/sdk/blob/master/spec/kratos/v0.11.1.json

Generation Details
packageName: ${RUST_PACKAGE_NAME}
packageVersion: $VERSION
library: reqwest
supportAsync: true
enumNameSuffix: Enum
Steps to reproduce
Related issues/PRs
Suggest a fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant