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

Add Discriminator mapping #752

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions utoipa/src/openapi/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ pub struct Discriminator {
/// Defines a discriminator property name which must be found within all composite
/// objects.
pub property_name: String,

// An object to hold mappings between payload values and schema names or references.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change this to triple slash and expand the comment so it is more suitable for public documentation?
It needs to state that it can only be populated manually - i.e. there is no macro support, and there is no validation of the mapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I edited the comment and added a test here: c2834c5

#[serde(skip_serializing_if = "BTreeMap::is_empty", default)]
pub mapping: BTreeMap<String, String>,
}

impl Discriminator {
Expand All @@ -299,6 +303,7 @@ impl Discriminator {
pub fn new<I: Into<String>>(property_name: I) -> Self {
Self {
property_name: property_name.into(),
mapping: BTreeMap::new(),
}
}
}
Expand Down