Skip to content

Commit 055d87e

Browse files
cataggarctaggartheaths
authored
add links & README.md for services (Azure#695)
Co-authored-by: Cameron Taggart <cameron.taggart@gmail.com> Co-authored-by: Heath Stewart <heaths@outlook.com>
1 parent 490f4c3 commit 055d87e

File tree

477 files changed

+2357
-517
lines changed

Some content is hidden

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

477 files changed

+2357
-517
lines changed

services/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- [#672](https://github.com/Azure/azure-sdk-for-rust/pull/672) generated from azure-rest-api-specs [commit from 2022-03-02](https://github.com/Azure/azure-rest-api-specs/commit/c56b44b794ff17caad4d31c6ab64b07e28253504)
44
- [#675](https://github.com/Azure/azure-sdk-for-rust/pull/675) use Basic Information tag for default version
55
- [#634](https://github.com/Azure/azure-sdk-for-rust/issues/634) limit docs.rs to 5 API tags
6+
- [#632](https://github.com/Azure/azure-sdk-for-rust/issues/632) add links & README.md for services
67

78
# 0.1 (2022-01)
89

services/autorust/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ model*.rs
88
generated
99
node_modules
1010
package*.json
11+
gen_readme.md

services/autorust/codegen/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "autorust_codegen"
33
version = "0.1.0"
44
authors = ["Cameron Taggart <cameron.taggart@gmail.com>"]
55
edition = "2018"
6+
publish = false
67

78
[lib]
89

@@ -23,3 +24,4 @@ http = "0.2"
2324
once_cell = "1.7"
2425
syn = { version = "1.0", features = ["parsing"] }
2526
camino = "1.0"
27+
askama = "0.11"

services/autorust/codegen/examples/gen_mgmt.rs

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
// cargo run --example gen_mgmt --release
22
// https://github.com/Azure/azure-rest-api-specs/blob/master/specification/compute/resource-manager
3-
use autorust_codegen::{self, cargo_toml, get_mgmt_readmes, lib_rs, path, Config, PropertyName, SpecReadme};
4-
use std::{collections::HashSet, fs, path::PathBuf};
3+
use autorust_codegen::{
4+
self, cargo_toml, get_mgmt_readmes, io, lib_rs,
5+
readme_md::{self, ReadmeMd},
6+
Config, Error, PropertyName, Result, SpecReadme,
7+
};
8+
use camino::Utf8PathBuf;
9+
use std::{collections::HashSet, fs};
510

611
const OUTPUT_FOLDER: &str = "../mgmt";
712

@@ -293,24 +298,6 @@ const BOX_PROPERTIES: &[(&str, &str, &str)] = &[
293298
("../../../azure-rest-api-specs/specification/keyvault/resource-manager/Microsoft.KeyVault/stable/2021-10-01/managedHsm.json", "Error", "innererror"),
294299
];
295300

296-
pub type Result<T, E = Error> = std::result::Result<T, E>;
297-
298-
#[derive(Debug, thiserror::Error)]
299-
pub enum Error {
300-
#[error(transparent)]
301-
CodegenError(#[from] autorust_codegen::Error),
302-
#[error("file name was not utf-8")]
303-
FileNameNotUtf8Error {},
304-
#[error("IoError")]
305-
IoError { source: std::io::Error },
306-
#[error("PathError")]
307-
PathError { source: path::Error },
308-
#[error("CargoTomlError")]
309-
CargoTomlError { source: cargo_toml::Error },
310-
#[error("LibRsError")]
311-
LibRsError { source: lib_rs::Error },
312-
}
313-
314301
fn main() -> Result<()> {
315302
for (i, spec) in get_mgmt_readmes()?.iter().enumerate() {
316303
if !ONLY_SERVICES.is_empty() {
@@ -329,11 +316,11 @@ fn main() -> Result<()> {
329316
fn gen_crate(spec: &SpecReadme) -> Result<()> {
330317
let service_name = &spec.service_name();
331318
let crate_name = &format!("azure_mgmt_{}", service_name);
332-
let output_folder = &path::join(OUTPUT_FOLDER, service_name).map_err(|source| Error::PathError { source })?;
319+
let output_folder = &io::join(OUTPUT_FOLDER, service_name)?;
333320

334-
let src_folder = path::join(output_folder, "src").map_err(|source| Error::PathError { source })?;
321+
let src_folder = io::join(output_folder, "src")?;
335322
if src_folder.exists() {
336-
fs::remove_dir_all(&src_folder).map_err(|source| Error::IoError { source })?;
323+
fs::remove_dir_all(&src_folder)?;
337324
}
338325

339326
let mut tags = Vec::new();
@@ -342,7 +329,7 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
342329
let mut box_properties = HashSet::new();
343330
for (file_path, schema_name, property_name) in BOX_PROPERTIES {
344331
box_properties.insert(PropertyName {
345-
file_path: PathBuf::from(file_path),
332+
file_path: Utf8PathBuf::from(file_path),
346333
schema_name: schema_name.to_string(),
347334
property_name: property_name.to_string(),
348335
});
@@ -351,7 +338,7 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
351338
let mut optional_properties = HashSet::new();
352339
for (file_path, schema_name, property_name) in OPTIONAL_PROPERTIES {
353340
optional_properties.insert(PropertyName {
354-
file_path: PathBuf::from(file_path),
341+
file_path: Utf8PathBuf::from(file_path),
355342
schema_name: schema_name.to_string(),
356343
property_name: property_name.to_string(),
357344
});
@@ -365,12 +352,12 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
365352
continue;
366353
}
367354
println!(" {}", tag_name);
368-
let mod_output_folder = path::join(&src_folder, &tag.rust_mod_name()).map_err(|source| Error::PathError { source })?;
355+
let mod_output_folder = io::join(&src_folder, &tag.rust_mod_name())?;
369356
tags.push(tag);
370357
let input_files: Result<Vec<_>> = tag
371358
.input_files()
372359
.iter()
373-
.map(|input_file| path::join(spec.readme(), input_file).map_err(|source| Error::PathError { source }))
360+
.map(|input_file| io::join(spec.readme(), input_file).map_err(Error::from))
374361
.collect();
375362
let input_files = input_files?;
376363
autorust_codegen::run(Config {
@@ -385,19 +372,14 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
385372
if tags.is_empty() {
386373
return Ok(());
387374
}
388-
cargo_toml::create(
375+
cargo_toml::create(crate_name, &tags, config.tag(), &io::join(output_folder, "Cargo.toml")?)?;
376+
lib_rs::create(&tags, &io::join(src_folder, "lib.rs")?, false)?;
377+
378+
let readme = ReadmeMd {
389379
crate_name,
390-
&tags,
391-
config.tag(),
392-
&path::join(output_folder, "Cargo.toml").map_err(|source| Error::PathError { source })?,
393-
)
394-
.map_err(|source| Error::CargoTomlError { source })?;
395-
lib_rs::create(
396-
&tags,
397-
&path::join(src_folder, "lib.rs").map_err(|source| Error::PathError { source })?,
398-
false,
399-
)
400-
.map_err(|source| Error::LibRsError { source })?;
380+
readme_url: readme_md::url(spec.readme().as_str()),
381+
};
382+
readme.create(&io::join(output_folder, "README.md")?)?;
401383

402384
Ok(())
403385
}

services/autorust/codegen/examples/gen_svc.rs

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// cargo run --example gen_svc --release
22
// https://github.com/Azure/azure-rest-api-specs/blob/master/specification/batch/data-plane
33
use autorust_codegen::{
4-
self,
5-
cargo_toml::{self},
6-
get_svc_readmes, lib_rs, path, Config, PropertyName, SpecReadme,
4+
self, cargo_toml, get_svc_readmes, io, lib_rs,
5+
readme_md::{self, ReadmeMd},
6+
Config, Error, PropertyName, Result, SpecReadme,
77
};
8-
use std::{collections::HashSet, fs, path::PathBuf};
8+
use camino::Utf8PathBuf;
9+
use std::{collections::HashSet, fs};
910

1011
const OUTPUT_FOLDER: &str = "../svc";
1112

@@ -166,24 +167,6 @@ const BOX_PROPERTIES: &[(&str, &str, &str)] = &[
166167
),
167168
];
168169

169-
pub type Result<T, E = Error> = std::result::Result<T, E>;
170-
171-
#[derive(Debug, thiserror::Error)]
172-
pub enum Error {
173-
#[error(transparent)]
174-
CodegenError(#[from] autorust_codegen::Error),
175-
#[error("file name was not utf-8")]
176-
FileNameNotUtf8Error {},
177-
#[error("IoError")]
178-
IoError { source: std::io::Error },
179-
#[error("PathError")]
180-
PathError { source: path::Error },
181-
#[error("CargoTomlError")]
182-
CargoTomlError { source: cargo_toml::Error },
183-
#[error("LibRsError")]
184-
LibRsError { source: lib_rs::Error },
185-
}
186-
187170
fn main() -> Result<()> {
188171
for (i, spec) in get_svc_readmes()?.iter().enumerate() {
189172
if !ONLY_SERVICES.is_empty() {
@@ -210,11 +193,11 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
210193

211194
let service_name = &spec.service_name();
212195
let crate_name = &format!("azure_svc_{}", service_name);
213-
let output_folder = &path::join(OUTPUT_FOLDER, service_name).map_err(|source| Error::PathError { source })?;
196+
let output_folder = &io::join(OUTPUT_FOLDER, service_name)?;
214197

215-
let src_folder = path::join(output_folder, "src").map_err(|source| Error::PathError { source })?;
198+
let src_folder = io::join(output_folder, "src")?;
216199
if src_folder.exists() {
217-
fs::remove_dir_all(&src_folder).map_err(|source| Error::IoError { source })?;
200+
fs::remove_dir_all(&src_folder)?;
218201
}
219202

220203
let mut tags = Vec::new();
@@ -227,7 +210,7 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
227210
let mut box_properties = HashSet::new();
228211
for (file_path, schema_name, property_name) in BOX_PROPERTIES {
229212
box_properties.insert(PropertyName {
230-
file_path: PathBuf::from(file_path),
213+
file_path: Utf8PathBuf::from(file_path),
231214
schema_name: schema_name.to_string(),
232215
property_name: property_name.to_string(),
233216
});
@@ -236,7 +219,7 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
236219
let mut invalid_types = HashSet::new();
237220
for (file_path, schema_name, property_name) in INVALID_TYPE_WORKAROUND {
238221
invalid_types.insert(PropertyName {
239-
file_path: PathBuf::from(file_path),
222+
file_path: Utf8PathBuf::from(file_path),
240223
schema_name: schema_name.to_string(),
241224
property_name: property_name.to_string(),
242225
});
@@ -250,12 +233,12 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
250233
}
251234
println!(" {}", tag_name);
252235
let mod_name = tag.rust_mod_name();
253-
let mod_output_folder = path::join(&src_folder, &mod_name).map_err(|source| Error::PathError { source })?;
236+
let mod_output_folder = io::join(&src_folder, &mod_name)?;
254237
tags.push(tag);
255238
let input_files: Result<Vec<_>> = tag
256239
.input_files()
257240
.iter()
258-
.map(|input_file| path::join(spec.readme(), input_file).map_err(|source| Error::PathError { source }))
241+
.map(|input_file| io::join(spec.readme(), input_file).map_err(Error::from))
259242
.collect();
260243
let input_files = input_files?;
261244
autorust_codegen::run(Config {
@@ -271,19 +254,14 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
271254
if tags.is_empty() {
272255
return Ok(());
273256
}
274-
cargo_toml::create(
257+
cargo_toml::create(crate_name, &tags, config.tag(), &io::join(output_folder, "Cargo.toml")?)?;
258+
lib_rs::create(&tags, &io::join(src_folder, "lib.rs")?, false)?;
259+
260+
let readme = ReadmeMd {
275261
crate_name,
276-
&tags,
277-
config.tag(),
278-
&path::join(output_folder, "Cargo.toml").map_err(|source| Error::PathError { source })?,
279-
)
280-
.map_err(|source| Error::CargoTomlError { source })?;
281-
lib_rs::create(
282-
&tags,
283-
&path::join(src_folder, "lib.rs").map_err(|source| Error::PathError { source })?,
284-
false,
285-
)
286-
.map_err(|source| Error::LibRsError { source })?;
262+
readme_url: readme_md::url(spec.readme().as_str()),
263+
};
264+
readme.create(&io::join(output_folder, "README.md")?)?;
287265

288266
Ok(())
289267
}

services/autorust/codegen/examples/mgmt_tags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// prints all the mgmt (control plane, resource-manager) tags
33

44
use autorust_codegen::get_mgmt_readmes;
5-
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
5+
use autorust_codegen::Result;
66

77
fn main() -> Result<()> {
88
let mut tag_count = 0;
@@ -11,7 +11,7 @@ fn main() -> Result<()> {
1111
for tag in spec.config()?.tags() {
1212
println!(" {}", &tag.name());
1313
for input_file in &tag.input_files() {
14-
println!(" {}", input_file.display());
14+
println!(" {}", input_file);
1515
}
1616
tag_count += 1;
1717
}

services/autorust/codegen/examples/multiple_versions.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
// in general, we want to avoid this
44
// https://github.com/Azure/azure-sdk-for-rust/issues/563
55

6-
use autorust_codegen::{get_mgmt_readmes, get_svc_readmes, path, Spec, SpecReadme};
6+
use autorust_codegen::{get_mgmt_readmes, get_svc_readmes, io, Result, Spec, SpecReadme};
77
use std::collections::BTreeSet;
88

9-
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
10-
119
fn main() -> Result<()> {
1210
println!("CONTROL PLANE");
1311
check(&get_mgmt_readmes()?)?;
@@ -23,7 +21,7 @@ fn check(readmes: &[SpecReadme]) -> Result<()> {
2321
for readme in readmes {
2422
let readme_path = readme.readme();
2523
for tag in readme.config()?.tags() {
26-
let input_files = path::join_several(readme_path, &tag.input_files())?;
24+
let input_files = io::join_several(readme_path, &tag.input_files())?;
2725
match Spec::read_files(&input_files) {
2826
Ok(spec) => {
2927
let versions = spec.api_versions();

services/autorust/codegen/examples/svc_tags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// cargo run --example svc_tags
22
// prints all the svc (data plane) tags
33

4+
use autorust_codegen::Result;
45
use autorust_codegen::{self, get_svc_readmes};
5-
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
66

77
fn main() -> Result<()> {
88
let mut tag_count = 0;
@@ -11,7 +11,7 @@ fn main() -> Result<()> {
1111
for tag in spec.config()?.tags() {
1212
println!(" {}", &tag.name());
1313
for input_file in &tag.input_files() {
14-
println!(" {}", input_file.display());
14+
println!(" {}", input_file);
1515
}
1616
tag_count += 1;
1717
}

services/autorust/codegen/src/cargo_toml.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
use crate::config_parser::Tag;
2+
use camino::Utf8Path;
23
use std::{
34
fs::File,
45
io::{prelude::*, LineWriter},
5-
path::Path,
66
};
77

88
pub type Result<T, E = Error> = std::result::Result<T, E>;
99
#[derive(Debug, thiserror::Error)]
1010
pub enum Error {
11-
#[error("IoError")]
12-
IoError { source: std::io::Error },
11+
#[error(transparent)]
12+
Io(crate::io::Error),
13+
}
14+
impl<T: Into<crate::io::Error>> From<T> for Error {
15+
fn from(error: T) -> Self {
16+
Self::Io(error.into())
17+
}
1318
}
1419

15-
pub fn create(crate_name: &str, tags: &[&Tag], default_tag: Option<&str>, path: &Path) -> Result<()> {
16-
let file = File::create(path).map_err(|source| Error::IoError { source })?;
20+
pub fn create(crate_name: &str, tags: &[&Tag], default_tag: Option<&str>, path: &Utf8Path) -> Result<()> {
21+
let file = File::create(path)?;
1722
let mut file = LineWriter::new(file);
1823
let default_feature = get_default_feature(tags, default_tag);
1924

@@ -28,9 +33,12 @@ pub fn create(crate_name: &str, tags: &[&Tag], default_tag: Option<&str>, path:
2833
[package]
2934
name = "{}"
3035
version = "0.2.0"
31-
edition = "2018"
36+
edition = "2021"
3237
license = "MIT"
3338
description = "generated REST API bindings"
39+
repository = "https://github.com/azure/azure-sdk-for-rust"
40+
homepage = "https://github.com/azure/azure-sdk-for-rust"
41+
documentation = "https://docs.rs/{}"
3442
3543
[dependencies]
3644
azure_core = {{ path = "../../../sdk/core", version = "0.1", default-features = false }}
@@ -55,15 +63,13 @@ enable_reqwest = ["azure_core/enable_reqwest"]
5563
enable_reqwest_rustls = ["azure_core/enable_reqwest_rustls"]
5664
no-default-version = []
5765
"#,
58-
crate_name, docs_rs_features, default_feature
66+
crate_name, crate_name, docs_rs_features, default_feature
5967
)
6068
.as_bytes(),
61-
)
62-
.map_err(|source| Error::IoError { source })?;
69+
)?;
6370

6471
for tag in tags {
65-
file.write_all(format!("\"{}\" = []\n", tag.rust_feature_name()).as_bytes())
66-
.map_err(|source| Error::IoError { source })?;
72+
file.write_all(format!("\"{}\" = []\n", tag.rust_feature_name()).as_bytes())?;
6773
}
6874
Ok(())
6975
}

0 commit comments

Comments
 (0)