Skip to content

Commit 2a25cd5

Browse files
committed
Update 8.0.x with rust-server from master and remove support for rust-server-deprecated
1 parent 2b23399 commit 2a25cd5

207 files changed

Lines changed: 26042 additions & 11660 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Samples Rust Servers
2+
3+
on:
4+
push:
5+
paths:
6+
- "samples/server/petstore/rust-server/**"
7+
- "samples/server/petstore/rust-axum/**"
8+
pull_request:
9+
paths:
10+
- "samples/server/petstore/rust-server/**"
11+
- "samples/server/petstore/rust-axum/**"
12+
13+
jobs:
14+
build:
15+
name: Build Rust
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
sample:
21+
# these folders contain sub-projects of rust clients, servers
22+
- samples/server/petstore/rust-server/
23+
- samples/server/petstore/rust-server-deprecated/
24+
- samples/server/petstore/rust-axum/
25+
steps:
26+
- uses: actions/checkout@v5
27+
- uses: actions-rs/toolchain@v1
28+
with:
29+
toolchain: stable
30+
31+
- name: Rust cache
32+
uses: Swatinem/rust-cache@v2
33+
with:
34+
cache-targets: false # Don't cache workspace target directories as they don't exist
35+
cache-directories:
36+
${{ matrix.sample }}/target
37+
workspaces: |
38+
${{ matrix.sample }}/output/*
39+
40+
- name: Build
41+
working-directory: ${{ matrix.sample }}
42+
run: |
43+
set -e
44+
cargo build --all-targets --all-features
45+
cargo build --all-targets --no-default-features
46+
- name: Tests
47+
working-directory: ${{ matrix.sample }}
48+
run: |
49+
set -e
50+
51+
# Iterate through each package and test various features
52+
for package in $(find output -maxdepth 1 -mindepth 1 -type d)
53+
do
54+
pushd $package
55+
# Not all versions have a server example
56+
if test -f examples/server/main.rs; then
57+
cargo build --example ${package##*/}-server --features="server"
58+
fi
59+
# Not all versions have a client example
60+
if test -f examples/client/main.rs; then
61+
cargo build --example ${package##*/}-client --features="client"
62+
fi
63+
# Test the CLI works if present
64+
if test -f bin/cli.rs; then
65+
cargo build --bin ${package##*/} --features cli
66+
../../target/debug/${package##*/} --help
67+
fi
68+
# Test the validate feature if it exists
69+
if cargo read-manifest | grep -q '"validate"'; then
70+
cargo build --features validate --all-targets
71+
fi
72+
# Test TLS features if they exist
73+
if cargo read-manifest | grep -q '"client-tls"'; then
74+
# Client without TLS (HTTP-only)
75+
cargo build --no-default-features --features=client --lib
76+
# Client with TLS (using native-tls)
77+
cargo build --no-default-features --features=client,client-tls --lib
78+
# Server without TLS
79+
cargo build --no-default-features --features=server --lib
80+
fi
81+
cargo fmt
82+
cargo test
83+
cargo clippy
84+
cargo doc
85+
popd
86+
done

modules/openapi-generator/src/main/resources/rust-server/Cargo.mustache

Lines changed: 106 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -28,128 +28,179 @@ repository = "{{.}}"
2828
documentation = "{{.}}"
2929
{{/documentationUrl}}
3030
{{#homePageUrl}}
31-
homepage = "{{.}}
31+
homepage = "{{.}}"
3232
{{/homePageUrl}}
3333

3434
[features]
35-
default = ["client", "server"]
35+
default = ["client", "server", "client-tls"]
3636
client = [
37-
{{#apiUsesMultipart}}
38-
"mime_0_2",
39-
{{/apiUsesMultipart}}
4037
{{#apiUsesMultipartFormData}}
4138
"multipart", "multipart/client", "swagger/multipart_form",
4239
{{/apiUsesMultipartFormData}}
4340
{{#apiUsesMultipartRelated}}
44-
"hyper_0_10", "mime_multipart",
41+
"mime_multipart", "swagger/multipart_related",
4542
{{/apiUsesMultipartRelated}}
4643
{{#usesUrlEncodedForm}}
4744
"serde_urlencoded",
4845
{{/usesUrlEncodedForm}}
4946
{{#hasCallbacks}}
50-
"serde_ignored", "regex", "percent-encoding", "lazy_static",
47+
"serde_ignored", "percent-encoding", {{^apiUsesByteArray}}"lazy_static", "regex",{{/apiUsesByteArray}}
5148
{{/hasCallbacks}}
5249
{{! Anything added to the list below, should probably be added to the callbacks list below }}
53-
"hyper", "hyper-openssl", "hyper-tls", "native-tls", "openssl", "url"
50+
"hyper", "percent-encoding", "hyper-util/http1", "hyper-util/http2", "url"
51+
]
52+
# TLS support - automatically selects backend based on target OS:
53+
# - macOS/Windows/iOS: native-tls via hyper-tls
54+
# - Other platforms: OpenSSL via hyper-openssl
55+
# Dependencies are in target-specific sections below
56+
client-tls = [
57+
"client",
58+
"dep:native-tls",
59+
"dep:hyper-tls",
60+
"dep:openssl",
61+
"dep:hyper-openssl",
62+
"swagger/tls"
5463
]
5564
server = [
56-
{{#apiUsesMultipart}}
57-
"mime_0_2",
58-
{{/apiUsesMultipart}}
5965
{{#apiUsesMultipartFormData}}
6066
"multipart", "multipart/server", "swagger/multipart_form",
6167
{{/apiUsesMultipartFormData}}
6268
{{#apiUsesMultipartRelated}}
63-
"hyper_0_10", "mime_multipart",
69+
"mime_multipart", "swagger/multipart_related",
6470
{{/apiUsesMultipartRelated}}
6571
{{#hasCallbacks}}
66-
"native-tls", "hyper-openssl", "hyper-tls", "openssl",
72+
"hyper-util/http1", "hyper-util/http2",
6773
{{/hasCallbacks}}
6874
{{! Anything added to the list below, should probably be added to the callbacks list above }}
69-
"serde_ignored", "hyper", "regex", "percent-encoding", "url", "lazy_static"
75+
"serde_ignored", "hyper", "percent-encoding", "url",
76+
{{^apiUsesByteArray}}"lazy_static", "regex"{{/apiUsesByteArray}}
77+
]
78+
cli = [
79+
{{#apiHasDeleteMethods}}
80+
"dialoguer",
81+
{{/apiHasDeleteMethods}}
82+
"anyhow", "clap", "clap-verbosity-flag", "simple_logger", "tokio"
7083
]
7184
conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-enum-derive"]
7285

73-
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
74-
native-tls = { version = "0.2", optional = true }
75-
hyper-tls = { version = "0.5", optional = true }
76-
77-
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
78-
hyper-openssl = { version = "0.9", optional = true }
79-
openssl = {version = "0.10", optional = true }
86+
mock = ["mockall"]
87+
validate = [{{^apiUsesByteArray}}"regex",{{/apiUsesByteArray}} "serde_valid", "swagger/serdevalid"]
8088

8189
[dependencies]
8290
# Common
83-
async-trait = "0.1.24"
91+
async-trait = "0.1.89"
8492
chrono = { version = "0.4", features = ["serde"] }
8593
futures = "0.3"
86-
swagger = { version = "6.1", features = ["serdejson", "server", "client", "tls", "tcp"] }
87-
log = "0.4.0"
94+
swagger = { version = "7.0.0", features = ["serdejson", "server", "client"] }
95+
headers = "0.4.1"
96+
log = "0.4.29"
97+
8898
mime = "0.3"
99+
mockall = { version = "0.14", optional = true }
100+
{{#apiUsesByteArray}}
101+
lazy_static = "1.5"
102+
regex = "1.12"
103+
{{/apiUsesByteArray}}
104+
89105

90106
serde = { version = "1.0", features = ["derive"] }
91107
serde_json = "1.0"
92-
validator = { version = "0.16", features = ["derive"] }
108+
{{#apiUsesIntegerEnums}}
109+
serde_repr = "0.1"
110+
{{/apiUsesIntegerEnums}}
111+
serde_valid = { version = "2.0", optional = true }
112+
113+
validator = { version = "0.20", features = ["derive"] }
93114

94115
# Crates included if required by the API definition
95116
{{#usesXml}}
96-
# TODO: this should be updated to point at the official crate once
97-
# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream
98-
serde-xml-rs = {git = "https://github.com/Metaswitch/serde-xml-rs" , branch = "master"}
117+
serde-xml-rs = "0.8"
99118
{{/usesXml}}
100-
{{#apiUsesMultipart}}
101-
mime_0_2 = { package = "mime", version = "0.2.6", optional = true }
102-
{{/apiUsesMultipart}}
103119
{{#apiUsesMultipartFormData}}
104-
multipart = { version = "0.16", default-features = false, optional = true }
120+
multipart = { version = "0.18", default-features = false, optional = true }
105121
{{/apiUsesMultipartFormData}}
106122
{{#apiUsesUuid}}
107-
uuid = {version = "1.3.1", features = ["serde", "v4"]}
123+
uuid = { version = "1.23.0", features = ["serde", "v4"]}
108124
{{/apiUsesUuid}}
109125

110126
# Common between server and client features
111-
hyper = {version = "0.14", features = ["full"], optional = true}
127+
bytes = "1.11"
128+
http-body-util = "0.1.3"
129+
hyper = { version = "1.9.0", features = ["full"], optional = true }
130+
hyper-util = { version = "0.1.20", features = ["service"] }
112131
{{#apiUsesMultipartRelated}}
113-
mime_multipart = {version = "0.5", optional = true}
114-
hyper_0_10 = {package = "hyper", version = "0.10", default-features = false, optional=true}
132+
mime_multipart = { version = "0.10", optional = true, package = "mime-multipart-hyper1" }
115133
{{/apiUsesMultipartRelated}}
116-
serde_ignored = {version = "0.1.1", optional = true}
117-
url = {version = "2.1", optional = true}
134+
serde_ignored = { version = "0.1.14", optional = true }
135+
url = { version = "2.5", optional = true }
118136

119137
# Client-specific
120138
{{#usesUrlEncodedForm}}
121-
serde_urlencoded = {version = "0.6.1", optional = true}
139+
serde_urlencoded = { version = "0.7.1", optional = true }
122140
{{/usesUrlEncodedForm}}
141+
tower-service = "0.3.3"
123142

124143
# Server, and client callback-specific
125-
lazy_static = { version = "1.4", optional = true }
126-
percent-encoding = {version = "2.1.0", optional = true}
127-
regex = {version = "1.3", optional = true}
144+
{{^apiUsesByteArray}}
145+
lazy_static = { version = "1.5", optional = true }
146+
regex = { version = "1.12", optional = true }
147+
{{/apiUsesByteArray}}
148+
percent-encoding = { version = "2.3.2", optional = true }
149+
150+
# CLI-specific
151+
anyhow = { version = "1", optional = true }
152+
clap = { version = "4.6.0", features = ["env"], optional = true }
153+
clap-verbosity-flag = { version = "3.0", optional = true }
154+
simple_logger = { version = "5.2.0", features = ["stderr"], optional = true }
155+
tokio = { version = "1.50.0", features = ["rt-multi-thread", "macros"], optional = true }
156+
{{#apiHasDeleteMethods}}
157+
dialoguer = { version = "0.12", optional = true }
158+
{{/apiHasDeleteMethods}}
128159

129160
# Conversion
130-
frunk = { version = "0.3.0", optional = true }
131-
frunk_derives = { version = "0.3.0", optional = true }
132-
frunk_core = { version = "0.3.0", optional = true }
133-
frunk-enum-derive = { version = "0.2.0", optional = true }
134-
frunk-enum-core = { version = "0.2.0", optional = true }
161+
frunk = { version = "0.4.4", optional = true }
162+
frunk_derives = { version = "0.4.4", optional = true }
163+
frunk_core = { version = "0.4.4", optional = true }
164+
frunk-enum-derive = { version = "0.3.0", optional = true }
165+
frunk-enum-core = { version = "0.3.0", optional = true }
135166

136-
# Bearer authentication
137-
jsonwebtoken = { version = "9.3.0", optional = false }
167+
# TLS dependencies - platform-specific backends
168+
# On macOS/Windows/iOS, use native-tls via hyper-tls
169+
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
170+
native-tls = { version = "0.2", optional = true }
171+
hyper-tls = { version = "0.6", optional = true }
172+
173+
# On other platforms (Linux, etc.), use OpenSSL via hyper-openssl
174+
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dependencies]
175+
openssl = { version = "0.10", optional = true }
176+
hyper-openssl = { version = "0.10", optional = true }
138177

139178
[dev-dependencies]
140-
clap = "2.25"
141-
env_logger = "0.7"
142-
tokio = { version = "1.14", features = ["full"] }
179+
always_send = "0.1.1"
180+
clap = "4.6.0"
181+
env_logger = "0.11"
182+
tokio = { version = "1.50.0", features = ["full"] }
143183
native-tls = "0.2"
184+
pin-project = "1.1.11"
185+
186+
# Bearer authentication, used in examples
187+
jsonwebtoken = {version = "10.3.0", features = ["rust_crypto"]}
144188

145189
[target.'cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))'.dev-dependencies]
146-
tokio-openssl = "0.6"
147190
openssl = "0.10"
191+
tokio-openssl = "0.6"
148192

149193
[[example]]
150-
name = "client"
194+
name = "{{{packageName}}}-client"
195+
path = "examples/client/main.rs"
151196
required-features = ["client"]
152197

153198
[[example]]
154-
name = "server"
199+
name = "{{{packageName}}}-server"
200+
path = "examples/server/main.rs"
155201
required-features = ["server"]
202+
203+
[[bin]]
204+
name = "{{{packageName}}}"
205+
path = "bin/cli.rs"
206+
required-features = ["client", "cli"]

modules/openapi-generator/src/main/resources/rust-server/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The Rust Server Generator templates use Mustache Partials.
55
The following tree shows which templates include which:
66

77
- `api_doc.mustache`
8+
- `bin-cli.mustache`
89
- `cargo-config`
910
- `Cargo.mustache`
1011
- `context.mustache`

0 commit comments

Comments
 (0)