pub fn derive_component(input: TokenStream) -> TokenStream {
    let DeriveInput {
        attrs,
        ident,
        data,
        generics,
        ..
    } = syn::parse_macro_input!(input);

    let component = Component::new(&data, &attrs, &ident, &generics);

    component.to_token_stream().into()
}
/// Component dervice macro
///
/// This is `#[derive]` implementation for [`Component`][c] trait. The macro accepts one `component`
/// attribute optionally which can be used to enhance generated documentation. The attribute can be placed
/// at item level or field level in struct and enums. Currently placing this attribute to unnamed field does
/// not have any effect.
///
/// You can use the Rust's own `#[deprecated]` attribute on any struct, emun or field to mark it as deprecated and it will
/// reflect to the generated OpenAPI spec.
///
/// `#[deprecated]` attribute supports adding addtional details such as a reason and or since version but this is is not supported in
/// OpenAPI. OpenAPI has only a boolean flag to determine deprecation. While it is totally okay to declare deprecated with reason
/// `#[deprecated  = "There is better way to do this"]` the reason would not render in OpenAPI spec.
///
/// # Struct Optional Configuration Options
/// * `example = ...` Can be either _`json!(...)`_ or literal string that can be parsed to json. _`json!`_
///   should be something that _`serde_json::json!`_ can parse as a _`serde_json::Value`_. [^json]
/// * `xml(...)` Can be used to define [`Xml`][xml] object properties applicable to Structs.
///  
/// [^json]: **json** feature need to be enabled for _`json!(...)`_ type to work.
///
/// # Enum Optional Configuration Options
/// * `example = ...` Can be literal value, method reference or _`json!(...)`_. [^json2]
/// * `default = ...` Can be literal value, method reference or _`json!(...)`_. [^json2]
///
/// # Unnamed Field Struct Optional Configuration Options
/// * `example = ...` Can be literal value, method reference or _`json!(...)`_. [^json2]
/// * `default = ...` Can be literal value, method reference or _`json!(...)`_. [^json2]
/// * `format = ...` [`ComponentFormat`][format] to use for the property. By default the format is derived from
///   the type of the property according OpenApi spec.
/// * `value_type = ...` Can be used to override default type derived from type of the field used in OpenAPI spec.
///   This is useful in cases the where default type does not correspond to the actual type e.g. when
///   any thrid-party types are used which are not components nor primitive types. With **value_type** we can enforce
///   type used to certain type. Value type may only be [`primitive`][primitive] type or [`String`]. Generic types are not allowed.
///
/// # Named Fields Optional Configuration Options
/// * `example = ...` Can be literal value, method reference or _`json!(...)`_. [^json2]
/// * `default = ...` Can be literal value, method reference or _`json!(...)`_. [^json2]
/// * `format = ...` [`ComponentFormat`][format] to use for the property. By default the format is derived from
///   the type of the property according OpenApi spec.
/// * `write_only` Defines property is only used in **write** operations *POST,PUT,PATCH* but not in *GET*
/// * `read_only` Defines property is only used in **read** operations *GET* but not in *POST,PUT,PATCH*
/// * `xml(...)` Can be used to define [`Xml`][xml] object properties applicable to named fields.
/// * `value_type = ...` Can be used to override default type derived from type of the field used in OpenAPI spec.
///   This is useful in cases the where default type does not correspond to the actual type e.g. when
///   any thrid-party types are used which are not components nor primitive types. With **value_type** we can enforce
///   type used to certain type. Value type may only be [`primitive`][primitive] type or [`String`]. Generic types are not allowed.
///
/// [^json2]: Values are converted to string if **json** feature is not enabled.
///
/// # Xml attribute Configuration Options
///
/// * `xml(name = "...")` Will set name for property or type.
/// * `xml(namespace = "...")` Will set namespace for xml element which needs to be valid uri.
/// * `xml(prefix = "...")` Will set prefix for name.
/// * `xml(attribute)` Will translate property to xml attribute instead of xml element.
/// * `xml(wrapped)` Will make wrapped xml element.
/// * `xml(wrapped(name = "wrap_name"))` Will override the wrapper elements name.
///
/// See [`Xml`][xml] for more details.
///
/// # Partial `#[serde(...)]` attributes support
///
/// Component derive has partial support for [serde attributes](https://serde.rs/attributes.html). These supported attributes will reflect to the
/// generated OpenAPI doc. For example if _`#[serde(skip)]`_ is defined the attribute will not show up in the OpenAPI spec at all since it will not never
/// be serialized anyway. Similarly the _`rename`_ and _`rename_all`_ will reflect to the generated OpenAPI doc.
///
/// * `rename_all = "..."` Supported in container level.
/// * `rename = "..."` Supported **only** in field or variant level.
/// * `skip = "..."` Supported  **only** in field or variant level.
///
/// Other _`serde`_ attributes works as is but does not have any effect on the generated OpenAPI doc.
///
/// ```rust
/// # use serde::Serialize;
/// # use utoipa::Component;
/// #[derive(Serialize, Component)]
/// struct Foo(String);
///
/// #[derive(Serialize, Component)]
/// #[serde(rename_all = "camelCase")]
/// enum Bar {
///     UnitValue,
///     #[serde(rename_all = "camelCase")]
///     NamedFields {
///         #[serde(rename = "id")]
///         named_id: &'static str,
///         name_list: Option<Vec<String>>
///     },
///     UnnamedFields(Foo),
///     #[serde(skip)]
///     SkipMe,
/// }
/// ```
///
/// # Examples
///
/// Example struct with struct level example.
/// ```rust
/// # use utoipa::Component;
/// #[derive(Component)]
/// #[component(example = json!({"name": "bob the cat", "id": 0}))]
/// struct Pet {
///     id: u64,
///     name: String,
///     age: Option<i32>,
/// }
/// ```
///
/// The `component` attribute can also be placed at field level as follows.
/// ```rust
/// # use utoipa::Component;
/// #[derive(Component)]
/// struct Pet {
///     #[component(example = 1, default = 0)]
///     id: u64,
///     name: String,
///     age: Option<i32>,
/// }
/// ```
///
/// You can also use method reference for attribute values.
/// ```rust
/// # use utoipa::Component;
/// #[derive(Component)]
/// struct Pet {
///     #[component(example = u64::default, default = u64::default)]
///     id: u64,
///     #[component(default = default_name)]
///     name: String,
///     age: Option<i32>,
/// }
///
/// fn default_name() -> String {
///     "bob".to_string()
/// }
/// ```
///
/// For enums and unnamed field structs you can define `component` at type level.
/// ```rust
/// # use utoipa::Component;
/// #[derive(Component)]
/// #[component(example = "Bus")]
/// enum VechileType {
///     Rocket, Car, Bus, Submarine
/// }
/// ```
///
/// Also you write complex enum combining all above types.
/// ```rust
/// # use utoipa::Component;
/// #[derive(Component)]
/// enum ErrorResponse {
///     InvalidCredentials,
///     #[component(default = String::default, example = "Pet not found")]
///     NotFound(String),
///     System {
///         #[component(example = "Unknown system failure")]
///         details: String,
///     }
/// }
/// ```
///
/// Use `xml` attribute to manipulate xml output.
/// ```rust
/// # use utoipa::Component;
/// #[derive(Component)]
/// #[component(xml(name = "user", prefix = "u", namespace = "https://user.xml.schema.test"))]
/// struct User {
///     #[component(xml(attribute, prefix = "u"))]
///     id: i64,
///     #[component(xml(name = "user_name", prefix = "u"))]
///     username: String,
///     #[component(xml(wrapped(name = "linkList"), name = "link"))]
///     links: Vec<String>,
///     #[component(xml(wrapped, name = "photo_url"))]
///     photos_urls: Vec<String>
/// }
/// ```
///
/// Use of Rust's own `#[deprecated]` attribute will reflect to generated OpenAPI spec.
/// ```rust
/// # use utoipa::Component;
/// #[derive(Component)]
/// #[deprecated]
/// struct User {
///     id: i64,
///     username: String,
///     links: Vec<String>,
///     #[deprecated]
///     photos_urls: Vec<String>
/// }
/// ```
///
/// Enforce type being used in OpenAPI spec to [`String`] with `value_type` and set format to octect stream
/// with [`ComponentFormat::Binary`][binary].
/// ```rust
/// # use utoipa::Component;
/// #[derive(Component)]
/// struct Post {
///     id: i32,
///     #[component(value_type = String, format = ComponentFormat::Binary)]
///     value: Vec<u8>,
/// }
/// ```
///
/// Enforce type being used in OpenAPI spec to [`String`] with `value_type` option.
/// ```rust
/// # use utoipa::Component;
/// #[derive(Component)]
/// #[component(value_type = String)]
/// struct Value(i64);
/// ```
///
/// [c]: trait.Component.html
/// [format]: openapi/schema/enum.ComponentFormat.html
/// [binary]: openapi/schema/enum.ComponentFormat.html#variant.Binary
/// [xml]: openapi/xml/struct.Xml.html
/// [primitive]: https://doc.rust-lang.org/std/primitive/index.html
Component dervice macro
This is `#[derive]` implementation for [`Component`][c] trait. The macro accepts one `component`
attribute optionally which can be used to enhance generated documentation. The attribute can be placed
at item level or field level in struct and enums. Currently placing this attribute to unnamed field does
not have any effect.

You can use the Rust's own `#[deprecated]` attribute on any struct, emun or field to mark it as deprecated and it will
reflect to the generated OpenAPI spec.

`#[deprecated]` attribute supports adding addtional details such as a reason and or since version but this is is not supported in
OpenAPI. OpenAPI has only a boolean flag to determine deprecation. While it is totally okay to declare deprecated with reason
`#[deprecated  = "There is better way to do this"]` the reason would not render in OpenAPI spec.
Component dervice macro This is ` # [ derive ] ` implementation for [ ` Component ` ] [ c ] trait . The macro accepts one ` component ` attribute optionally which can be used to enhance generated documentation . The attribute can be placed at item level or field level in struct and enums . Currently placing this attribute to unnamed field does not have any effect . You can use the Rust ' s own ` # [ deprecated ] ` attribute on any struct emun or field to mark it as deprecated and it will reflect to the generated OpenAPI spec . ` # [ deprecated ] ` attribute supports adding addtional details such as a reason and or since version but this is is not supported in OpenAPI . OpenAPI has only a boolean flag to determine deprecation . While it is totally okay to declare deprecated with reason ` # [ deprecated = " There is better way to do this " ] ` the reason would not render in OpenAPI spec .
pub fn derive_component(input: TokenStream) -> TokenStream {
    let DeriveInput {
        attrs,
        ident,
        data,
        generics,
        ..
    } = syn::parse_macro_input!(input);
    let component = Component::new(&data, &attrs, &ident, &generics);
    component.to_token_stream().into()
}
pub fn derive_component ( input : TokenStream ) -> TokenStream { let DeriveInput { attrs , ident , data , generics , .. } = syn :: parse_macro_input ! ( input ) ; let component = Component :: new ( & data , & attrs , & ident , & generics ) ; component . to_token_stream ( ) . into ( ) }
Component dervice macro
This is `#[derive]` implementation for [`Component`][c] trait.
Component dervice macro This is ` # [ derive ] ` implementation for [ ` Component ` ] [ c ] trait .
input
TokenStream
struct optional configuration options
`example = ...` Can be either _`json!(...)`_ or literal string that can be parsed to json. _`json!`_
should be something that _`serde_json::json!`_ can parse as a _`serde_json::Value`_. [^json]
`xml(...)` Can be used to define [`Xml`][xml] object properties applicable to Structs.

[^json]: **json** feature need to be enabled for _`json!(...)`_ type to work.
` example = ... ` Can be either _ ` json! ( ... ) ` _ or literal string that can be parsed to json . _ ` json! ` _ should be something that _ ` serde_json :: json! ` _ can parse as a _ ` serde_json :: Value ` _ . [ ^json ] ` xml ( ... ) ` Can be used to define [ ` Xml ` ] [ xml ] object properties applicable to Structs . [ ^json ] : ** json ** feature need to be enabled for _ ` json! ( ... ) ` _ type to work .
enum optional configuration options
`example = ...` Can be literal value, method reference or _`json!(...)`_. [^json2]
`default = ...` Can be literal value, method reference or _`json!(...)`_.
` example = ... ` Can be literal value method reference or _ ` json! ( ... ) ` _ . [ ^json2 ] ` default = ... ` Can be literal value method reference or _ ` json! ( ... ) ` _ .
unnamed field struct optional configuration options
`example = ...` Can be literal value, method reference or _`json!(...)`_. [^json2]
`default = ...` Can be literal value, method reference or _`json!(...)`_. [^json2]
`format = ...` [`ComponentFormat`][format] to use for the property. By default the format is derived from
the type of the property according OpenApi spec.
`value_type = ...` Can be used to override default type derived from type of the field used in OpenAPI spec.
This is useful in cases the where default type does not correspond to the actual type e.g. when
any thrid-party types are used which are not components nor primitive types. With **value_type** we can enforce
type used to certain type. Value type may only be [`primitive`][primitive] type or [`String`]. Generic types are not allowed.
` example = ... ` Can be literal value method reference or _ ` json! ( ... ) ` _ . [ ^json2 ] ` default = ... ` Can be literal value method reference or _ ` json! ( ... ) ` _ . [ ^json2 ] ` format = ... ` [ ` ComponentFormat ` ] [ format ] to use for the property . By default the format is derived from the type of the property according OpenApi spec . ` value_type = ... ` Can be used to override default type derived from type of the field used in OpenAPI spec . This is useful in cases the where default type does not correspond to the actual type e . g . when any thrid - party types are used which are not components nor primitive types . With ** value_type ** we can enforce type used to certain type . Value type may only be [ ` primitive ` ] [ primitive ] type or [ ` String ` ] . Generic types are not allowed .
named fields optional configuration options
`example = ...` Can be literal value, method reference or _`json!(...)`_. [^json2]
`default = ...` Can be literal value, method reference or _`json!(...)`_. [^json2]
`format = ...` [`ComponentFormat`][format] to use for the property. By default the format is derived from
the type of the property according OpenApi spec.
`write_only` Defines property is only used in **write** operations *POST,PUT,PATCH* but not in *GET
`read_only` Defines property is only used in **read** operations *GET* but not in *POST,PUT,PATCH
`xml(...)` Can be used to define [`Xml`][xml] object properties applicable to named fields.
`value_type = ...` Can be used to override default type derived from type of the field used in OpenAPI spec.
This is useful in cases the where default type does not correspond to the actual type e.g. when
any thrid-party types are used which are not components nor primitive types. With **value_type** we can enforce
type used to certain type. Value type may only be [`primitive`][primitive] type or [`String`]. Generic types are not allowed.

[^json2]: Values are converted to string if **json** feature is not enabled.
` example = ... ` Can be literal value method reference or _ ` json! ( ... ) ` _ . [ ^json2 ] ` default = ... ` Can be literal value method reference or _ ` json! ( ... ) ` _ . [ ^json2 ] ` format = ... ` [ ` ComponentFormat ` ] [ format ] to use for the property . By default the format is derived from the type of the property according OpenApi spec . ` write_only ` Defines property is only used in ** write ** operations * POST PUT PATCH * but not in * GET ` read_only ` Defines property is only used in ** read ** operations * GET * but not in * POST PUT PATCH ` xml ( ... ) ` Can be used to define [ ` Xml ` ] [ xml ] object properties applicable to named fields . ` value_type = ... ` Can be used to override default type derived from type of the field used in OpenAPI spec . This is useful in cases the where default type does not correspond to the actual type e . g . when any thrid - party types are used which are not components nor primitive types . With ** value_type ** we can enforce type used to certain type . Value type may only be [ ` primitive ` ] [ primitive ] type or [ ` String ` ] . Generic types are not allowed . [ ^json2 ] : Values are converted to string if ** json ** feature is not enabled .
xml attribute configuration options
`xml(name = "...")` Will set name for property or type.
`xml(namespace = "...")` Will set namespace for xml element which needs to be valid uri.
`xml(prefix = "...")` Will set prefix for name.
`xml(attribute)` Will translate property to xml attribute instead of xml element.
`xml(wrapped)` Will make wrapped xml element.
`xml(wrapped(name = "wrap_name"))` Will override the wrapper elements name.

See [`Xml`][xml] for more details.
` xml ( name = " ... " ) ` Will set name for property or type . ` xml ( namespace = " ... " ) ` Will set namespace for xml element which needs to be valid uri . ` xml ( prefix = " ... " ) ` Will set prefix for name . ` xml ( attribute ) ` Will translate property to xml attribute instead of xml element . ` xml ( wrapped ) ` Will make wrapped xml element . ` xml ( wrapped ( name = " wrap_name " )) ` Will override the wrapper elements name . See [ ` Xml ` ] [ xml ] for more details .
partial `#[serde(...)]` attributes support
Component derive has partial support for [serde attributes]. These supported attributes will reflect to the
generated OpenAPI doc. For example if _`#[serde(skip)]`_ is defined the attribute will not show up in the OpenAPI spec at all since it will not never
be serialized anyway. Similarly the _`rename`_ and _`rename_all`_ will reflect to the generated OpenAPI doc.

`rename_all = "..."` Supported in container level.
`rename = "..."` Supported **only** in field or variant level.
`skip = "..."` Supported  **only** in field or variant level.

Other _`serde`_ attributes works as is but does not have any effect on the generated OpenAPI doc.


Component derive has partial support for [ serde attributes ] . These supported attributes will reflect to the generated OpenAPI doc . For example if _ ` # [ serde ( skip ) ] ` _ is defined the attribute will not show up in the OpenAPI spec at all since it will not never be serialized anyway . Similarly the _ ` rename ` _ and _ ` rename_all ` _ will reflect to the generated OpenAPI doc . ` rename_all = " ... " ` Supported in container level . ` rename = " ... " ` Supported ** only ** in field or variant level . ` skip = " ... " ` Supported ** only ** in field or variant level . Other _ ` serde ` _ attributes works as is but does not have any effect on the generated OpenAPI doc .
use serde::serialize;
None
use utoipa::component;
None
[derive(serialize, component)]
None
[derive(serialize, component)]
None
[serde(rename_all = "camelcase")]
enum Bar {
UnitValue,
[serde(rename_all = "camelCase")]
NamedFields {
[serde(rename = "id")]
named_id: &'static str,
name_list: Option>
},
UnnamedFields(Foo),
[serde(skip)]
SkipMe,
}
```
enum Bar { UnitValue [ serde ( rename_all = " camelCase " ) ] NamedFields { [ serde ( rename = " id " ) ] named_id : & ' static str name_list : Option > } UnnamedFields ( Foo ) [ serde ( skip ) ] SkipMe } ` ` `
examples
Example struct with struct level example.
Example struct with struct level example .
use utoipa::component;
None
[derive(component)]
None
[component(example = json!({"name": "bob the cat", "id": 0}))]
struct Pet {
id: u64,
name: String,
age: Option,
}
```

The `component` attribute can also be placed at field level as follows.
struct Pet { id : u64 name : String age : Option } ` ` ` The ` component ` attribute can also be placed at field level as follows .
use utoipa::component;
None
[derive(component)]
struct Pet {
[component(example = 1, default = 0)]
id: u64,
name: String,
age: Option,
}
```

You can also use method reference for attribute values.
struct Pet { [ component ( example = 1 default = 0 ) ] id : u64 name : String age : Option } ` ` ` You can also use method reference for attribute values .
use utoipa::component;
None
[derive(component)]
struct Pet {
[component(example = u64::default, default = u64::default)]
id: u64,
[component(default = default_name)]
name: String,
age: Option,
}

fn default_name() -> String {
"bob".to_string()
}
```

For enums and unnamed field structs you can define `component` at type level.
struct Pet { [ component ( example = u64 :: default default = u64 :: default ) ] id : u64 [ component ( default = default_name ) ] name : String age : Option } fn default_name () - > String { " bob " . to_string () } ` ` ` For enums and unnamed field structs you can define ` component ` at type level .
use utoipa::component;
None
[derive(component)]
None
[component(example = "bus")]
enum VechileType {
Rocket, Car, Bus, Submarine
}
```

Also you write complex enum combining all above types.
enum VechileType { Rocket Car Bus Submarine } ` ` ` Also you write complex enum combining all above types .
use utoipa::component;
None
[derive(component)]
enum ErrorResponse {
InvalidCredentials,
[component(default = String::default, example = "Pet not found")]
NotFound(String),
System {
[component(example = "Unknown system failure")]
details: String,
}
}
```

Use `xml` attribute to manipulate xml output.
enum ErrorResponse { InvalidCredentials [ component ( default = String :: default example = " Pet not found " ) ] NotFound ( String ) System { [ component ( example = " Unknown system failure " ) ] details : String } } ` ` ` Use ` xml ` attribute to manipulate xml output .
use utoipa::component;
None
[derive(component)]
None
[component(xml(name = "user", prefix = "u", namespace = "https://user.xml.schema.test"))]
struct User {
[component(xml(attribute, prefix = "u"))]
id: i64,
[component(xml(name = "user_name", prefix = "u"))]
username: String,
[component(xml(wrapped(name = "linkList"), name = "link"))]
links: Vec,
[component(xml(wrapped, name = "photo_url"))]
photos_urls: Vec
}
```

Use of Rust's own `#[deprecated]` attribute will reflect to generated OpenAPI spec.
struct User { [ component ( xml ( attribute prefix = " u " )) ] id : i64 [ component ( xml ( name = " user_name " prefix = " u " )) ] username : String [ component ( xml ( wrapped ( name = " linkList " ) name = " link " )) ] links : Vec [ component ( xml ( wrapped name = " photo_url " )) ] photos_urls : Vec } ` ` ` Use of Rust ' s own ` # [ deprecated ] ` attribute will reflect to generated OpenAPI spec .
use utoipa::component;
None
[derive(component)]
None
[deprecated]
struct User {
id: i64,
username: String,
links: Vec,
[deprecated]
photos_urls: Vec
}
```

Enforce type being used in OpenAPI spec to [`String`] with `value_type` and set format to octect stream
with [`ComponentFormat::Binary`][binary].
struct User { id : i64 username : String links : Vec [ deprecated ] photos_urls : Vec } ` ` ` Enforce type being used in OpenAPI spec to [ ` String ` ] with ` value_type ` and set format to octect stream with [ ` ComponentFormat :: Binary ` ] [ binary ] .
use utoipa::component;
None
[derive(component)]
struct Post {
id: i32,
[component(value_type = String, format = ComponentFormat::Binary)]
value: Vec,
}
```

Enforce type being used in OpenAPI spec to [`String`] with `value_type` option.
struct Post { id : i32 [ component ( value_type = String format = ComponentFormat :: Binary ) ] value : Vec } ` ` ` Enforce type being used in OpenAPI spec to [ ` String ` ] with ` value_type ` option .
use utoipa::component;
None
[derive(component)]
None
[component(value_type = string)]
None