utoipa_config

Struct Config

source
#[non_exhaustive]
pub struct Config<'c> { pub schema_collect: SchemaCollect, /* private fields */ }
Expand description

Global configuration initialized in build.rs of user project.

This works similar fashion to what hyperium/tonic grpc library does with the project configuration. See the quick usage from module documentation

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§schema_collect: SchemaCollect

Schema collect mode for utoipa. By default only non inlined schemas are collected.

Implementations§

source§

impl<'c> Config<'c>

source

pub fn new() -> Self

Construct a new Config.

source

pub fn alias_for(self, alias: &'c str, value: &'c str) -> Config<'c>

Add new global alias.

This method accepts two arguments. First being identifier of the user’s type alias. Second is the type path definition to be used as alias value. The value can be anything that utoipa can parse as TypeTree and can be used as type for a value.

Because of TypeTree the aliased value can also be a fairly complex type and not limited to primitive types. This also allows users create custom types which can be treated as primitive types. E.g. One could create custom date time type that is treated as chrono’s DateTime or a String.

§Examples

Create MyType alias for i32.

use utoipa_config::Config;

let _ = Config::new()
    .alias_for("MyType", "i32");

Create Json alias for serde_json::Value.

use utoipa_config::Config;

let _ = Config::new()
    .alias_for("Json", "Value");

Create NullableString alias for Option<String>.

use utoipa_config::Config;

let _ = Config::new()
    .alias_for("NullableString", "Option<String>");
source

pub fn schema_collect(self, schema_collect: SchemaCollect) -> Self

Define schema collect mode for utoipa.

Method accepts one argument SchemaCollect which defines the collect mode to be used by utiopa. If none is defined SchemaCollect::NonInlined schemas will be collected by default.

This can be changed to SchemaCollect::All if schemas called with inline(T) is wished to be collected to the resulting OpenAPI.

source

pub fn write_to_file(&self)

Write the current Config to a file. This persists the Config for utoipa to read and use later.

Trait Implementations§

source§

impl<'c> Default for Config<'c>

source§

fn default() -> Config<'c>

Returns the “default value” for a type. Read more
source§

impl<'de, 'c> Deserialize<'de> for Config<'c>

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'c> Serialize for Config<'c>

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<'c> Freeze for Config<'c>

§

impl<'c> RefUnwindSafe for Config<'c>

§

impl<'c> Send for Config<'c>

§

impl<'c> Sync for Config<'c>

§

impl<'c> Unpin for Config<'c>

§

impl<'c> UnwindSafe for Config<'c>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,