Attribute Macro poem_openapi::OpenApi[][src]

#[OpenApi]
Expand description

Define a OpenAPI.

Operation parameters

AttributedescriptionTypeOptional
pathHTTP uri.stringN
methodHTTP method. The possible values are “get”, “post”, “put”, “delete”, “head”, “options”, “connect”, “patch”, “trace”.stringN
deprecatedOperation deprecatedboolY
tagOperation tagTagsY

Operation argument parameters

AttributedescriptionTypeOptional
nameParameter name. When this value is set, it means this is an OpenAPI parameter type.stringY
inWhere to parse the parameter. The possible values are “query”, “path”, “header”, “cookie”.stringY
extractIt means this parameter is a Poem extractor.boolY
authIt means this parameter is a authorization extractor.boolY
descArgument descriptionstringY
deprecatedArgument deprecatedboolY
defaultDefault valuebool,stringY
multiple_ofThe value of “multiple_of” MUST be a number, strictly greater than 0. A numeric instance is only valid if division by this value results in an integer.numberY
maximumThe value of “maximum” MUST be a number, representing an upper limit for a numeric instance. If exclusive is true and instance is less than the provided value, or else if the instance is less than or exactly equal to the provided value.{ value: <number>, exclusive: <bool>}Y
minimumThe value of “minimum” MUST be a number, representing a lower limit for a numeric instance. If exclusive is true and instance is greater than the provided value, or else if the instance is greater than or exactly equal to the provided value.{ value: <number>, exclusive: <bool>}Y
max_lengthThe value of “max_length” MUST be a non-negative integer. A string instance is valid against this validator if its length is less than, or equal to, the value.usizeY
min_lengthThe value of “min_length” MUST be a non-negative integer. The value of this validator MUST be an integer. This integer MUST be greater than, or equal to, 0.usizeY
patternThe value of “pattern” MUST be a string. This string SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect. A string instance is considered valid if the regular expression matches the instance successfully.stringY
max_itemsThe value of “max_items” MUST be an integer. This integer MUST be greater than, or equal to, 0. An array instance is valid if its size is less than, or equal to, the value of this validator.usizeY
min_itemsThe value of “min_items” MUST be an integer. This integer MUST be greater than, or equal to, 0. An array instance is valid if its size is greater than, or equal to, the value of this validator.usizeY
unique_itemsThe value of “unique_items” MUST be an boolean. If this value is false, the instance validates successfully. If this value is true, the instance validates successfully if all of its elements are unique.boolY

Examples

use poem_openapi::{
    payload::{Json, PlainText},
    Request, Object, OpenApi, Response,
};

#[derive(Object)]
struct Pet {
    id: String,
    name: String,
}

#[derive(Request)]
enum CreatePetRequest {
    /// This request receives a pet in JSON format(application/json).
    CreateByJSON(Json<Pet>),
    /// This request receives a pet in text format(text/plain).
    CreateByPlainText(PlainText),
}

#[derive(Response)]
enum CreatePetResponse {
    /// Returns when the pet is successfully created.
    #[oai(status = 200)]
    Ok,
    /// Returns when the pet already exists.
    #[oai(status = 409)]
    PetAlreadyExists,
}

struct PetApi;

#[OpenApi]
impl PetApi {
    /// Create a new pet.
    #[oai(path = "/pet", method = "post")]
    async fn create_pet(
        &self,
        #[oai(name = "TOKEN", in = "header")] token: String,
        req: CreatePetRequest
    ) -> CreatePetResponse {
        todo!()
    }
}