use rovo::aide::axum::IntoApiResponse;
use rovo::extract::{Path, State};
use rovo::http::StatusCode;
use rovo::response::Json;
use rovo::schemars::JsonSchema;
use rovo::{routing::get, rovo, Router};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Clone)]
struct AppState {}
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
struct TodoItem {
id: Uuid,
title: String,
completed: bool,
}
impl Default for TodoItem {
fn default() -> Self {
Self {
id: Uuid::nil(),
title: "Buy milk".into(),
completed: false,
}
}
}
#[derive(Serialize, JsonSchema)]
struct ErrorResponse {
error: String,
code: String,
}
#[allow(dead_code)]
#[derive(Deserialize, JsonSchema)]
struct TodoId {
id: Uuid,
}
#[rovo]
async fn get_todo_single_line(
State(_app): State<AppState>,
Path(_id): Path<TodoId>,
) -> impl IntoApiResponse {
Json(TodoItem::default())
}
#[rovo]
async fn get_todo_multiline_desc(
State(_app): State<AppState>,
Path(_id): Path<TodoId>,
) -> impl IntoApiResponse {
Json(TodoItem::default())
}
#[rovo]
async fn create_todo_single_line(
State(_app): State<AppState>,
Json(_input): Json<TodoItem>,
) -> impl IntoApiResponse {
Json(TodoItem::default())
}
#[rovo]
async fn create_todo_multiline(
State(_app): State<AppState>,
Json(_input): Json<TodoItem>,
) -> impl IntoApiResponse {
Json(TodoItem::default())
}
#[rovo]
async fn get_status_primitives(State(_app): State<AppState>) -> impl IntoApiResponse {
Json("success")
}
#[rovo]
async fn list_todos_single_tag(State(_app): State<AppState>) -> impl IntoApiResponse {
Json(Vec::<TodoItem>::new())
}
#[rovo]
async fn list_todos_multiple_tags(State(_app): State<AppState>) -> impl IntoApiResponse {
Json(Vec::<TodoItem>::new())
}
#[rovo]
async fn get_protected_todo(
State(_app): State<AppState>,
Path(_id): Path<TodoId>,
) -> impl IntoApiResponse {
Json(TodoItem::default())
}
#[rovo]
async fn get_todo_custom_id(
State(_app): State<AppState>,
Path(_id): Path<TodoId>,
) -> impl IntoApiResponse {
Json(TodoItem::default())
}
#[rovo]
async fn internal_endpoint(State(_app): State<AppState>) -> impl IntoApiResponse {
Json("internal")
}
#[rovo]
async fn create_todo_complete(
State(_app): State<AppState>,
Json(_input): Json<TodoItem>,
) -> impl IntoApiResponse {
Json(TodoItem::default())
}
#[rovo]
async fn experimental_endpoint(State(_app): State<AppState>) -> impl IntoApiResponse {
Json("experimental")
}
#[rovo]
async fn delete_todo(
State(_app): State<AppState>,
Path(_id): Path<TodoId>,
) -> impl IntoApiResponse {
StatusCode::NO_CONTENT
}
#[rovo]
async fn get_nested_response(State(_app): State<AppState>) -> impl IntoApiResponse {
Json(Vec::<TodoItem>::new())
}
#[test]
fn test_single_line_responses() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todo/{id}", get(get_todo_single_line))
.with_state(_state)
.finish();
}
#[test]
fn test_multiline_responses() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todo/{id}", get(get_todo_multiline_desc))
.with_state(_state)
.finish();
}
#[test]
fn test_single_line_examples() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todo", get(create_todo_single_line))
.with_state(_state)
.finish();
}
#[test]
fn test_multiline_examples() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todo", get(create_todo_multiline))
.with_state(_state)
.finish();
}
#[test]
fn test_primitive_examples() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/status", get(get_status_primitives))
.with_state(_state)
.finish();
}
#[test]
fn test_metadata_single_tag() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todos", get(list_todos_single_tag))
.with_state(_state)
.finish();
}
#[test]
fn test_metadata_multiple_tags() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todos", get(list_todos_multiple_tags))
.with_state(_state)
.finish();
}
#[test]
fn test_metadata_with_security() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todo/{id}", get(get_protected_todo))
.with_state(_state)
.finish();
}
#[test]
fn test_metadata_custom_id() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todo/{id}", get(get_todo_custom_id))
.with_state(_state)
.finish();
}
#[test]
fn test_metadata_hidden() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/internal", get(internal_endpoint))
.with_state(_state)
.finish();
}
#[test]
fn test_complete_documentation() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todo", get(create_todo_complete))
.with_state(_state)
.finish();
}
#[test]
fn test_rovo_ignore() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/experimental", get(experimental_endpoint))
.with_state(_state)
.finish();
}
#[test]
fn test_delete_endpoint() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todo/{id}", get(delete_todo))
.with_state(_state)
.finish();
}
#[test]
fn test_nested_response_types() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/nested", get(get_nested_response))
.with_state(_state)
.finish();
}
#[rovo]
#[allow(unused_variables)]
async fn get_todo_next_line_example(
State(_app): State<AppState>,
Path(id): Path<Uuid>,
) -> impl IntoApiResponse {
Json(TodoItem::default())
}
#[test]
fn test_example_starts_next_line() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todos/{id}", get(get_todo_next_line_example))
.with_state(_state)
.finish();
}
#[rovo]
async fn get_todo_code_block_unmarked(
State(_app): State<AppState>,
Path(_id): Path<Uuid>,
) -> impl IntoApiResponse {
Json(TodoItem::default())
}
#[test]
fn test_code_block_unmarked() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todos/{id}", get(get_todo_code_block_unmarked))
.with_state(_state)
.finish();
}
#[rovo]
async fn get_todo_code_block_rust(
State(_app): State<AppState>,
Path(_id): Path<Uuid>,
) -> impl IntoApiResponse {
Json(TodoItem::default())
}
#[test]
fn test_code_block_rust() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todos/{id}", get(get_todo_code_block_rust))
.with_state(_state)
.finish();
}
#[rovo]
async fn get_todo_code_block_rs(
State(_app): State<AppState>,
Path(_id): Path<Uuid>,
) -> impl IntoApiResponse {
Json(TodoItem::default())
}
#[test]
fn test_code_block_rs() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todos/{id}", get(get_todo_code_block_rs))
.with_state(_state)
.finish();
}
#[rovo]
async fn get_todo_code_block_same_line(
State(_app): State<AppState>,
Path(_id): Path<Uuid>,
) -> impl IntoApiResponse {
Json(TodoItem::default())
}
#[test]
fn test_code_block_same_line() {
let _state = AppState {};
let _router: ::axum::Router = Router::<AppState>::new()
.route("/todos/{id}", get(get_todo_code_block_same_line))
.with_state(_state)
.finish();
}