{"id":28528797,"url":"https://github.com/oramasearch/axum-openapi3","last_synced_at":"2025-07-06T23:30:50.458Z","repository":{"id":268170919,"uuid":"897274480","full_name":"oramasearch/axum-openapi3","owner":"oramasearch","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-31T11:50:06.000Z","size":51,"stargazers_count":10,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-30T21:18:08.558Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oramasearch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-02T10:52:09.000Z","updated_at":"2025-04-04T10:38:17.000Z","dependencies_parsed_at":"2024-12-14T22:03:43.977Z","dependency_job_id":"503f5e4f-9607-4831-9152-9a234573de7f","html_url":"https://github.com/oramasearch/axum-openapi3","commit_stats":null,"previous_names":["oramasearch/axum-openapi3"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/oramasearch/axum-openapi3","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oramasearch%2Faxum-openapi3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oramasearch%2Faxum-openapi3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oramasearch%2Faxum-openapi3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oramasearch%2Faxum-openapi3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oramasearch","download_url":"https://codeload.github.com/oramasearch/axum-openapi3/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oramasearch%2Faxum-openapi3/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263988245,"owners_count":23540144,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-09T13:11:35.187Z","updated_at":"2025-07-06T23:30:50.440Z","avatar_url":"https://github.com/oramasearch.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Axum OpenAPI 3\n\nThis is a library for generating OpenAPI 3.0 specifications from Axum applications.\n\nThis library uses [`utoipa`](https://crates.io/crates/utoipa) crate to generate the OpenAPI spec from Rust types.\nSee the [`utoipa`](https://crates.io/crates/utoipa) crate for more information on how to use it.\n\n## Example\n\n```rust\nuse std::net::{IpAddr, SocketAddr};\n\nuse axum::extract::{Path, Query};\nuse axum::response::IntoResponse;\nuse axum::Json;\nuse axum_openapi3::utoipa; // Needed for ToSchema and IntoParams derive\nuse axum_openapi3::utoipa::*; // Needed for ToSchema and IntoParams derive\nuse axum_openapi3::utoipa::openapi::{InfoBuilder, OpenApiBuilder};\nuse serde::{Deserialize, Serialize};\n\nuse axum_openapi3::{\n    build_openapi, // function for building the openapi spec\n    endpoint,      // macro for defining endpoints\n    reset_openapi, // function for cleaning the openapi cache (mostly used for testing)\n    AddRoute,      // `add` method for Router to add routes also to the openapi spec\n};\n\n#[derive(Serialize, Deserialize, ToSchema)]\nstruct Todo {\n    id: u64,\n    title: String,\n    completed: bool,\n}\n#[derive(Serialize, Deserialize, IntoParams)]\nstruct TodoFilter {\n    completed: bool,\n}\n\n#[endpoint(method = \"POST\", path = \"/todos\", description = \"Insert a new todo\")]\nasync fn insert_todo(_: Json\u003cTodo\u003e) -\u003e Json\u003cTodo\u003e {\n    unreachable!(\"\")\n}\n#[endpoint(\n    method = \"PATCH\",\n    path = \"/todos/{id}/complete\",\n    description = \"Mark a todo as completed\"\n)]\nasync fn mark_todo_as_complete(_: Path\u003cu64\u003e, _: Json\u003cu64\u003e) -\u003e Json\u003cTodo\u003e {\n    unreachable!(\"\")\n}\n#[endpoint(\n    method = \"GET\",\n    path = \"/todos/filter\",\n    description = \"Filter todos by completed status\"\n)]\nasync fn filter(_: Query\u003cTodoFilter\u003e) -\u003e Json\u003cVec\u003cTodo\u003e\u003e {\n    unreachable!(\"\")\n}\n\nfn get_router() -\u003e axum::Router {\n    axum::Router::new()\n        .add(insert_todo())\n        .add(mark_todo_as_complete())\n        .add(filter())\n        .add(openapi())\n}\n\n#[endpoint(method = \"GET\", path = \"/openapi.json\", description = \"OpenAPI spec\")]\nasync fn openapi() -\u003e impl IntoResponse {\n    // `build_openapi` caches the openapi spec, so it's not necessary to call it every time\n    let openapi = build_openapi(|| {\n        OpenApiBuilder::new().info(InfoBuilder::new().title(\"My Webserver\").version(\"0.1.0\"))\n    });\n\n    Json(openapi)\n}\n\n#[tokio::main]\nasync fn main() {\n    reset_openapi(); // clean the openapi cache. Mostly used for testing\n\n    let ip: IpAddr = \"127.0.0.1\".parse().unwrap();\n    let _addr = SocketAddr::new(ip, 8080);\n\n    let _router = get_router();\n\n    // De-comment the following lines to start the server\n\n    // let listener = tokio::net::TcpListener::bind(addr)\n    //     .await\n    //     .expect(\"failed to bind address\");\n    // println!(\"Address binded. Starting web server on http://{}\", addr);\n    // axum::serve(listener, router).await.expect(\"server failed\");\n}\n```\n\n## Limitations\n\n- No nested routes: `axum` allows nested routes, but this library does not support them: the endpoints must be defined at the root level of the router.\n- Only one http server per process: `axum-openapi3` uses a global cache to store the OpenAPI spec, so it's not possible to have more than one http server per process.\n- Only `Json` responses: the library only supports `Json` responses. Other response types are not supported. The endpoint will be generated, but with empty response.\n\n\n## License\n\nLicensed under Apache License, Version 2.0, ([LICENSE](LICENSE))","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foramasearch%2Faxum-openapi3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foramasearch%2Faxum-openapi3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foramasearch%2Faxum-openapi3/lists"}