Skip to content

Commit abee6e5

Browse files
authored
into_future for services (#527)
1 parent bf17a76 commit abee6e5

File tree

1,761 files changed

+5839709
-4213054
lines changed

Some content is hidden

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

1,761 files changed

+5839709
-4213054
lines changed

.github/workflows/services-all-features.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55

66
env:
7-
RUSTFLAGS: --deny warnings --allow unused_attributes
7+
RUSTFLAGS: --deny warnings --allow unused_attributes --allow unreachable-code --allow unused-assignments
88
CARGO_INCREMENTAL: 0
99

1010
jobs:

services/autorust/codegen/src/cargo_toml.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ bytes = "1.0"
3232
thiserror = "1.0"
3333
http = "0.2"
3434
url = "2.2"
35+
futures = "0.3"
3536
3637
[dev-dependencies]
3738
azure_identity = {{ path = "../../../sdk/identity", version = "0.1.0" }}

services/autorust/codegen/src/codegen.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,6 @@ pub fn is_vec(ts: &TokenStream) -> bool {
123123
ts.to_string().starts_with("Vec <")
124124
}
125125

126-
pub fn is_array(schema: &SchemaCommon) -> bool {
127-
matches!(schema.type_, Some(DataType::Array))
128-
}
129-
130-
pub fn is_string(schema: &SchemaCommon) -> bool {
131-
matches!(schema.type_, Some(DataType::String))
132-
}
133-
134126
pub fn get_schema_array_items(schema: &SchemaCommon) -> Result<&ReferenceOr<Schema>, Error> {
135127
schema.items.as_ref().as_ref().ok_or(Error::ArrayExpectedToHaveItems)
136128
}
@@ -157,12 +149,12 @@ pub fn is_basic_type(property: &ResolvedSchema) -> bool {
157149
)
158150
}
159151

160-
/// Wraps a type in an Option if is not required.
161-
pub fn require(is_required: bool, tp: TokenStream) -> TokenStream {
162-
if is_required {
163-
tp
164-
} else {
152+
/// Wraps a type in an Option
153+
pub fn add_option(is_option: bool, tp: TokenStream) -> TokenStream {
154+
if is_option {
165155
quote! { Option<#tp> }
156+
} else {
157+
tp
166158
}
167159
}
168160

@@ -200,29 +192,32 @@ impl TypeName {
200192
idt
201193
};
202194
match as_ref {
203-
true => quote! { &#idt },
195+
true => quote! { impl Into<#idt> },
204196
false => idt,
205197
}
206198
}
207199
TypeName::Array(vec_items_typ) => {
208-
let vec_items_typ = vec_items_typ.to_token_stream(as_ref, qualify_models)?;
200+
let vec_items_typ = vec_items_typ.to_token_stream(false, qualify_models)?;
209201
match as_ref {
210-
true => quote! { &[#vec_items_typ] },
202+
true => quote! { impl Into<Vec<#vec_items_typ>> },
211203
false => quote! { Vec<#vec_items_typ> },
212204
}
213205
}
214206
TypeName::Value => match as_ref {
215-
true => quote! { &serde_json::Value },
207+
true => quote! { impl Into<serde_json::Value> },
216208
false => quote! { serde_json::Value },
217209
},
218-
TypeName::Bytes => quote! { bytes::Bytes },
210+
TypeName::Bytes => match as_ref {
211+
true => quote! { impl Into<bytes::Bytes> },
212+
false => quote! { bytes::Bytes },
213+
},
219214
TypeName::Int32 => quote! { i32 },
220215
TypeName::Int64 => quote! { i64 },
221216
TypeName::Float32 => quote! { f32 },
222217
TypeName::Float64 => quote! { f64 },
223218
TypeName::Boolean => quote! { bool },
224219
TypeName::String => match as_ref {
225-
true => quote! { &str },
220+
true => quote! { impl Into<String> },
226221
false => quote! { String },
227222
},
228223
})

services/autorust/codegen/src/codegen_models.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::{
22
codegen::{
3-
create_generated_by_header, enum_values_as_strings, get_schema_array_items, get_type_name_for_schema, get_type_name_for_schema_ref,
4-
is_array, is_basic_type, is_local_enum, is_local_struct, is_vec, require, Error,
3+
add_option, create_generated_by_header, enum_values_as_strings, get_schema_array_items, get_type_name_for_schema,
4+
get_type_name_for_schema_ref, is_basic_type, is_local_enum, is_local_struct, is_vec, Error,
55
},
66
identifier::{CamelCaseIdent, SnakeCaseIdent},
77
spec, CodeGen, PropertyName, ResolvedSchema,
88
};
9-
use autorust_openapi::Reference;
9+
use autorust_openapi::{DataType, Reference, SchemaCommon};
1010
use indexmap::IndexMap;
1111
use proc_macro2::TokenStream;
1212
use quote::quote;
@@ -16,6 +16,10 @@ use std::{
1616
path::{Path, PathBuf},
1717
};
1818

19+
fn is_array(schema: &SchemaCommon) -> bool {
20+
matches!(schema.type_, Some(DataType::Array))
21+
}
22+
1923
pub fn create_models(cg: &CodeGen) -> Result<TokenStream, Error> {
2024
let mut file = TokenStream::new();
2125
file.extend(create_generated_by_header());
@@ -203,7 +207,7 @@ fn create_struct(cg: &CodeGen, doc_file: &Path, struct_name: &str, schema: &Reso
203207

204208
let is_vec = is_vec(&field_tp_name);
205209
if !is_vec {
206-
field_tp_name = require(is_required, field_tp_name);
210+
field_tp_name = add_option(!is_required, field_tp_name);
207211
}
208212
local_types.extend(field_tp);
209213
let mut serde_attrs: Vec<TokenStream> = Vec::new();

0 commit comments

Comments
 (0)