Skip to content

Commit 9827098

Browse files
authored
[Rust] [Server] New generator bases on Axum (#17549)
* Rust Server - Axum based (#5) * Fix typo * Address comment * Address comment
1 parent 210044e commit 9827098

File tree

107 files changed

+35444
-0
lines changed

Some content is hidden

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

107 files changed

+35444
-0
lines changed

.github/workflows/samples-rust.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ on:
66
- "samples/client/others/rust/**"
77
- "samples/server/petstore/rust-server/**"
88
- "samples/client/petstore/rust-server/**"
9+
- "samples/server/petstore/rust-axum/**"
910
pull_request:
1011
paths:
1112
- "samples/client/others/rust/**"
1213
- "samples/client/petstore/rust/**"
1314
- "samples/server/petstore/rust-server/**"
15+
- "samples/server/petstore/rust-axum/**"
1416

1517
jobs:
1618
build:
@@ -24,6 +26,7 @@ jobs:
2426
- samples/client/others/rust/
2527
- samples/client/petstore/rust/
2628
- samples/server/petstore/rust-server/
29+
- samples/server/petstore/rust-axum/
2730
steps:
2831
- uses: actions/checkout@v4
2932
- uses: actions-rs/toolchain@v1

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ cache:
2222
- $HOME/samples/client/petstore/ruby/vendor/bundle
2323
- $HOME/samples/client/petstore/python/.venv/
2424
- $HOME/samples/server/petstore/rust-server/target
25+
- $HOME/samples/server/petstore/rust-axum/target
2526
- $HOME/perl5
2627
- $HOME/.cargo
2728
- $HOME/.pub-cache
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
generatorName: rust-axum
2+
outputDir: samples/server/petstore/rust-axum/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-axum
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
allowBlockingResponseSerialize: "true"
9+
packageName: multipart-v3
10+
enablePostProcessFile: true

bin/configs/rust-axum-openapi-v3.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
generatorName: rust-axum
2+
outputDir: samples/server/petstore/rust-axum/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-axum
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
allowBlockingValidator: "true"
9+
packageName: openapi-v3
10+
enablePostProcessFile: true

bin/configs/rust-axum-ops-v3.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: rust-axum
2+
outputDir: samples/server/petstore/rust-axum/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-axum
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: ops-v3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
generatorName: rust-axum
2+
outputDir: samples/server/petstore/rust-axum/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-axum
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: petstore-with-fake-endpoints-models-for-testing
9+
publishRustRegistry: crates-io
10+
enablePostProcessFile: true

bin/configs/rust-axum-petstore.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
generatorName: rust-axum
2+
outputDir: samples/server/petstore/rust-axum/output/petstore
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/rust-axum
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: petstore
9+
enablePostProcessFile: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
generatorName: rust-axum
2+
outputDir: samples/server/petstore/rust-axum/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-axum
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: ping-bearer-auth
9+
enablePostProcessFile: true

bin/configs/rust-axum-test.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
generatorName: rust-axum
2+
outputDir: samples/server/petstore/rust-axum/output/rust-axum-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-axum
5+
generateAliasAsModel: true
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
packageName: rust-server-test
9+
enablePostProcessFile: true

docs/generators.md

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ The following generators are available:
130130
* [python-flask](generators/python-flask.md)
131131
* [ruby-on-rails](generators/ruby-on-rails.md)
132132
* [ruby-sinatra](generators/ruby-sinatra.md)
133+
* [rust-axum (beta)](generators/rust-axum.md)
133134
* [rust-server](generators/rust-server.md)
134135
* [scala-akka-http-server (beta)](generators/scala-akka-http-server.md)
135136
* [scala-finch](generators/scala-finch.md)

docs/generators/rust-axum.md

+235
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
---
2+
title: Documentation for the rust-axum Generator
3+
---
4+
5+
## METADATA
6+
7+
| Property | Value | Notes |
8+
| -------- | ----- | ----- |
9+
| generator name | rust-axum | pass this to the generate command after -g |
10+
| generator stability | BETA | |
11+
| generator type | SERVER | |
12+
| generator language | Rust | |
13+
| generator default templating engine | mustache | |
14+
| helpTxt | Generates a Rust server library which bases on Axum. | |
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+
|allowBlockingResponseSerialize|By default, json/form-urlencoded response serialization, which might perform a lot of compute in a future without yielding, is executed on a blocking thread via tokio::task::spawn_blocking. Set this option to true will override this behaviour and allow blocking call to happen. It helps to improve the performance when response serialization (e.g. returns tiny data) is low cost.| |false|
22+
|allowBlockingValidator|By default, validation process, which might perform a lot of compute in a future without yielding, is executed on a blocking thread via tokio::task::spawn_blocking. Set this option to true will override this behaviour and allow blocking call to happen. It helps to improve the performance when validating request-data (header, path, query, body) is low cost.| |false|
23+
|disableValidator|Disable validating request-data (header, path, query, body) against OpenAPI Schema Specification.| |false|
24+
|packageName|Rust crate name (convention: snake_case).| |openapi|
25+
|packageVersion|Rust crate version.| |null|
26+
27+
## IMPORT MAPPING
28+
29+
| Type/Alias | Imports |
30+
| ---------- | ------- |
31+
32+
33+
## INSTANTIATION TYPES
34+
35+
| Type/Alias | Instantiated By |
36+
| ---------- | --------------- |
37+
|array|Vec|
38+
|map|std::collections::HashMap|
39+
40+
41+
## LANGUAGE PRIMITIVES
42+
43+
<ul class="column-ul">
44+
<li>String</li>
45+
<li>bool</li>
46+
<li>char</li>
47+
<li>f32</li>
48+
<li>f64</li>
49+
<li>i16</li>
50+
<li>i32</li>
51+
<li>i64</li>
52+
<li>i8</li>
53+
<li>isize</li>
54+
<li>str</li>
55+
<li>u16</li>
56+
<li>u32</li>
57+
<li>u64</li>
58+
<li>u8</li>
59+
<li>usize</li>
60+
</ul>
61+
62+
## RESERVED WORDS
63+
64+
<ul class="column-ul">
65+
<li>Self</li>
66+
<li>abstract</li>
67+
<li>as</li>
68+
<li>async</li>
69+
<li>await</li>
70+
<li>become</li>
71+
<li>box</li>
72+
<li>break</li>
73+
<li>const</li>
74+
<li>continue</li>
75+
<li>crate</li>
76+
<li>do</li>
77+
<li>dyn</li>
78+
<li>else</li>
79+
<li>enum</li>
80+
<li>extern</li>
81+
<li>false</li>
82+
<li>final</li>
83+
<li>fn</li>
84+
<li>for</li>
85+
<li>if</li>
86+
<li>impl</li>
87+
<li>in</li>
88+
<li>let</li>
89+
<li>loop</li>
90+
<li>macro</li>
91+
<li>match</li>
92+
<li>mod</li>
93+
<li>move</li>
94+
<li>mut</li>
95+
<li>override</li>
96+
<li>priv</li>
97+
<li>pub</li>
98+
<li>ref</li>
99+
<li>return</li>
100+
<li>self</li>
101+
<li>static</li>
102+
<li>struct</li>
103+
<li>super</li>
104+
<li>trait</li>
105+
<li>true</li>
106+
<li>try</li>
107+
<li>type</li>
108+
<li>typeof</li>
109+
<li>unsafe</li>
110+
<li>unsized</li>
111+
<li>use</li>
112+
<li>virtual</li>
113+
<li>where</li>
114+
<li>while</li>
115+
<li>yield</li>
116+
</ul>
117+
118+
## FEATURE SET
119+
120+
121+
### Client Modification Feature
122+
| Name | Supported | Defined By |
123+
| ---- | --------- | ---------- |
124+
|BasePath|✗|ToolingExtension
125+
|Authorizations|✗|ToolingExtension
126+
|UserAgent|✗|ToolingExtension
127+
|MockServer|✗|ToolingExtension
128+
129+
### Data Type Feature
130+
| Name | Supported | Defined By |
131+
| ---- | --------- | ---------- |
132+
|Custom|✗|OAS2,OAS3
133+
|Int32|✓|OAS2,OAS3
134+
|Int64|✓|OAS2,OAS3
135+
|Float|✓|OAS2,OAS3
136+
|Double|✓|OAS2,OAS3
137+
|Decimal|✓|ToolingExtension
138+
|String|✓|OAS2,OAS3
139+
|Byte|✓|OAS2,OAS3
140+
|Binary|✓|OAS2,OAS3
141+
|Boolean|✓|OAS2,OAS3
142+
|Date|✓|OAS2,OAS3
143+
|DateTime|✓|OAS2,OAS3
144+
|Password|✓|OAS2,OAS3
145+
|File|✓|OAS2
146+
|Uuid||
147+
|Array|✓|OAS2,OAS3
148+
|Null|✗|OAS3
149+
|AnyType|✗|OAS2,OAS3
150+
|Object|✓|OAS2,OAS3
151+
|Maps|✓|ToolingExtension
152+
|CollectionFormat|✓|OAS2
153+
|CollectionFormatMulti|✓|OAS2
154+
|Enum|✓|OAS2,OAS3
155+
|ArrayOfEnum|✓|ToolingExtension
156+
|ArrayOfModel|✓|ToolingExtension
157+
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
158+
|ArrayOfCollectionOfModel|✓|ToolingExtension
159+
|ArrayOfCollectionOfEnum|✓|ToolingExtension
160+
|MapOfEnum|✓|ToolingExtension
161+
|MapOfModel|✓|ToolingExtension
162+
|MapOfCollectionOfPrimitives|✓|ToolingExtension
163+
|MapOfCollectionOfModel|✓|ToolingExtension
164+
|MapOfCollectionOfEnum|✓|ToolingExtension
165+
166+
### Documentation Feature
167+
| Name | Supported | Defined By |
168+
| ---- | --------- | ---------- |
169+
|Readme|✗|ToolingExtension
170+
|Model|✓|ToolingExtension
171+
|Api|✓|ToolingExtension
172+
173+
### Global Feature
174+
| Name | Supported | Defined By |
175+
| ---- | --------- | ---------- |
176+
|Host|✓|OAS2,OAS3
177+
|BasePath|✓|OAS2,OAS3
178+
|Info|✗|OAS2,OAS3
179+
|Schemes|✗|OAS2,OAS3
180+
|PartialSchemes|✓|OAS2,OAS3
181+
|Consumes|✓|OAS2
182+
|Produces|✓|OAS2
183+
|ExternalDocumentation|✗|OAS2,OAS3
184+
|Examples|✗|OAS2,OAS3
185+
|XMLStructureDefinitions|✗|OAS2,OAS3
186+
|MultiServer|✗|OAS3
187+
|ParameterizedServer|✗|OAS3
188+
|ParameterStyling|✗|OAS3
189+
|Callbacks|✗|OAS3
190+
|LinkObjects|✗|OAS3
191+
192+
### Parameter Feature
193+
| Name | Supported | Defined By |
194+
| ---- | --------- | ---------- |
195+
|Path|✓|OAS2,OAS3
196+
|Query|✓|OAS2,OAS3
197+
|Header|✓|OAS2,OAS3
198+
|Body|✓|OAS2
199+
|FormUnencoded|✓|OAS2
200+
|FormMultipart|✓|OAS2
201+
|Cookie|✗|OAS3
202+
203+
### Schema Support Feature
204+
| Name | Supported | Defined By |
205+
| ---- | --------- | ---------- |
206+
|Simple|✓|OAS2,OAS3
207+
|Composite|✓|OAS2,OAS3
208+
|Polymorphism|✗|OAS2,OAS3
209+
|Union|✗|OAS3
210+
|allOf|✗|OAS2,OAS3
211+
|anyOf|✗|OAS3
212+
|oneOf|✗|OAS3
213+
|not|✗|OAS3
214+
215+
### Security Feature
216+
| Name | Supported | Defined By |
217+
| ---- | --------- | ---------- |
218+
|BasicAuth|✓|OAS2,OAS3
219+
|ApiKey|✓|OAS2,OAS3
220+
|OpenIDConnect|✗|OAS3
221+
|BearerToken|✓|OAS3
222+
|OAuth2_Implicit|✓|OAS2,OAS3
223+
|OAuth2_Password|✓|OAS2,OAS3
224+
|OAuth2_ClientCredentials|✓|OAS2,OAS3
225+
|OAuth2_AuthorizationCode|✓|OAS2,OAS3
226+
|SignatureAuth|✗|OAS3
227+
|AWSV4Signature|✗|ToolingExtension
228+
229+
### Wire Format Feature
230+
| Name | Supported | Defined By |
231+
| ---- | --------- | ---------- |
232+
|JSON|✓|OAS2,OAS3
233+
|XML|✗|OAS2,OAS3
234+
|PROTOBUF|✗|ToolingExtension
235+
|Custom|✓|OAS2,OAS3

0 commit comments

Comments
 (0)