forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
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
6ade255
commit ab259fa
Showing
15 changed files
with
2,411 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
generatorName: rust-axum | ||
outputDir: samples/server/petstore/rust-axum/output/rust-axum-oneof | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust-axum/rust-axum-oneof.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/rust-axum | ||
generateAliasAsModel: true | ||
additionalProperties: | ||
hideGenerationTimestamp: "true" | ||
packageName: rust-axum-oneof | ||
globalProperties: | ||
skipFormModel: "false" | ||
enablePostProcessFile: true |
86 changes: 86 additions & 0 deletions
86
modules/openapi-generator/src/test/resources/3_0/rust-axum/rust-axum-oneof.yaml
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,86 @@ | ||
openapi: "3.0.4" | ||
info: | ||
title: "test" | ||
version: "0.0.1" | ||
paths: | ||
"/": | ||
post: | ||
operationId: foo | ||
requestBody: | ||
required: true | ||
content: | ||
"application/json": | ||
schema: | ||
"$ref": "#/components/schemas/Message" | ||
responses: | ||
"200": | ||
description: Re-serialize and echo the request data | ||
content: | ||
"application/json": | ||
schema: | ||
"$ref": "#/components/schemas/Message" | ||
components: | ||
schemas: | ||
Message: | ||
type: object | ||
additionalProperties: false | ||
discriminator: | ||
propertyName: op | ||
oneOf: | ||
- "$ref": "#/components/schemas/Hello" | ||
- "$ref": "#/components/schemas/Greeting" | ||
- "$ref": "#/components/schemas/Goodbye" | ||
title: Message | ||
Hello: | ||
type: object | ||
additionalProperties: false | ||
title: Hello | ||
properties: | ||
op: | ||
type: string | ||
enum: | ||
- Hello | ||
default: Hello | ||
d: | ||
type: object | ||
properties: | ||
welcome_message: | ||
type: string | ||
required: | ||
- welcome_message | ||
required: | ||
- op | ||
- d | ||
Greeting: | ||
type: object | ||
additionalProperties: false | ||
title: Greeting | ||
properties: | ||
d: | ||
type: object | ||
properties: | ||
greet_message: | ||
type: string | ||
required: | ||
- greet_message | ||
required: | ||
- d | ||
Goodbye: | ||
type: object | ||
additionalProperties: false | ||
title: Goodbye | ||
properties: | ||
op: | ||
type: string | ||
enum: | ||
- Goodbye | ||
d: | ||
type: object | ||
properties: | ||
goodbye_message: | ||
type: string | ||
required: | ||
- goodbye_message | ||
required: | ||
- op | ||
- d |
2 changes: 2 additions & 0 deletions
2
samples/server/petstore/rust-axum/output/rust-axum-oneof/.gitignore
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,2 @@ | ||
target | ||
Cargo.lock |
23 changes: 23 additions & 0 deletions
23
samples/server/petstore/rust-axum/output/rust-axum-oneof/.openapi-generator-ignore
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,23 @@ | ||
# OpenAPI Generator Ignore | ||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
# As an example, the C# client generator defines ApiClient.cs. | ||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
#ApiClient.cs | ||
|
||
# You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
#foo/*/qux | ||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
#foo/**/qux | ||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
||
# You can also negate patterns with an exclamation (!). | ||
# For example, you can ignore all files in a docs folder with the file extension .md: | ||
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md |
11 changes: 11 additions & 0 deletions
11
samples/server/petstore/rust-axum/output/rust-axum-oneof/.openapi-generator/FILES
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,11 @@ | ||
.gitignore | ||
.openapi-generator-ignore | ||
Cargo.toml | ||
README.md | ||
src/apis/default.rs | ||
src/apis/mod.rs | ||
src/header.rs | ||
src/lib.rs | ||
src/models.rs | ||
src/server/mod.rs | ||
src/types.rs |
1 change: 1 addition & 0 deletions
1
samples/server/petstore/rust-axum/output/rust-axum-oneof/.openapi-generator/VERSION
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 @@ | ||
7.11.0-SNAPSHOT |
46 changes: 46 additions & 0 deletions
46
samples/server/petstore/rust-axum/output/rust-axum-oneof/Cargo.toml
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,46 @@ | ||
[package] | ||
name = "rust-axum-oneof" | ||
version = "0.0.1" | ||
authors = ["OpenAPI Generator team and contributors"] | ||
description = "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)" | ||
edition = "2021" | ||
|
||
[features] | ||
default = ["server"] | ||
server = [] | ||
conversion = [ | ||
"frunk", | ||
"frunk_derives", | ||
"frunk_core", | ||
"frunk-enum-core", | ||
"frunk-enum-derive", | ||
] | ||
|
||
[dependencies] | ||
async-trait = "0.1" | ||
axum = "0.7" | ||
axum-extra = { version = "0.9", features = ["cookie", "multipart"] } | ||
base64 = "0.22" | ||
bytes = "1" | ||
chrono = { version = "0.4", features = ["serde"] } | ||
frunk = { version = "0.4", optional = true } | ||
frunk-enum-core = { version = "0.3", optional = true } | ||
frunk-enum-derive = { version = "0.3", optional = true } | ||
frunk_core = { version = "0.4", optional = true } | ||
frunk_derives = { version = "0.4", optional = true } | ||
http = "1" | ||
lazy_static = "1" | ||
regex = "1" | ||
serde = { version = "1", features = ["derive"] } | ||
serde_json = { version = "1", features = ["raw_value"] } | ||
serde_urlencoded = "0.7" | ||
tokio = { version = "1", default-features = false, features = [ | ||
"signal", | ||
"rt-multi-thread", | ||
] } | ||
tracing = { version = "0.1", features = ["attributes"] } | ||
uuid = { version = "1", features = ["serde"] } | ||
validator = { version = "0.19", features = ["derive"] } | ||
|
||
[dev-dependencies] | ||
tracing-subscriber = "0.3" |
91 changes: 91 additions & 0 deletions
91
samples/server/petstore/rust-axum/output/rust-axum-oneof/README.md
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,91 @@ | ||
# Rust API for rust-axum-oneof | ||
|
||
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) | ||
|
||
## Overview | ||
|
||
This server was generated by the [openapi-generator] | ||
(https://openapi-generator.tech) project. By using the | ||
[OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote | ||
server, you can easily generate a server stub. | ||
|
||
To see how to make this your own, look here: [README]((https://openapi-generator.tech)) | ||
|
||
- API version: 0.0.1 | ||
- Generator version: 7.11.0-SNAPSHOT | ||
|
||
|
||
|
||
This autogenerated project defines an API crate `rust-axum-oneof` which contains: | ||
* An `Api` trait defining the API in Rust. | ||
* Data types representing the underlying data model. | ||
* Axum router which accepts HTTP requests and invokes the appropriate `Api` method for each operation. | ||
* Request validations (path, query, body params) are included. | ||
|
||
## Using the generated library | ||
|
||
The generated library has a few optional features that can be activated through Cargo. | ||
|
||
* `server` | ||
* This defaults to enabled and creates the basic skeleton of a server implementation based on Axum. | ||
* To create the server stack you'll need to provide an implementation of the API trait to provide the server function. | ||
* `conversions` | ||
* This defaults to disabled and creates extra derives on models to allow "transmogrification" between objects of structurally similar types. | ||
|
||
See https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section for how to use features in your `Cargo.toml`. | ||
|
||
### Example | ||
|
||
```rust | ||
struct ServerImpl { | ||
// database: sea_orm::DbConn, | ||
} | ||
|
||
#[allow(unused_variables)] | ||
#[async_trait] | ||
impl rust-axum-oneof::Api for ServerImpl { | ||
// API implementation goes here | ||
} | ||
|
||
pub async fn start_server(addr: &str) { | ||
// initialize tracing | ||
tracing_subscriber::fmt::init(); | ||
|
||
// Init Axum router | ||
let app = rust-axum-oneof::server::new(Arc::new(ServerImpl)); | ||
|
||
// Add layers to the router | ||
let app = app.layer(...); | ||
|
||
// Run the server with graceful shutdown | ||
let listener = TcpListener::bind(addr).await.unwrap(); | ||
axum::serve(listener, app) | ||
.with_graceful_shutdown(shutdown_signal()) | ||
.await | ||
.unwrap(); | ||
} | ||
|
||
async fn shutdown_signal() { | ||
let ctrl_c = async { | ||
signal::ctrl_c() | ||
.await | ||
.expect("failed to install Ctrl+C handler"); | ||
}; | ||
|
||
#[cfg(unix)] | ||
let terminate = async { | ||
signal::unix::signal(signal::unix::SignalKind::terminate()) | ||
.expect("failed to install signal handler") | ||
.recv() | ||
.await; | ||
}; | ||
|
||
#[cfg(not(unix))] | ||
let terminate = std::future::pending::<()>(); | ||
|
||
tokio::select! { | ||
_ = ctrl_c => {}, | ||
_ = terminate => {}, | ||
} | ||
} | ||
``` |
30 changes: 30 additions & 0 deletions
30
samples/server/petstore/rust-axum/output/rust-axum-oneof/src/apis/default.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,30 @@ | ||
use async_trait::async_trait; | ||
use axum::extract::*; | ||
use axum_extra::extract::{CookieJar, Multipart}; | ||
use bytes::Bytes; | ||
use http::Method; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{models, types::*}; | ||
|
||
#[derive(Debug, PartialEq, Serialize, Deserialize)] | ||
#[must_use] | ||
#[allow(clippy::large_enum_variant)] | ||
pub enum FooResponse { | ||
/// Re-serialize and echo the request data | ||
Status200_Re(models::Message), | ||
} | ||
|
||
/// Default | ||
#[async_trait] | ||
#[allow(clippy::ptr_arg)] | ||
pub trait Default { | ||
/// Foo - POST / | ||
async fn foo( | ||
&self, | ||
method: Method, | ||
host: Host, | ||
cookies: CookieJar, | ||
body: models::Message, | ||
) -> Result<FooResponse, ()>; | ||
} |
1 change: 1 addition & 0 deletions
1
samples/server/petstore/rust-axum/output/rust-axum-oneof/src/apis/mod.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 @@ | ||
pub mod default; |
Oops, something went wrong.