Skip to content

Commit

Permalink
docs(openapi): provide usage examples for status_range
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickariel committed Feb 12, 2025
1 parent f09290d commit f2638f5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions poem-openapi/src/docs/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Define an OpenAPI response.
| Attribute | description | Type | Optional |
|--------------|--------------------------------------------------------------|------------------------------------------------------------|----------|
| status | HTTP status code. If omitted, it is a default response type. | u16 | Y |
| status_range | Specify a range of HTTP status codes. | string | Y |
| content_type | Specify the content type. | string | Y |
| actual_type | Specifies the actual response type | string | Y |
| header | Add an extra header | [`ExtraHeader`](macro@ApiResponse#extra-header-parameters) | Y |
Expand Down Expand Up @@ -62,6 +63,23 @@ enum CreateUserResponse {
}
```

# Example status range

```rust
use poem::http::StatusCode;
use poem_openapi::{payload::PlainText, ApiResponse};

#[derive(ApiResponse)]
enum CreateUserResponse {
#[oai(status_range = "2XX")]
Ok(StatusCode, PlainText<String>),
#[oai(status_range = "4XX")]
ClientError(StatusCode),
#[oai(status_range = "5XX")]
ServerError(StatusCode),
}
```

# Example with bad request handler

```rust
Expand Down

0 comments on commit f2638f5

Please sign in to comment.