Skip to content

Commit

Permalink
Format and add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
juhaku committed May 14, 2024
1 parent 06c1af2 commit d1b2f17
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
19 changes: 10 additions & 9 deletions utoipa-gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ use self::{
/// where super type declares common code for type aliases.
///
/// In this example we have common `Status` type which accepts one generic type. It is then defined
/// with `#[aliases(...)]` that it is going to be used with [`String`](std::string::String) and [`i32`] values.
/// with `#[aliases(...)]` that it is going to be used with [`String`] and [`i32`] values.
/// The generic argument could also be another [`ToSchema`][to_schema] as well.
/// ```rust
/// # use utoipa::{ToSchema, OpenApi};
Expand Down Expand Up @@ -728,11 +728,12 @@ pub fn derive_to_schema(input: TokenStream) -> TokenStream {
///
/// * `description = "..."` Define the description for the request body object as str.
///
/// * `content_type = "..."` Can be used to override the default behavior of auto resolving the content type
/// from the `content` attribute. If defined the value should be valid content type such as
/// _`application/json`_. By default the content type is _`text/plain`_ for
/// [primitive Rust types][primitive], `application/octet-stream` for _`[u8]`_ and
/// _`application/json`_ for struct and complex enum types.
/// * `content_type = "..."` or `content_type = [...]` Can be used to override the default behavior
/// of auto resolving the content type from the `content` attribute. If defined the value should be valid
/// content type such as _`application/json`_ or a slice of content types within brackets e.g.
/// _`content_type = ["application/json", "text/html"]`_. By default the content type is _`text/plain`_
/// for [primitive Rust types][primitive], `application/octet-stream` for _`[u8]`_ and _`application/json`_
/// for struct and complex enum types.
///
/// * `example = ...` Can be _`json!(...)`_. _`json!(...)`_ should be something that
/// _`serde_json::json!`_ can parse as a _`serde_json::Value`_.
Expand Down Expand Up @@ -766,7 +767,7 @@ pub fn derive_to_schema(input: TokenStream) -> TokenStream {
/// that free form _`ref`_ is accessible via OpenAPI doc or Swagger UI, users are responsible for making
/// these guarantees.
///
/// * `content_type = "..." | content_type = [...]` Can be used to override the default behavior of auto resolving the content type
/// * `content_type = "..."` or `content_type = [...]` Can be used to override the default behavior of auto resolving the content type
/// from the `body` attribute. If defined the value should be valid content type such as
/// _`application/json`_. By default the content type is _`text/plain`_ for
/// [primitive Rust types][primitive], `application/octet-stream` for _`[u8]`_ and
Expand Down Expand Up @@ -905,7 +906,7 @@ pub fn derive_to_schema(input: TokenStream) -> TokenStream {
/// The given _`Type`_ can be any Rust type that is JSON parseable. It can be Option, Vec or Map etc.
/// With _`inline(...)`_ the schema will be inlined instead of a referenced which is the default for
/// [`ToSchema`][to_schema] types. Parameter type is placed after `name` with
/// equals sign E.g. _`"id" = String`_
/// equals sign E.g. _`"id" = string`_
///
/// * `in` _**Must be placed after name or parameter_type**_. Define the place of the parameter.
/// This must be one of the variants of [`openapi::path::ParameterIn`][in_enum].
Expand Down Expand Up @@ -1643,7 +1644,7 @@ pub fn openapi(input: TokenStream) -> TokenStream {
///
/// Typically path parameters need to be defined within [`#[utoipa::path(...params(...))]`][path_params] section
/// for the endpoint. But this trait eliminates the need for that when [`struct`][struct]s are used to define parameters.
/// Still [`std::primitive`] and [`String`](std::string::String) path parameters or [`tuple`] style path parameters need to be defined
/// Still [`std::primitive`] and [`String`] path parameters or [`tuple`] style path parameters need to be defined
/// within `params(...)` section if description or other than default configuration need to be given.
///
/// You can use the Rust's own `#[deprecated]` attribute on field to mark it as
Expand Down
13 changes: 6 additions & 7 deletions utoipa-gen/src/path/request_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::component::ComponentSchema;
use crate::{impl_to_tokens_diagnostics, parse_utils, AnyValue, Array, Diagnostics, Required};

use super::example::Example;
use super::{PathType, PathTypeTree, parse};
use super::{parse, PathType, PathTypeTree};

#[cfg_attr(feature = "debug", derive(Debug))]
pub enum RequestBody<'r> {
Expand Down Expand Up @@ -207,13 +207,12 @@ impl RequestBodyAttr<'_> {
let required: Required = (!type_tree.is_option()).into();
let content_types = if self.content_type.is_empty() {
let content_type = type_tree.get_default_content_type();
vec![
quote!(#content_type),
]
vec![quote!(#content_type)]
} else {
self.content_type.iter().map(|content_type| {
content_type.to_token_stream()
}).collect()
self.content_type
.iter()
.map(|content_type| content_type.to_token_stream())
.collect()
};

tokens.extend(quote! {
Expand Down
2 changes: 1 addition & 1 deletion utoipa-gen/src/path/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
impl_to_tokens_diagnostics, parse_utils, AnyValue, Array, Diagnostics,
};

use super::{example::Example, status::STATUS_CODES, InlineType, PathType, PathTypeTree, parse};
use super::{example::Example, parse, status::STATUS_CODES, InlineType, PathType, PathTypeTree};

pub mod derive;

Expand Down
1 change: 0 additions & 1 deletion utoipa-gen/tests/request_body_derive_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ fn derive_request_body_complex_multi_content_type_success() {
);
}


test_fn! {
module: derive_request_body_complex_inline,
body: (content = inline(Foo), description = "Create new Foo", content_type = "text/xml")
Expand Down

0 comments on commit d1b2f17

Please sign in to comment.