Skip to content

Commit 1f2162a

Browse files
authored
import autorust_openapi (Azure#328)
* copy of ctaggart/autorust_openapi@fc2f579 * build autorust * cd services/autorust * use base_dir * remove custom path * $GITHUB_WORKSPACE * echo pwd * echo pwd * echo $PWD * specify paths * use separate paths for repositories * test openapi_spec_examples too * Copyright (c) 2020 Cameron Taggart * set major.minor versions * versions for dev-dependencies * name: test AutoRust * add NOTICE.txt for https://github.com/softprops/openapi/blob/master/LICENSE https://github.com/glademiller/openapiv3/blob/master/LICENSE-MIT
1 parent 5350f09 commit 1f2162a

36 files changed

+1554
-45
lines changed

.github/workflows/build.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,42 @@ jobs:
134134
run: df -h /
135135
if: ${{ always() }}
136136

137+
test-autorust:
138+
name: test AutoRust
139+
runs-on: ubuntu-20.04
140+
steps:
141+
- name: git clone
142+
uses: actions/checkout@v2
143+
with:
144+
path: azure-sdk-for-rust
145+
- name: install rust
146+
uses: actions-rs/toolchain@v1
147+
with:
148+
toolchain: stable
149+
profile: minimal
150+
override: true
151+
components: rustfmt
152+
- name: fmt check
153+
run: |
154+
cd azure-sdk-for-rust/services/autorust
155+
cargo fmt --all -- --check
156+
- name: unit tests
157+
run: |
158+
cd azure-sdk-for-rust/services/autorust
159+
cargo test --lib
160+
- name: git clone Azure/azure-rest-api-specs
161+
uses: actions/checkout@v2
162+
with:
163+
repository: Azure/azure-rest-api-specs
164+
path: azure-rest-api-specs
165+
- name: git clone OAI/OpenAPI-Specification
166+
uses: actions/checkout@v2
167+
with:
168+
repository: OAI/OpenAPI-Specification
169+
path: OpenAPI-Specification
170+
- name: integration tests
171+
run: |
172+
cd azure-sdk-for-rust/services/autorust
173+
cargo test --package autorust_openapi --test openapi_spec_examples
174+
cargo test --package autorust_openapi --test azure_rest_api_specs
175+
cargo test --package autorust_codegen --test azure_rest_api_specs

NOTICE.txt

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
azure-sdk-for-rust
2+
3+
NOTICES AND INFORMATION
4+
Do Not Translate or Localize
5+
6+
This software incorporates material from third parties. Microsoft makes certain
7+
open source code available at https://3rdpartysource.microsoft.com, or you may
8+
send a check or money order for US $5.00, including the product name, the open
9+
source component name, and version number, to:
10+
11+
Source Code Compliance Team
12+
Microsoft Corporation
13+
One Microsoft Way
14+
Redmond, WA 98052
15+
USA
16+
17+
Notwithstanding any other terms, you may reverse engineer this software to the
18+
extent required to debug changes to any libraries licensed under the GNU Lesser
19+
General Public License.
20+
21+
------------------------------------------------------------------------------
22+
23+
Azure SDK for Rust uses third-party libraries or other resources that may be
24+
distributed under licenses different than the Azure SDK for Rust software.
25+
26+
In the event that we accidentally failed to list a required notice, please
27+
bring it to our attention. Post an issue.
28+
29+
The attached notices are provided for information only.
30+
31+
License notice for softprops/openapi
32+
------------------------------------------------------------------------------
33+
34+
Copyright (c) 2017 Doug Tangren
35+
36+
Permission is hereby granted, free of charge, to any person obtaining
37+
a copy of this software and associated documentation files (the
38+
"Software"), to deal in the Software without restriction, including
39+
without limitation the rights to use, copy, modify, merge, publish,
40+
distribute, sublicense, and/or sell copies of the Software, and to
41+
permit persons to whom the Software is furnished to do so, subject to
42+
the following conditions:
43+
44+
The above copyright notice and this permission notice shall be
45+
included in all copies or substantial portions of the Software.
46+
47+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
51+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
52+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
53+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
54+
55+
License notice for glademiller/openapiv3
56+
------------------------------------------------------------------------------
57+
58+
Permission is hereby granted, free of charge, to any
59+
person obtaining a copy of this software and associated
60+
documentation files (the "Software"), to deal in the
61+
Software without restriction, including without
62+
limitation the rights to use, copy, modify, merge,
63+
publish, distribute, sublicense, and/or sell copies of
64+
the Software, and to permit persons to whom the Software
65+
is furnished to do so, subject to the following
66+
conditions:
67+
68+
The above copyright notice and this permission notice
69+
shall be included in all copies or substantial portions
70+
of the Software.
71+
72+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
73+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
74+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
75+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
76+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
77+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
78+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
79+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
80+
DEALINGS IN THE SOFTWARE.

services/autorust/.github/workflows/ci.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

services/autorust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
members = [
33
"autorust",
44
"codegen",
5+
"openapi",
56
]

services/autorust/codegen/Cargo.toml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ edition = "2018"
77
[lib]
88

99
[dependencies]
10-
autorust_openapi = { git = "https://github.com/ctaggart/autorust_openapi" }
11-
# autorust_openapi = { path = "../autorust_openapi" }
12-
quote = "*"
13-
proc-macro2 = { version = "*", default-features = false }
14-
serde_json = "*"
15-
serde_yaml = "*"
16-
heck = "*"
10+
autorust_openapi = { path = "../openapi" }
11+
quote = "1.0"
12+
proc-macro2 = { version = "1.0", default-features = false }
13+
serde_json = "1.0"
14+
serde_yaml = "0.8"
15+
heck = "0.3"
1716
regex = "*"
18-
indexmap = { version = "*", features = ["serde-1"] }
19-
path_abs = "*"
17+
indexmap = { version = "1.7", features = ["serde-1"] }
18+
path_abs = "0.5"
2019
comrak = "0.8"
2120
serde = "1.0"
2221
thiserror = "1.0"

services/autorust/codegen/tests/azure_rest_api_specs.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use std::path::PathBuf;
99

1010
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
1111

12-
const COMMON_TYPES_SPEC: &str = "../../azure-rest-api-specs/specification/security/resource-manager/common/v1/types.json";
13-
const VMWARE_SPEC: &str = "../../azure-rest-api-specs/specification/vmware/resource-manager/Microsoft.AVS/stable/2020-03-20/vmware.json";
12+
const COMMON_TYPES_SPEC: &str = "../../../../azure-rest-api-specs/specification/security/resource-manager/common/v1/types.json";
13+
const VMWARE_SPEC: &str =
14+
"../../../../azure-rest-api-specs/specification/vmware/resource-manager/Microsoft.AVS/stable/2020-03-20/vmware.json";
1415

1516
#[test]
1617
fn refs_count_security_common() -> Result<()> {
@@ -42,7 +43,7 @@ fn read_spec_avs() -> Result<()> {
4243
let spec = &Spec::read_files(&[VMWARE_SPEC])?;
4344
assert_eq!(2, spec.docs().len());
4445
assert!(spec.docs().contains_key(std::path::Path::new(
45-
"../../azure-rest-api-specs/specification/common-types/resource-management/v1/types.json"
46+
"../../../../azure-rest-api-specs/specification/common-types/resource-management/v1/types.json"
4647
)));
4748
Ok(())
4849
}

services/autorust/openapi/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target
2+
Cargo.lock
3+
*.bk
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# 0.2
2+
* forked as autorust_openapi
3+
* removed OpenAPI v3 support. Use openapiv3 crate
4+
* moved v2 module to be the root module
5+
* removed serde_yaml, url, serde_url, semver, error-chain, & failure dependencies
6+
* switched CI from Travis CI to GitHub Actions
7+
* removed pretty_assertions dev-dependencies
8+
* added serde_ignored dev-dependency
9+
* added integration tests for OpenAPI v2 specification examples
10+
* added integration tests for azure-rest-api-specs specifications
11+
* added --example ignored
12+
* add `ReferenceOr<T>` from openapiv3
13+
* replace `ParameterOrRef` with `ReferenceOr<Parameter>`
14+
* rename `Spec` to `OpenAPI` to match openapiv3
15+
* replace `Option<Vec<T>>` with `Vec<T>` and skip if `is_empty` like openapiv3
16+
* add dependency on `indexmap` like openapiv3
17+
* use `is_empty` on `IndexMap` instead of wrapping in `Option<T>` like openapiv3
18+
* added missing Schema Object & Parameter Object fields
19+
* added StatusCode based on openapiv3
20+
21+
* expose security definition as an enum type
22+
* Adds License object
23+
* Adds Contact object
24+
* Derives Default for all structs
25+
* Derives Clone for all structs
26+
* Changes the order of the output to be more similar to OpenAPI examples
27+
* switch to 2018 edition
28+
29+
# 0.1.5
30+
31+
* expose other schema types as public interfaces
32+
* re-export Result and ResultExt as top level interfaces
33+
34+
# 0.1.4
35+
36+
* added operational `parameters` field to `Operations` object
37+
38+
# 0.1.3
39+
40+
* added optional `required` and `enum_values` fields to `Schema` object
41+
42+
# 0.1.2
43+
44+
* added optional `format` fields to `Parameter` object
45+
46+
# 0.1.1
47+
48+
* added optional `summary` field to `Operation` object
49+
* made schemes and tags optional fields on `Operation` object
50+
51+
# 0.1.0
52+
53+
* initial release

services/autorust/openapi/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "autorust_openapi"
3+
version = "0.2.0"
4+
authors = ["Cameron Taggart <[email protected]>", "softprops <[email protected]>"]
5+
description = "Rust bindings for OpenAPI v2 as needed by autorust"
6+
documentation = "https://docs.rs/autorust_openapi"
7+
homepage = "https://github.com/ctaggart/autorust_openapi"
8+
repository = "https://github.com/ctaggart/autorust_openapi"
9+
keywords = ["openapi", "swagger", "AutoRest", "autorust"]
10+
license = "MIT"
11+
edition = "2018"
12+
13+
[dependencies]
14+
serde = { version = "1.0", features = ["derive"] }
15+
serde_json = "1.0"
16+
indexmap = {version = "1.0", features = ["serde-1"]}
17+
18+
[dev-dependencies]
19+
assert-json-diff = "2.0"
20+
serde_yaml = "0.8"

services/autorust/openapi/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) 2020 Cameron Taggart
2+
Copyright (c) 2017 Doug Tangren
3+
4+
Permission is hereby granted, free of charge, to any person obtaining
5+
a copy of this software and associated documentation files (the
6+
"Software"), to deal in the Software without restriction, including
7+
without limitation the rights to use, copy, modify, merge, publish,
8+
distribute, sublicense, and/or sell copies of the Software, and to
9+
permit persons to whom the Software is furnished to do so, subject to
10+
the following conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

services/autorust/openapi/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# autorust_openapi [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)
2+
3+
Rust crate for deserializing [OpenAPI](http://swagger.io/specification/) documents as needed by [autorust](https://github.com/ctaggart/autorust/), an AutoRest extension. The goal is to be able to deserialize all of the documents found in [Azure/azure-rest-api-specs/specification](https://github.com/Azure/azure-rest-api-specs/tree/master/specification). They follow [OpenAPI Specfication Version 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameter-object) and use several [extensions](https://github.com/Azure/autorest/blob/master/docs/extensions/readme.md).
4+
5+
## Install
6+
7+
Add the following to your `Cargo.toml` file:
8+
9+
```toml
10+
[dependencies]
11+
autorust_openapi = { git = "https://github.com/ctaggart/autorust_openapi" }
12+
```
13+
14+
## Similar Crates
15+
16+
- This is a fork of the [openapi crate](https://crates.io/crates/openapi), maintained at [softprops/openapi](https://github.com/softprops/openapi). It was created by Doug Tangren (softprops) in 2017.
17+
- The [openapiv3 crate](https://github.com/glademiller/openapiv3) was created by Glade Miller in 2019 and is maintained at [glademiller/openapiv3](https://github.com/glademiller/openapiv3).
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Print the operation IDs alphabetically
2+
// cargo run --example operation_ids -- ../azure-rest-api-specs/specification/vmware/resource-manager/Microsoft.AVS/stable/2020-03-20/vmware.json
3+
4+
use autorust_openapi::*;
5+
use std::{
6+
fs::{self},
7+
path::Path,
8+
process::exit,
9+
};
10+
11+
fn main() -> Result<(), Box<dyn std::error::Error>> {
12+
match std::env::args().nth(1) {
13+
None => {
14+
eprintln!("Please pass in the spec path.");
15+
exit(1);
16+
}
17+
Some(file_in) => {
18+
let file_in = Path::new(&file_in);
19+
let bytes = fs::read(file_in)?;
20+
let api: OpenAPI = serde_json::from_slice(&bytes)?;
21+
22+
let mut operation_ids = Vec::new();
23+
for (_path, item) in &api.paths {
24+
match item {
25+
ReferenceOr::Reference { .. } => (),
26+
ReferenceOr::Item(item) => {
27+
for op in item.operations() {
28+
if let Some(operation_id) = &op.operation_id {
29+
operation_ids.push(operation_id);
30+
}
31+
}
32+
}
33+
}
34+
}
35+
36+
operation_ids.sort();
37+
for operation_id in operation_ids {
38+
println!("{}", operation_id);
39+
}
40+
}
41+
}
42+
Ok(())
43+
}

0 commit comments

Comments
 (0)