Skip to content

Commit

Permalink
import autorust_openapi (Azure#328)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ctaggart authored Aug 30, 2021
1 parent 5350f09 commit 1f2162a
Show file tree
Hide file tree
Showing 36 changed files with 1,554 additions and 45 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,42 @@ jobs:
run: df -h /
if: ${{ always() }}

test-autorust:
name: test AutoRust
runs-on: ubuntu-20.04
steps:
- name: git clone
uses: actions/checkout@v2
with:
path: azure-sdk-for-rust
- name: install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
components: rustfmt
- name: fmt check
run: |
cd azure-sdk-for-rust/services/autorust
cargo fmt --all -- --check
- name: unit tests
run: |
cd azure-sdk-for-rust/services/autorust
cargo test --lib
- name: git clone Azure/azure-rest-api-specs
uses: actions/checkout@v2
with:
repository: Azure/azure-rest-api-specs
path: azure-rest-api-specs
- name: git clone OAI/OpenAPI-Specification
uses: actions/checkout@v2
with:
repository: OAI/OpenAPI-Specification
path: OpenAPI-Specification
- name: integration tests
run: |
cd azure-sdk-for-rust/services/autorust
cargo test --package autorust_openapi --test openapi_spec_examples
cargo test --package autorust_openapi --test azure_rest_api_specs
cargo test --package autorust_codegen --test azure_rest_api_specs
80 changes: 80 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
azure-sdk-for-rust

NOTICES AND INFORMATION
Do Not Translate or Localize

This software incorporates material from third parties. Microsoft makes certain
open source code available at https://3rdpartysource.microsoft.com, or you may
send a check or money order for US $5.00, including the product name, the open
source component name, and version number, to:

Source Code Compliance Team
Microsoft Corporation
One Microsoft Way
Redmond, WA 98052
USA

Notwithstanding any other terms, you may reverse engineer this software to the
extent required to debug changes to any libraries licensed under the GNU Lesser
General Public License.

------------------------------------------------------------------------------

Azure SDK for Rust uses third-party libraries or other resources that may be
distributed under licenses different than the Azure SDK for Rust software.

In the event that we accidentally failed to list a required notice, please
bring it to our attention. Post an issue.

The attached notices are provided for information only.

License notice for softprops/openapi
------------------------------------------------------------------------------

Copyright (c) 2017 Doug Tangren

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

License notice for glademiller/openapiv3
------------------------------------------------------------------------------

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
33 changes: 0 additions & 33 deletions services/autorust/.github/workflows/ci.yml

This file was deleted.

1 change: 1 addition & 0 deletions services/autorust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
members = [
"autorust",
"codegen",
"openapi",
]
17 changes: 8 additions & 9 deletions services/autorust/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ edition = "2018"
[lib]

[dependencies]
autorust_openapi = { git = "https://github.com/ctaggart/autorust_openapi" }
# autorust_openapi = { path = "../autorust_openapi" }
quote = "*"
proc-macro2 = { version = "*", default-features = false }
serde_json = "*"
serde_yaml = "*"
heck = "*"
autorust_openapi = { path = "../openapi" }
quote = "1.0"
proc-macro2 = { version = "1.0", default-features = false }
serde_json = "1.0"
serde_yaml = "0.8"
heck = "0.3"
regex = "*"
indexmap = { version = "*", features = ["serde-1"] }
path_abs = "*"
indexmap = { version = "1.7", features = ["serde-1"] }
path_abs = "0.5"
comrak = "0.8"
serde = "1.0"
thiserror = "1.0"
Expand Down
7 changes: 4 additions & 3 deletions services/autorust/codegen/tests/azure_rest_api_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use std::path::PathBuf;

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

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

#[test]
fn refs_count_security_common() -> Result<()> {
Expand Down Expand Up @@ -42,7 +43,7 @@ fn read_spec_avs() -> Result<()> {
let spec = &Spec::read_files(&[VMWARE_SPEC])?;
assert_eq!(2, spec.docs().len());
assert!(spec.docs().contains_key(std::path::Path::new(
"../../azure-rest-api-specs/specification/common-types/resource-management/v1/types.json"
"../../../../azure-rest-api-specs/specification/common-types/resource-management/v1/types.json"
)));
Ok(())
}
Expand Down
3 changes: 3 additions & 0 deletions services/autorust/openapi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
Cargo.lock
*.bk
53 changes: 53 additions & 0 deletions services/autorust/openapi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 0.2
* forked as autorust_openapi
* removed OpenAPI v3 support. Use openapiv3 crate
* moved v2 module to be the root module
* removed serde_yaml, url, serde_url, semver, error-chain, & failure dependencies
* switched CI from Travis CI to GitHub Actions
* removed pretty_assertions dev-dependencies
* added serde_ignored dev-dependency
* added integration tests for OpenAPI v2 specification examples
* added integration tests for azure-rest-api-specs specifications
* added --example ignored
* add `ReferenceOr<T>` from openapiv3
* replace `ParameterOrRef` with `ReferenceOr<Parameter>`
* rename `Spec` to `OpenAPI` to match openapiv3
* replace `Option<Vec<T>>` with `Vec<T>` and skip if `is_empty` like openapiv3
* add dependency on `indexmap` like openapiv3
* use `is_empty` on `IndexMap` instead of wrapping in `Option<T>` like openapiv3
* added missing Schema Object & Parameter Object fields
* added StatusCode based on openapiv3

* expose security definition as an enum type
* Adds License object
* Adds Contact object
* Derives Default for all structs
* Derives Clone for all structs
* Changes the order of the output to be more similar to OpenAPI examples
* switch to 2018 edition

# 0.1.5

* expose other schema types as public interfaces
* re-export Result and ResultExt as top level interfaces

# 0.1.4

* added operational `parameters` field to `Operations` object

# 0.1.3

* added optional `required` and `enum_values` fields to `Schema` object

# 0.1.2

* added optional `format` fields to `Parameter` object

# 0.1.1

* added optional `summary` field to `Operation` object
* made schemes and tags optional fields on `Operation` object

# 0.1.0

* initial release
20 changes: 20 additions & 0 deletions services/autorust/openapi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "autorust_openapi"
version = "0.2.0"
authors = ["Cameron Taggart <[email protected]>", "softprops <[email protected]>"]
description = "Rust bindings for OpenAPI v2 as needed by autorust"
documentation = "https://docs.rs/autorust_openapi"
homepage = "https://github.com/ctaggart/autorust_openapi"
repository = "https://github.com/ctaggart/autorust_openapi"
keywords = ["openapi", "swagger", "AutoRest", "autorust"]
license = "MIT"
edition = "2018"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
indexmap = {version = "1.0", features = ["serde-1"]}

[dev-dependencies]
assert-json-diff = "2.0"
serde_yaml = "0.8"
21 changes: 21 additions & 0 deletions services/autorust/openapi/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) 2020 Cameron Taggart
Copyright (c) 2017 Doug Tangren

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 changes: 17 additions & 0 deletions services/autorust/openapi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# autorust_openapi [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)

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).

## Install

Add the following to your `Cargo.toml` file:

```toml
[dependencies]
autorust_openapi = { git = "https://github.com/ctaggart/autorust_openapi" }
```

## Similar Crates

- 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.
- 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).
43 changes: 43 additions & 0 deletions services/autorust/openapi/examples/operation_ids.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Print the operation IDs alphabetically
// cargo run --example operation_ids -- ../azure-rest-api-specs/specification/vmware/resource-manager/Microsoft.AVS/stable/2020-03-20/vmware.json

use autorust_openapi::*;
use std::{
fs::{self},
path::Path,
process::exit,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
match std::env::args().nth(1) {
None => {
eprintln!("Please pass in the spec path.");
exit(1);
}
Some(file_in) => {
let file_in = Path::new(&file_in);
let bytes = fs::read(file_in)?;
let api: OpenAPI = serde_json::from_slice(&bytes)?;

let mut operation_ids = Vec::new();
for (_path, item) in &api.paths {
match item {
ReferenceOr::Reference { .. } => (),
ReferenceOr::Item(item) => {
for op in item.operations() {
if let Some(operation_id) = &op.operation_id {
operation_ids.push(operation_id);
}
}
}
}
}

operation_ids.sort();
for operation_id in operation_ids {
println!("{}", operation_id);
}
}
}
Ok(())
}
Loading

0 comments on commit 1f2162a

Please sign in to comment.