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

Allow simple integer enums by rawstring escaping variant names #100

Merged
merged 4 commits into from
Nov 11, 2022
Merged

Conversation

clux
Copy link
Member

@clux clux commented Nov 11, 2022

Addresses enums of the following form:

statusCode:
  default: 302
  description: "StatusCode is the HTTP status
    code to be used in response. \n Support: Core
    \n Note that values may be added to this enum,
    implementations must ensure that unknown values
    will not cause a crash. \n Unknown values
    here must result in the implementation setting
    the Accepted Condition for the Route to `status:
    False`, with a Reason of `UnsupportedValue`."
  enum:
  - 301
  - 302
  type: integer

like the one found in the gateway api's httproute crd (which has been copied as an integration test). Consequently, this pr fixes generation of that CRD.

The relevant generated enum now is output like this:

#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum HTTPRouteRulesFiltersRequestRedirectStatusCode {
    r#_301,
    r#_302,
}

We did not have to worry about discriminants for this (and we can only really guess the discriminant from the name anyway).

There is a commented out unit test here because this exposed a bad logic setup for us in analyze_; we only catch enums that's children of something, so not top-level containers. Issue reported separately; #101

Signed-off-by: clux <sszynrae@gmail.com>
@clux clux linked an issue Nov 11, 2022 that may be closed by this pull request
@clux clux changed the title allow integer enums and escape their names with rawstrings Allow simple integer enums by rawstring escaping variant names Nov 11, 2022
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
@clux clux marked this pull request as ready for review November 11, 2022 06:35
@clux clux merged commit 3b98f29 into main Nov 11, 2022
@clux clux deleted the int-enums branch November 11, 2022 06:41
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

Successfully merging this pull request may close these issues.

not handling non-string enum
1 participant