-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support for axum::extract::Path (#14)
* rename axum-path test to axum-query test The test does use axum Query not Path * add axum Path extraction capability This turns a axum::extract::Path into a parameter * add modifying parameter names during route/operation registration --------- Co-authored-by: Kurt Wolf <[email protected]>
- Loading branch information
1 parent
66657bb
commit 23abc41
Showing
7 changed files
with
136 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use axum::extract::{Path, Json}; | ||
use oasgen::{OaSchema, oasgen, Server}; | ||
use serde::{Deserialize}; | ||
|
||
/// Send a code to a mobile number | ||
#[derive(Deserialize, OaSchema)] | ||
pub struct TaskFilter { | ||
pub completed: bool, | ||
pub assigned_to: i32, | ||
} | ||
|
||
#[oasgen] | ||
async fn get_task(Path(_id): Path<u64>) -> Json<()> { | ||
Json(()) | ||
} | ||
|
||
fn main() { | ||
use pretty_assertions::assert_eq; | ||
let server = Server::axum() | ||
.get("/tasks/:id/", get_task) | ||
; | ||
|
||
let spec = serde_yaml::to_string(&server.openapi).unwrap(); | ||
let other = include_str!("03-path.yaml"); | ||
assert_eq!(spec.trim(), other); | ||
let router = axum::Router::new() | ||
.merge(server.freeze().into_router()); | ||
router.into_make_service(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
openapi: 3.0.3 | ||
info: | ||
title: '' | ||
version: '' | ||
paths: | ||
/tasks/{id}/: | ||
get: | ||
operationId: get_task | ||
parameters: | ||
- name: id | ||
schema: | ||
type: integer | ||
in: path | ||
style: simple | ||
responses: {} | ||
components: | ||
schemas: | ||
TaskFilter: | ||
description: Send a code to a mobile number | ||
type: object | ||
properties: | ||
completed: | ||
type: boolean | ||
assigned_to: | ||
type: integer | ||
required: | ||
- completed | ||
- assigned_to |