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

Rust: Add support for lists (and sets) of enum values #8693

Merged
merged 2 commits into from
Feb 23, 2021

Conversation

gferon
Copy link
Contributor

@gferon gferon commented Feb 12, 2021

For a field described like:

matrixAttributes:
  type: array
  uniqueItems: true
  items:
    type: string
    enum: ["travelTimes", "distances"]
  default: ["travelTimes"]

the generated field in Rust would not be correct and was:

#[serde(rename = "matrixAttributes", skip_serializing_if = "Option::is_none")]
pub matrix_attributes: Option<MatrixAttributes>,

with this patch, it is now correctly wrapped in a collection, depending on whether uniqueItems is set or not:

For a list:

#[serde(rename = "matrixAttributes", skip_serializing_if = "Option::is_none")]
pub matrix_attributes: Option<Vec<MatrixAttributes>>,

For a set:

#[serde(rename = "matrixAttributes", skip_serializing_if = "Option::is_none")]
pub matrix_attributes: Option<std::collections::HashSet<MatrixAttributes>>,

cc @frol (2017/07) @farcaller (2017/08) @richardwhiuk (2019/07) @paladinzh (2020/05) for review

@wing328
Copy link
Member

wing328 commented Feb 14, 2021

  type: array
  uniqueItems: true

@gferon thanks for the PR. Are we on the same page that this is a set instead of array?

I've not checked if we have correctly mapped this to a proper set type in Rust in the generator.

@gferon
Copy link
Contributor Author

gferon commented Feb 14, 2021

@wing328 great catch! you're absolutely right, I've added a test for {{#uniqueItems}} now to support both sets and lists of enum values.

@gferon gferon changed the title Add support for arrays of enums for Rust Rust: Add support for lists (and sets) of enum values Feb 14, 2021
@wing328 wing328 added this to the 5.1.0 milestone Feb 23, 2021
Copy link
Member

@wing328 wing328 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally and the result is good.

@wing328 wing328 merged commit a7c6ecc into OpenAPITools:master Feb 23, 2021
@wing328
Copy link
Member

wing328 commented Mar 22, 2021

@gferon thanks for the PR, which has been included in the v5.1.0 release: https://twitter.com/oas_generator/status/1373636654024380423

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants