Module utoipa::openapi::server

source ·
Expand description

Implements OpenAPI Server Object types to configure target servers.

OpenAPI will implicitly add Server with url = "/" to OpenApi when no servers are defined.

Server can be used to alter connection url for path operations. It can be a relative path e.g /api/v1 or valid http url e.g. http://alternative.api.com/api/v1.

Relative path will append to the sever address so the connection url for path operations will become server address + relative path.

Optionally it also supports parameter substitution with {variable} syntax.

See Modify trait for details how add servers to OpenApi.

Examples

Create new server with relative path.

Server::new("/api/v1");

Create server with custom url using a builder.

ServerBuilder::new().url("https://alternative.api.url.test/api").build();

Create server with builder and variable substitution.

ServerBuilder::new().url("/api/{version}/{username}")
    .parameter("version", ServerVariableBuilder::new()
        .enum_values(Some(["v1", "v2"]))
        .default_value("v1"))
    .parameter("username", ServerVariableBuilder::new()
        .default_value("the_user")).build();

Structs