-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
112 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "okapi-operation-macro" | ||
description = "Macro implementation for okapi-operation" | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
authors = ["Andrey Kononov [email protected]"] | ||
edition = "2021" | ||
license = "MIT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use darling::FromMeta; | ||
use proc_macro2::TokenStream; | ||
use quote::{quote, ToTokens}; | ||
use syn::Path; | ||
|
||
use crate::{operation::parameters::ParameterStyle, utils::quote_option}; | ||
|
||
pub(super) static COOKIE_ATTRIBUTE_NAME: &str = "cookie"; | ||
|
||
/// Cookie parameter. | ||
#[derive(Debug, FromMeta)] | ||
pub(super) struct Cookie { | ||
name: String, | ||
#[darling(default)] | ||
description: Option<String>, | ||
#[darling(default)] | ||
required: bool, | ||
#[darling(default)] | ||
deprecated: bool, | ||
#[darling(default)] | ||
explode: Option<bool>, | ||
#[darling(default)] | ||
allow_empty_value: bool, | ||
schema: Path, | ||
// TODO: support content as well | ||
} | ||
|
||
impl ToTokens for Cookie { | ||
fn to_tokens(&self, tokens: &mut TokenStream) { | ||
let name = &self.name; | ||
let description = quote_option(&self.description); | ||
let required = &self.required; | ||
let deprecated = &self.deprecated; | ||
let style = ParameterStyle::Form; | ||
let explode = quote_option(&self.explode); | ||
let allow_empty_values = &self.allow_empty_value; | ||
let allow_reserved = false; | ||
let ty = &self.schema; | ||
tokens.extend(quote! { | ||
okapi::openapi3::Parameter { | ||
name: #name.into(), | ||
location: "Cookie".into(), | ||
description: #description, | ||
required: #required, | ||
deprecated: #deprecated, | ||
allow_empty_value: #allow_empty_values, | ||
value: { | ||
okapi::openapi3::ParameterValue::Schema { | ||
style: #style, | ||
explode: #explode, | ||
allow_reserved: #allow_reserved, | ||
schema: components.schema_for::<#ty>(), | ||
example: Default::default(), | ||
examples: Default::default(), | ||
} | ||
}, | ||
extensions: Default::default(), | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "okapi-operation" | ||
description = "Procedural macro for generating OpenAPI operation specification (using okapi)" | ||
version = "0.1.1" | ||
version = "0.1.2" | ||
authors = ["Andrey Kononov [email protected]"] | ||
edition = "2021" | ||
license = "MIT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters