Skip to content

Commit

Permalink
[utoipa-gen] MediaTypeAttr: Make parse_named_attributes a method (#1236)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Juha Kukkonen <[email protected]>
  • Loading branch information
jsoo1 and juhaku authored Dec 18, 2024
1 parent f6ac333 commit a502b21
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 @@ -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

0 comments on commit a502b21

Please sign in to comment.