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

M and m are normalized to ident m #821

Open
drahnr opened this issue Jun 4, 2024 · 5 comments
Open

M and m are normalized to ident m #821

drahnr opened this issue Jun 4, 2024 · 5 comments

Comments

@drahnr
Copy link
Contributor

drahnr commented Jun 4, 2024

An externally provided openapi spec file defines

    foo:
      type: object
      properties:
        m:
          type: boolean
          description: small m
        M:
          type: boolean
          description: biiiig M

which generates

    #[derive(Clone, Debug, Deserialize, Serialize)]
    pub struct Foo {
        #[serde(rename = "M")]
        pub m: bool,
        pub m: bool,
    }

which won't compile. The root here is the normalization of the identifiers to be lowercase.

@ahl
Copy link
Collaborator

ahl commented Jun 4, 2024

Oof. Yeah, there's a reason this is issue 1! oxidecomputer/typify#1

What could would you ideally like to see generated?

@drahnr
Copy link
Contributor Author

drahnr commented Jun 4, 2024

I think I'd want to see something like a configurable prefix for disambiguation, or some structural suffix mapping i.e. {orig}_1 or similar. All of them suffer from deferring the collision one level away but doesn't fix the root cause systematically

In a perfect world the upstream would amend the spec, for the particular vendor, that won't happen unfortunately 😕

@drahnr
Copy link
Contributor Author

drahnr commented Jun 5, 2024

Thinking about this some more: What I really want, is a closure (FnMut of some sort) to be passable for ident normalization, which gives a context of some sort if it's going to be a field name, a function name, or struct name.

@ahl
Copy link
Collaborator

ahl commented Jun 12, 2024

Setting aside the mechanism: what code would you like to see generated in this case?

@drahnr
Copy link
Contributor Author

drahnr commented Jun 13, 2024

Setting aside the mechanism: what code would you like to see generated in this case?

    #[derive(Clone, Debug, Deserialize, Serialize)]
    pub struct Foo {
        #[serde(rename = "M")]
        pub m__disambiguation_case_1: bool,
        pub m: bool,
    }

Given that depending on the context, any suffix will risk a collision, that was what motivated the user defined closure for normalization (with a sane default).

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