Skip to content

Commit

Permalink
[utoipa-gen] MediaTypeAttr: Make parse_named_attributes a method
Browse files Browse the repository at this point in the history
Using &mut self - since it was already doing this.
  • Loading branch information
jsoo1 committed Dec 17, 2024
1 parent 88e86e9 commit 3cff779
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
1 change: 1 addition & 0 deletions utoipa-gen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changed

* Simplified `ToTokensDiagnostics` for `request_body` (https://github.com/juhaku/utoipa/pull/1235)
* Make `parse_named_attributes` a method of `MediaTypeAttr` (https://github.com/juhaku/utoipa/pull/1236)

### Fixed

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

0 comments on commit 3cff779

Please sign in to comment.