Skip to content

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

Merged
wing328 merged 2 commits intoOpenAPITools:masterfrom
gferon:rust-array-enums
Feb 23, 2021
Merged

Rust: Add support for lists (and sets) of enum values#8693
wing328 merged 2 commits intoOpenAPITools:masterfrom
gferon:rust-array-enums

Conversation

@gferon
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

wing328 commented Mar 22, 2021

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.

2 participants