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

Support for rust type aliases #787

Open
ilha opened this issue Oct 27, 2023 · 1 comment
Open

Support for rust type aliases #787

ilha opened this issue Oct 27, 2023 · 1 comment

Comments

@ilha
Copy link

ilha commented Oct 27, 2023

Perhaps there's a way already to workaround this, I just could not find it.

I'm working on a code generator for Redfish schemas that produces some code like this:

#[derive(Deserialize, Serialize, ToSchema, Builder, Clone, Debug)]
#[builder(setter(strip_option))]
#[builder(build_fn(error = "ModelBuildError"))]
pub struct IPv6Address {
    /// The IPv6 address.
    #[serde(rename = "Address")]
    #[builder(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub address: Option<String>,

    // ... other stuff
    /// The IPv6 address prefix Length.
    #[serde(rename = "PrefixLength")]
    #[builder(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prefix_length: Option<PrefixLength>,              ///// <<<<< NOTICE THE USAGE OF PrefixLength here
}

The PrefixLength is generated as this:

pub type PrefixLength = i32;

When I generate the swagger-ui, there's this error for types like that:

Resolver error at paths./redfish/v1/Managers/{manager_id}/EthernetInterfaces/{ifc_id}.get.responses.200.content.application/json.schema.items.properties.IPv6StaticAddresses.items.properties.PrefixLength.$ref
Could not resolve reference: Could not resolve pointer: /components/schemas/PrefixLength does not exist in document

As it's an alias to a primitive type, I can't put the #[derive(ToSchema)] on it.

I could create the aliases as struct wrappers, but it would be a bit of a hassle to use it.

I'm about to change my codegenerator to do some lookup for aliases and translate it directly in the struct definition, but decided to check if there's another option available.

Thank you.

@juhaku
Copy link
Owner

juhaku commented Oct 31, 2023

I belive that this is related to this issue that is actually quite popularly asked in Github Issues. #790 (comment)

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

No branches or pull requests

2 participants