Skip to content

Commit 2af194b

Browse files
[rust-server] Update to hyper1 in rust-server generator (#21422)
* Add rust-server-deprecated generator in preparation for hyper1 upgrade to rust-server generator * [Rust Server] Fix spacing in `Cargo.mustache` (#17876) * [Rust Server] Update dependency versions in `Cargo.mustache` (#17876) * [Rust Server] Update templates so generated client and server compile (#17876) * [Rust Server] Get `server` example to compile (#17876) * [Rust Server] Update `client` example to compile (#17876) * [Rust Server] Update `bin/cli.rs` to compile (#17876) * Revert changes to use typed auth in rust-server. Run sample generation. * Hyper1 fixup compilation errors in all examples * Add tests to all examples, clippy, tests, cli-bin, run examples * Use headers Auth structs * Fixup various clippy lints * Move more Service impl to use BoxBody * Reduce generic restriction on some Service impl where possible * Appease clippy lints in rust 1.88 --------- Co-authored-by: Azriel Hoh <[email protected]>
1 parent 65773a9 commit 2af194b

File tree

511 files changed

+78993
-6604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

511 files changed

+78993
-6604
lines changed

.github/workflows/samples-rust.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,54 @@ jobs:
2626
- samples/client/others/rust/
2727
- samples/client/petstore/rust/
2828
- samples/server/petstore/rust-server/
29+
- samples/server/petstore/rust-server-deprecated/
2930
- samples/server/petstore/rust-axum/
3031
steps:
3132
- uses: actions/checkout@v4
3233
- uses: actions-rs/toolchain@v1
3334
with:
3435
toolchain: stable
36+
37+
- name: Rust cache
38+
uses: Swatinem/rust-cache@v2
39+
with:
40+
cache-targets: false # Don't cache workspace target directories as they don't exist
41+
cache-directories:
42+
${{ matrix.sample }}/target
43+
workspaces: |
44+
${{ matrix.sample }}/output/*
45+
3546
- name: Build
3647
working-directory: ${{ matrix.sample }}
3748
run: cargo build --all-targets --all-features
49+
- name: Tests
50+
working-directory: ${{ matrix.sample }}
51+
run: |
52+
set -e
53+
# Skip samples/client/petstore/rust/ as it's tests are failing.
54+
if [[ "${{ matrix.sample }}" == "samples/client/petstore/rust/" ]]; then
55+
echo "Skipping tests for samples/client/petstore/rust/"
56+
exit 0
57+
fi
58+
59+
# Iterate through each example and test various features
60+
for package in $(find . -maxdepth 1 -mindepth 1 -type d)
61+
do
62+
# Not all versions have a client example
63+
if test -f examples/client/main.rs; then
64+
cargo build --example client --features="client"
65+
fi
66+
# Not all versions have a server example
67+
if test -f examples/server/main.rs; then
68+
cargo build --example server --features="server"
69+
fi
70+
# Test the CLI works if present
71+
if test -f bin/cli.rs; then
72+
cargo build --bin ${package##*/} --features cli
73+
target/debug/${package##*/} --help
74+
fi
75+
cargo fmt
76+
cargo test
77+
cargo clippy
78+
cargo doc
79+
done
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: rust-server-deprecated
2+
outputDir: samples/server/petstore/rust-server-deprecated/output/multipart-v3
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust-server/multipart-v3.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/rust-server-deprecated
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: multipart-v3
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: rust-server-deprecated
2+
outputDir: samples/server/petstore/rust-server-deprecated/output/no-example-v3
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust-server/no-example-v3.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/rust-server-deprecated
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: no-example-v3
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: rust-server-deprecated
2+
outputDir: samples/server/petstore/rust-server-deprecated/output/openapi-v3
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/rust-server-deprecated
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: openapi-v3
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: rust-server-deprecated
2+
outputDir: samples/server/petstore/rust-server-deprecated/output/ops-v3
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust-server/ops-v3.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/rust-server-deprecated
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: ops-v3
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
generatorName: rust-server-deprecated
2+
outputDir: samples/server/petstore/rust-server-deprecated/output/petstore-with-fake-endpoints-models-for-testing
3+
inputSpec: modules/openapi-generator/src/test/resources/2_0/rust-server/petstore-with-fake-endpoints-models-for-testing.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/rust-server-deprecated
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: petstore-with-fake-endpoints-models-for-testing
9+
publishRustRegistry: crates-io
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: rust-server-deprecated
2+
outputDir: samples/server/petstore/rust-server-deprecated/output/ping-bearer-auth
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust-server/ping-bearer-auth.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/rust-server-deprecated
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: ping-bearer-auth
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: rust-server-deprecated
2+
outputDir: samples/server/petstore/rust-server-deprecated/output/rust-server-test
3+
inputSpec: modules/openapi-generator/src/test/resources/2_0/rust-server/rust-server-test.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/rust-server-deprecated
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: rust-server-test

docs/generators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ The following generators are available:
142142
* [ruby-sinatra](generators/ruby-sinatra.md)
143143
* [rust-axum (beta)](generators/rust-axum.md)
144144
* [rust-server](generators/rust-server.md)
145+
* [rust-server-deprecated](generators/rust-server-deprecated.md)
145146
* [scala-akka-http-server (beta)](generators/scala-akka-http-server.md)
146147
* [scala-cask](generators/scala-cask.md)
147148
* [scala-finch](generators/scala-finch.md)
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
---
2+
title: Documentation for the rust-server-deprecated Generator
3+
---
4+
5+
## METADATA
6+
7+
| Property | Value | Notes |
8+
| -------- | ----- | ----- |
9+
| generator name | rust-server-deprecated | pass this to the generate command after -g |
10+
| generator stability | STABLE | |
11+
| generator type | SERVER | |
12+
| generator language | Rust | |
13+
| generator default templating engine | mustache | |
14+
| helpTxt | Generates a Rust Hyper/Tower server library based on hyper 0.14. Also generates a matching Hyper client library within the same crate that implements the same trait. | |
15+
16+
## CONFIG OPTIONS
17+
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
18+
19+
| Option | Description | Values | Default |
20+
| ------ | ----------- | ------ | ------- |
21+
|packageName|Rust crate name (convention: snake_case).| |openapi_client|
22+
|packageVersion|Rust crate version.| |null|
23+
24+
## IMPORT MAPPING
25+
26+
| Type/Alias | Imports |
27+
| ---------- | ------- |
28+
29+
30+
## INSTANTIATION TYPES
31+
32+
| Type/Alias | Instantiated By |
33+
| ---------- | --------------- |
34+
|array|Vec|
35+
|map|std::collections::HashMap|
36+
37+
38+
## LANGUAGE PRIMITIVES
39+
40+
<ul class="column-ul">
41+
<li>String</li>
42+
<li>bool</li>
43+
<li>char</li>
44+
<li>f32</li>
45+
<li>f64</li>
46+
<li>i16</li>
47+
<li>i32</li>
48+
<li>i64</li>
49+
<li>i8</li>
50+
<li>isize</li>
51+
<li>str</li>
52+
<li>u16</li>
53+
<li>u32</li>
54+
<li>u64</li>
55+
<li>u8</li>
56+
<li>usize</li>
57+
</ul>
58+
59+
## RESERVED WORDS
60+
61+
<ul class="column-ul">
62+
<li>Self</li>
63+
<li>abstract</li>
64+
<li>as</li>
65+
<li>async</li>
66+
<li>await</li>
67+
<li>become</li>
68+
<li>box</li>
69+
<li>break</li>
70+
<li>const</li>
71+
<li>continue</li>
72+
<li>crate</li>
73+
<li>do</li>
74+
<li>dyn</li>
75+
<li>else</li>
76+
<li>enum</li>
77+
<li>extern</li>
78+
<li>false</li>
79+
<li>final</li>
80+
<li>fn</li>
81+
<li>for</li>
82+
<li>if</li>
83+
<li>impl</li>
84+
<li>in</li>
85+
<li>let</li>
86+
<li>loop</li>
87+
<li>macro</li>
88+
<li>match</li>
89+
<li>mod</li>
90+
<li>move</li>
91+
<li>mut</li>
92+
<li>override</li>
93+
<li>priv</li>
94+
<li>pub</li>
95+
<li>ref</li>
96+
<li>return</li>
97+
<li>self</li>
98+
<li>static</li>
99+
<li>struct</li>
100+
<li>super</li>
101+
<li>trait</li>
102+
<li>true</li>
103+
<li>try</li>
104+
<li>type</li>
105+
<li>typeof</li>
106+
<li>unsafe</li>
107+
<li>unsized</li>
108+
<li>use</li>
109+
<li>virtual</li>
110+
<li>where</li>
111+
<li>while</li>
112+
<li>yield</li>
113+
</ul>
114+
115+
## FEATURE SET
116+
117+
118+
### Client Modification Feature
119+
| Name | Supported | Defined By |
120+
| ---- | --------- | ---------- |
121+
|BasePath|✓|ToolingExtension
122+
|Authorizations|✗|ToolingExtension
123+
|UserAgent|✗|ToolingExtension
124+
|MockServer|✗|ToolingExtension
125+
126+
### Data Type Feature
127+
| Name | Supported | Defined By |
128+
| ---- | --------- | ---------- |
129+
|Custom|✗|OAS2,OAS3
130+
|Int32|✓|OAS2,OAS3
131+
|Int64|✓|OAS2,OAS3
132+
|Float|✓|OAS2,OAS3
133+
|Double|✓|OAS2,OAS3
134+
|Decimal|✓|ToolingExtension
135+
|String|✓|OAS2,OAS3
136+
|Byte|✓|OAS2,OAS3
137+
|Binary|✓|OAS2,OAS3
138+
|Boolean|✓|OAS2,OAS3
139+
|Date|✓|OAS2,OAS3
140+
|DateTime|✓|OAS2,OAS3
141+
|Password|✓|OAS2,OAS3
142+
|File|✓|OAS2
143+
|Uuid||
144+
|Array|✓|OAS2,OAS3
145+
|Null|✗|OAS3
146+
|AnyType|✗|OAS2,OAS3
147+
|Object|✓|OAS2,OAS3
148+
|Maps|✓|ToolingExtension
149+
|CollectionFormat|✓|OAS2
150+
|CollectionFormatMulti|✓|OAS2
151+
|Enum|✓|OAS2,OAS3
152+
|ArrayOfEnum|✓|ToolingExtension
153+
|ArrayOfModel|✓|ToolingExtension
154+
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
155+
|ArrayOfCollectionOfModel|✓|ToolingExtension
156+
|ArrayOfCollectionOfEnum|✓|ToolingExtension
157+
|MapOfEnum|✓|ToolingExtension
158+
|MapOfModel|✓|ToolingExtension
159+
|MapOfCollectionOfPrimitives|✓|ToolingExtension
160+
|MapOfCollectionOfModel|✓|ToolingExtension
161+
|MapOfCollectionOfEnum|✓|ToolingExtension
162+
163+
### Documentation Feature
164+
| Name | Supported | Defined By |
165+
| ---- | --------- | ---------- |
166+
|Readme|✓|ToolingExtension
167+
|Model|✓|ToolingExtension
168+
|Api|✓|ToolingExtension
169+
170+
### Global Feature
171+
| Name | Supported | Defined By |
172+
| ---- | --------- | ---------- |
173+
|Host|✓|OAS2,OAS3
174+
|BasePath|✓|OAS2,OAS3
175+
|Info|✓|OAS2,OAS3
176+
|Schemes|✗|OAS2,OAS3
177+
|PartialSchemes|✓|OAS2,OAS3
178+
|Consumes|✓|OAS2
179+
|Produces|✓|OAS2
180+
|ExternalDocumentation|✓|OAS2,OAS3
181+
|Examples|✓|OAS2,OAS3
182+
|XMLStructureDefinitions|✗|OAS2,OAS3
183+
|MultiServer|✗|OAS3
184+
|ParameterizedServer|✗|OAS3
185+
|ParameterStyling|✗|OAS3
186+
|Callbacks|✓|OAS3
187+
|LinkObjects|✗|OAS3
188+
189+
### Parameter Feature
190+
| Name | Supported | Defined By |
191+
| ---- | --------- | ---------- |
192+
|Path|✓|OAS2,OAS3
193+
|Query|✓|OAS2,OAS3
194+
|Header|✓|OAS2,OAS3
195+
|Body|✓|OAS2
196+
|FormUnencoded|✓|OAS2
197+
|FormMultipart|✓|OAS2
198+
|Cookie|✗|OAS3
199+
200+
### Schema Support Feature
201+
| Name | Supported | Defined By |
202+
| ---- | --------- | ---------- |
203+
|Simple|✓|OAS2,OAS3
204+
|Composite|✓|OAS2,OAS3
205+
|Polymorphism|✗|OAS2,OAS3
206+
|Union|✗|OAS3
207+
|allOf|✗|OAS2,OAS3
208+
|anyOf|✗|OAS3
209+
|oneOf|✗|OAS3
210+
|not|✗|OAS3
211+
212+
### Security Feature
213+
| Name | Supported | Defined By |
214+
| ---- | --------- | ---------- |
215+
|BasicAuth|✓|OAS2,OAS3
216+
|ApiKey|✓|OAS2,OAS3
217+
|OpenIDConnect|✗|OAS3
218+
|BearerToken|✓|OAS3
219+
|OAuth2_Implicit|✓|OAS2,OAS3
220+
|OAuth2_Password|✗|OAS2,OAS3
221+
|OAuth2_ClientCredentials|✗|OAS2,OAS3
222+
|OAuth2_AuthorizationCode|✗|OAS2,OAS3
223+
|SignatureAuth|✗|OAS3
224+
|AWSV4Signature|✗|ToolingExtension
225+
226+
### Wire Format Feature
227+
| Name | Supported | Defined By |
228+
| ---- | --------- | ---------- |
229+
|JSON|✓|OAS2,OAS3
230+
|XML|✓|OAS2,OAS3
231+
|PROTOBUF|✗|ToolingExtension
232+
|Custom|✓|OAS2,OAS3

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.openapitools.codegen.languages.PhpNextgenClientCodegen;
5555
import org.openapitools.codegen.languages.RustAxumServerCodegen;
5656
import org.openapitools.codegen.languages.RustServerCodegen;
57+
import org.openapitools.codegen.languages.RustServerCodegenDeprecated;
5758
import org.openapitools.codegen.meta.FeatureSet;
5859
import org.openapitools.codegen.meta.GeneratorMetadata;
5960
import org.openapitools.codegen.meta.Stability;
@@ -5328,7 +5329,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
53285329
parameterSchema = unaliasSchema(parameter.getSchema());
53295330
parameterModelName = getParameterDataType(parameter, parameterSchema);
53305331
CodegenProperty prop;
5331-
if (this instanceof RustServerCodegen) {
5332+
if (this instanceof RustServerCodegen || this instanceof RustServerCodegenDeprecated) {
53325333
// for rust server, we need to do something special as it uses
53335334
// $ref (e.g. #components/schemas/Pet) to determine whether it's a model
53345335
prop = fromProperty(parameter.getName(), parameterSchema, false);

0 commit comments

Comments
 (0)