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

[utoipa-gen] MediaTypeAttr: Make parse_named_attributes a method #1236

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions utoipa-gen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Changed

* Make `parse_named_attributes` a method of `MediaTypeAttr` (https://github.com/juhaku/utoipa/pull/1236)
* Use a re-exported `serde_json` dependency in macros instead of implicitly requiring it as dependency in end projects (https://github.com/juhaku/utoipa/pull/1243)
* Simplified `ToTokensDiagnostics` for `request_body` (https://github.com/juhaku/utoipa/pull/1235)
* `Info::from_env()` sets `License::identifier` (https://github.com/juhaku/utoipa/pull/1233)
Expand Down
6 changes: 3 additions & 3 deletions utoipa-gen/src/path/media_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,20 @@ impl<'m> MediaTypeAttr<'m> {
}

pub fn parse_named_attributes(
media_type: &mut MediaTypeAttr,
&mut self,
input: ParseStream,
attribute: &Ident,
) -> syn::Result<()> {
let name = &*attribute.to_string();

match name {
"example" => {
media_type.example = Some(parse_utils::parse_next(input, || {
self.example = Some(parse_utils::parse_next(input, || {
AnyValue::parse_any(input)
})?)
}
"examples" => {
media_type.examples = parse_utils::parse_comma_separated_within_parenthesis(input)?
self.examples = parse_utils::parse_comma_separated_within_parenthesis(input)?
}
// // TODO implement encoding support
// "encoding" => (),
Expand Down
13 changes: 5 additions & 8 deletions utoipa-gen/src/path/request_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,11 @@ impl Parse for RequestBodyAttr<'_> {
request_body_attr.description = Some(parse::description(&group)?);
}
_ => {
MediaTypeAttr::parse_named_attributes(
request_body_attr
.content
.get_mut(0)
.expect("parse request body named attributes must have media type"),
&group,
&ident,
)?;
request_body_attr
.content
.get_mut(0)
.expect("parse request body named attributes must have media type")
.parse_named_attributes(&group, &ident)?;
}
}

Expand Down
11 changes: 5 additions & 6 deletions utoipa-gen/src/path/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,12 @@ impl<'r> ResponseValue<'r> {
self.links = parse_utils::parse_comma_separated_within_parenthesis(input)?;
}
_ => {
MediaTypeAttr::parse_named_attributes(
self.content.get_mut(0).expect(
self.content
.get_mut(0)
.expect(
"parse named attributes response value must have one media type by default",
),
input,
attribute,
)?;
)
.parse_named_attributes(input, attribute)?;
}
}
Ok(())
Expand Down
Loading