-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
884c47f
commit 601cd73
Showing
5 changed files
with
81 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[test] | ||
fn run_tests() { | ||
let t = trybuild::TestCases::new(); | ||
t.pass("tests/test-axum/01-hello.rs"); | ||
} |
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,33 @@ | ||
use oasgen::{OaSchema, Server, openapi}; | ||
use axum::Json; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Deserialize, OaSchema)] | ||
pub struct SendCode { | ||
pub mobile: String, | ||
} | ||
|
||
#[derive(Serialize, OaSchema)] | ||
pub struct SendCodeResponse { | ||
pub found_account: bool, | ||
} | ||
|
||
#[openapi] | ||
async fn send_code(_body: Json<SendCode>) -> Json<SendCodeResponse> { | ||
Json(SendCodeResponse { found_account: false }) | ||
} | ||
|
||
fn main() { | ||
use pretty_assertions::assert_eq; | ||
let server = Server::axum() | ||
.post("/hello", send_code) | ||
.freeze() | ||
; | ||
|
||
let spec = server.openapi.clone(); | ||
let spec = serde_yaml::to_string(&spec).unwrap(); | ||
assert_eq!(spec.trim(), include_str!("01-hello.yaml")); | ||
let router = axum::Router::new() | ||
.merge(server.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,37 @@ | ||
openapi: 3.0.3 | ||
info: | ||
title: '' | ||
version: '' | ||
paths: | ||
/hello: | ||
post: | ||
operationId: send_code | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/SendCode' | ||
required: true | ||
responses: | ||
'200': | ||
description: '' | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/SendCodeResponse' | ||
components: | ||
schemas: | ||
SendCode: | ||
type: object | ||
properties: | ||
mobile: | ||
type: string | ||
required: | ||
- mobile | ||
SendCodeResponse: | ||
type: object | ||
properties: | ||
found_account: | ||
type: boolean | ||
required: | ||
- found_account |
Empty file.