Skip to content

Commit b62f4c3

Browse files
test(rust-axum): add integer-types.yaml to integration tests
1 parent 39730e7 commit b62f4c3

16 files changed

Lines changed: 1670 additions & 12 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
generatorName: rust-axum
2+
outputDir: samples/server/petstore/rust-axum/output/rust-axum-integer-types-test
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust-axum/integer-types.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/rust-axum
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: rust-axum-integer-types-test
9+
homePageUrl: https://github.com/openapitools/openapi-generator
10+
globalProperties:
11+
skipFormModel: false
12+
enablePostProcessFile: true

modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustAxumServerCodegenTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.math.BigDecimal;
1414
import java.nio.file.Files;
1515
import java.nio.file.Path;
16-
import java.util.HashMap;
1716
import java.util.List;
1817

1918
import static org.openapitools.codegen.TestUtils.linearize;
@@ -102,7 +101,6 @@ public void testGeneratedIntegerTypes() throws IOException {
102101
TestUtils.assertFileContains(modelsPath, "pub positive_int32: u32");
103102
TestUtils.assertFileContains(modelsPath, "pub positive_int64: u64");
104103
TestUtils.assertFileContains(modelsPath, "pub small_positive: u8");
105-
TestUtils.assertFileContains(modelsPath, "pub explicit_unsigned: i32");
106104
TestUtils.assertFileContains(modelsPath, "pub struct GetIntegersQueryParams");
107105
}
108106
}

modules/openapi-generator/src/test/resources/3_0/rust-axum/integer-types.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ paths:
4040
type: integer
4141
minimum: 0
4242
maximum: 255
43-
- name: explicit_unsigned
44-
in: query
45-
required: true
46-
schema:
47-
type: integer
48-
x-unsigned: true
4943
responses:
5044
'200':
5145
description: OK
@@ -63,7 +57,6 @@ components:
6357
- positive_int32
6458
- positive_int64
6559
- small_positive
66-
- explicit_unsigned
6760
properties:
6861
legacy_uint32:
6962
type: integer
@@ -83,6 +76,3 @@ components:
8376
type: integer
8477
minimum: 0
8578
maximum: 255
86-
explicit_unsigned:
87-
type: integer
88-
x-unsigned: true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
Cargo.lock
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.gitignore
2+
Cargo.toml
3+
README.md
4+
src/apis/default.rs
5+
src/apis/mod.rs
6+
src/header.rs
7+
src/lib.rs
8+
src/models.rs
9+
src/server/mod.rs
10+
src/types.rs
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.22.0-SNAPSHOT
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[package]
2+
name = "rust-axum-integer-types-test"
3+
version = "1.0.0"
4+
authors = ["OpenAPI Generator team and contributors"]
5+
description = "No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)"
6+
edition = "2024"
7+
homepage = "https://github.com/openapitools/openapi-generator"
8+
9+
[features]
10+
default = ["server"]
11+
server = []
12+
conversion = [
13+
"frunk",
14+
"frunk_derives",
15+
"frunk_core",
16+
"frunk-enum-core",
17+
"frunk-enum-derive",
18+
]
19+
20+
[dependencies]
21+
ammonia = "4"
22+
async-trait = "0.1"
23+
axum = { version = "0.8", features = ["multipart"] }
24+
axum-extra = { version = "0.12", features = [
25+
"cookie",
26+
"query",
27+
"typed-header",
28+
] }
29+
base64 = "0.22"
30+
bytes = "1"
31+
chrono = { version = "0.4", features = ["serde"] }
32+
frunk = { version = "0.4", optional = true }
33+
frunk-enum-core = { version = "0.3", optional = true }
34+
frunk-enum-derive = { version = "0.3", optional = true }
35+
frunk_core = { version = "0.4", optional = true }
36+
frunk_derives = { version = "0.4", optional = true }
37+
headers = "0.4"
38+
http = "1"
39+
lazy_static = "1"
40+
regex = "1"
41+
serde = { version = "1", features = ["derive"] }
42+
serde_html_form = "0.2"
43+
serde_json = { version = "1", features = ["raw_value"] }
44+
tokio = { version = "1", default-features = false, features = [
45+
"signal",
46+
"rt-multi-thread",
47+
] }
48+
tracing = { version = "0.1", features = ["attributes"] }
49+
uuid = { version = "1", features = ["serde"] }
50+
validator = { version = "0.20", features = ["derive"] }
51+
52+
[dev-dependencies]
53+
tracing-subscriber = "0.3"
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Rust API for rust-axum-integer-types-test
2+
3+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4+
5+
## Overview
6+
7+
This server was generated by the [openapi-generator]
8+
(https://openapi-generator.tech) project. By using the
9+
[OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote
10+
server, you can easily generate a server stub.
11+
12+
To see how to make this your own, look here: [README]((https://openapi-generator.tech))
13+
14+
- API version: 1.0.0
15+
- Generator version: 7.22.0-SNAPSHOT
16+
17+
18+
19+
This autogenerated project defines an API crate `rust-axum-integer-types-test` which contains:
20+
* An `Api` trait defining the API in Rust.
21+
* Data types representing the underlying data model.
22+
* Axum router which accepts HTTP requests and invokes the appropriate `Api` method for each operation.
23+
* Request validations (path, query, body params) are included.
24+
25+
## Using the generated library
26+
27+
The generated library has a few optional features that can be activated through Cargo.
28+
29+
* `server`
30+
* This defaults to enabled and creates the basic skeleton of a server implementation based on Axum.
31+
* To create the server stack you'll need to provide an implementation of the API trait to provide the server function.
32+
* `conversions`
33+
* This defaults to disabled and creates extra derives on models to allow "transmogrification" between objects of structurally similar types.
34+
35+
See https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section for how to use features in your `Cargo.toml`.
36+
37+
### Example
38+
39+
```rust
40+
struct ServerImpl {
41+
// database: sea_orm::DbConn,
42+
}
43+
44+
#[allow(unused_variables)]
45+
#[async_trait]
46+
impl rust_axum_integer_types_test::apis::default::Api for ServerImpl {
47+
// API implementation goes here
48+
}
49+
50+
impl rust_axum_integer_types_test::apis::ErrorHandler for ServerImpl {}
51+
52+
pub async fn start_server(addr: &str) {
53+
// initialize tracing
54+
tracing_subscriber::fmt::init();
55+
56+
// Init Axum router
57+
let app = rust_axum_integer_types_test::server::new(Arc::new(ServerImpl));
58+
59+
// Add layers to the router
60+
let app = app.layer(...);
61+
62+
// Run the server with graceful shutdown
63+
let listener = TcpListener::bind(addr).await.unwrap();
64+
axum::serve(listener, app)
65+
.with_graceful_shutdown(shutdown_signal())
66+
.await
67+
.unwrap();
68+
}
69+
70+
async fn shutdown_signal() {
71+
let ctrl_c = async {
72+
signal::ctrl_c()
73+
.await
74+
.expect("failed to install Ctrl+C handler");
75+
};
76+
77+
#[cfg(unix)]
78+
let terminate = async {
79+
signal::unix::signal(signal::unix::SignalKind::terminate())
80+
.expect("failed to install signal handler")
81+
.recv()
82+
.await;
83+
};
84+
85+
#[cfg(not(unix))]
86+
let terminate = std::future::pending::<()>();
87+
88+
tokio::select! {
89+
_ = ctrl_c => {},
90+
_ = terminate => {},
91+
}
92+
}
93+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use async_trait::async_trait;
2+
use axum::extract::*;
3+
use axum_extra::extract::CookieJar;
4+
use bytes::Bytes;
5+
use headers::Host;
6+
use http::Method;
7+
use serde::{Deserialize, Serialize};
8+
9+
use crate::{models, types::*};
10+
11+
#[derive(Debug, PartialEq, Serialize, Deserialize)]
12+
#[must_use]
13+
#[allow(clippy::large_enum_variant)]
14+
pub enum GetIntegersResponse {
15+
/// OK
16+
Status200_OK(models::IntegerTypes),
17+
}
18+
19+
/// Default
20+
#[async_trait]
21+
#[allow(clippy::ptr_arg)]
22+
pub trait Default<E: std::fmt::Debug + Send + Sync + 'static = ()>: super::ErrorHandler<E> {
23+
/// GetIntegers - GET /integers
24+
async fn get_integers(
25+
&self,
26+
27+
method: &Method,
28+
host: &Host,
29+
cookies: &CookieJar,
30+
query_params: &models::GetIntegersQueryParams,
31+
) -> Result<GetIntegersResponse, E>;
32+
}

0 commit comments

Comments
 (0)