Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ohkami/src/fang/builtin/basicauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const _: () = {
#[cfg(feature="openapi")]
fn openapi_map_operation(&self, operation: openapi::Operation) -> openapi::Operation {
use openapi::security::SecurityScheme;
operation.security(SecurityScheme::Basic("basicAuth"), &[])
operation.security(SecurityScheme::basic("basicAuth"), &[])
}
}

Expand All @@ -124,7 +124,7 @@ const _: () = {
#[cfg(feature="openapi")]
fn openapi_map_operation(&self, operation: openapi::Operation) -> openapi::Operation {
use openapi::security::SecurityScheme;
operation.security(SecurityScheme::Basic("basicAuth"), &[])
operation.security(SecurityScheme::basic("basicAuth"), &[])
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion ohkami/src/fang/builtin/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<Payload> Jwt<Payload> {
secret: secret.into(),

#[cfg(feature="openapi")]
openapi_security: crate::openapi::security::SecurityScheme::Bearer(
openapi_security: crate::openapi::security::SecurityScheme::bearer(
"jwtAuth",
Some("JWT")
)
Expand Down
2 changes: 1 addition & 1 deletion ohkami/src/fang/handler/into_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn with_default_operation_id<F>(op: openapi::Operation) -> openapi::Operation {
if type_ident == "{{closure}}" {
op
} else {
op.operationId(type_ident)
op.operation_id(type_ident)
}
}

Expand Down
2 changes: 1 addition & 1 deletion ohkami/src/router/final.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl Router {
for param_name in &openapi_path_param_names {
operation.assign_path_param_name(param_name.to_string());
}
for security_scheme in operation.iter_securitySchemes() {
for security_scheme in operation.iter_security_schemes() {
doc.register_securityScheme_component(security_scheme);
}
for schema_component in operation.refize_schemas() {
Expand Down
16 changes: 8 additions & 8 deletions ohkami_macros/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ pub(super) fn derive_schema(input: TokenStream) -> syn::Result<TokenStream> {
}

Ok(quote! {
::ohkami::openapi::array(::ohkami::openapi::oneOf(
::ohkami::openapi::array(::ohkami::openapi::one_of(
(#(#type_schemas,)*)
))
})
Expand Down Expand Up @@ -436,7 +436,7 @@ pub(super) fn derive_schema(input: TokenStream) -> syn::Result<TokenStream> {
}

Ok(quote! {
::ohkami::openapi::oneOf(
::ohkami::openapi::one_of(
( #(#variant_schemas,)* )
)
})
Expand All @@ -447,7 +447,7 @@ pub(super) fn derive_schema(input: TokenStream) -> syn::Result<TokenStream> {
pub(super) fn operation(meta: TokenStream, handler: TokenStream) -> syn::Result<TokenStream> {
#[allow(non_snake_case)]
struct OperationMeta {
operationId: Option<String>,
operation_id: Option<String>,
descriptions: Vec<DescriptionOverride>,
}

Expand Down Expand Up @@ -514,7 +514,7 @@ pub(super) fn operation(meta: TokenStream, handler: TokenStream) -> syn::Result<
impl syn::parse::Parse for OperationMeta {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
#[allow(non_snake_case)]
let operationId = input.peek(Ident)
let operation_id = input.peek(Ident)
.then(|| input.parse::<Ident>().map(|i| i.to_string()))
.transpose()?;

Expand All @@ -529,7 +529,7 @@ pub(super) fn operation(meta: TokenStream, handler: TokenStream) -> syn::Result<
.unwrap_or_default();


Ok(Self { operationId, descriptions })
Ok(Self { operation_id, descriptions })
}
}

Expand All @@ -554,12 +554,12 @@ pub(super) fn operation(meta: TokenStream, handler: TokenStream) -> syn::Result<
let modify_op = {
let mut modify_op = TokenStream::new();

let operation_id = match meta.operationId {
let operation_id = match meta.operation_id {
Some(operation_id) => LitStr::new(&operation_id, Span::call_site()),
None => LitStr::new(&handler.sig.ident.to_string(), handler.sig.ident.span())
};
modify_op.extend(quote! {
op = op.operationId(#operation_id);
op = op.operation_id(#operation_id);
});

if let Some(description) = extract_doc_comment(&handler.attrs) {
Expand All @@ -577,7 +577,7 @@ pub(super) fn operation(meta: TokenStream, handler: TokenStream) -> syn::Result<
},
DescriptionTarget::RequestBody => {
quote! {
op = op.requestBody_description(#value);
op = op.requestbody_description(#value);
}
},
DescriptionTarget::DefaultResponse => {
Expand Down
15 changes: 8 additions & 7 deletions ohkami_openapi/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ impl Server {
#[derive(Serialize, Clone)]
pub struct Components {
#[serde(skip_serializing_if = "Map::is_empty")]
schemas: Map<&'static str, RawSchema>,
schemas: Map<&'static str, RawSchema>,
#[serde(skip_serializing_if = "Map::is_empty")]
securitySchemes: Map<&'static str, SecurityScheme>,
#[serde(rename = "securitySchemes")]
security_schemes: Map<&'static str, SecurityScheme>,
}
impl Components {
fn is_empty(&self) -> bool {
self.schemas.is_empty() && self.securitySchemes.is_empty()
self.schemas.is_empty() && self.security_schemes.is_empty()
}
}

Expand All @@ -96,7 +97,7 @@ impl Document {
info: Info { title, version, description:None },
servers: servers.into(),
paths: Paths::new(),
components: Components { schemas:Map::new(), securitySchemes:Map::new() }
components: Components { schemas:Map::new(), security_schemes:Map::new() }
}
}

Expand All @@ -122,10 +123,10 @@ impl Document {
}
#[doc(hidden)]
pub fn register_securityScheme_component(&mut self, securityScheme: SecurityScheme) {
match self.components.securitySchemes.get(&securityScheme.__name__) {
match self.components.security_schemes.get(&securityScheme.__name__) {
Some(it) if *it == securityScheme => return,
Some(_) => panic!("[OpenAPI] `components.securitySchemes`: contradict registrations of multiple `{}`s", securityScheme.__name__),
None => self.components.securitySchemes.insert(securityScheme.__name__, securityScheme),
Some(_) => panic!("[OpenAPI] `components.security_schemes`: contradict registrations of multiple `{}`s", securityScheme.__name__),
None => self.components.security_schemes.insert(securityScheme.__name__, securityScheme),
}
}
}
12 changes: 6 additions & 6 deletions ohkami_openapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ pub fn array(items: impl Into<schema::SchemaRef>) -> schema::Schema<schema::Type
pub fn object() -> schema::Schema<schema::Type::object> {
schema::Schema::object()
}
pub fn anyOf(schemas: impl schema::SchemaList) -> schema::Schema<schema::Type::any> {
schema::Schema::anyOf(schemas)
pub fn any_of(schemas: impl schema::SchemaList) -> schema::Schema<schema::Type::any> {
schema::Schema::any_of(schemas)
}
pub fn allOf(schemas: impl schema::SchemaList) -> schema::Schema<schema::Type::any> {
schema::Schema::allOf(schemas)
pub fn all_of(schemas: impl schema::SchemaList) -> schema::Schema<schema::Type::any> {
schema::Schema::all_of(schemas)
}
pub fn oneOf(schemas: impl schema::SchemaList) -> schema::Schema<schema::Type::any> {
schema::Schema::oneOf(schemas)
pub fn one_of(schemas: impl schema::SchemaList) -> schema::Schema<schema::Type::any> {
schema::Schema::one_of(schemas)
}

pub trait Schema {
Expand Down
41 changes: 22 additions & 19 deletions ohkami_openapi/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ pub struct Operations(
#[derive(Serialize, Clone)]
pub struct Operation {
#[serde(skip_serializing_if = "Option::is_none")]
operationId: Option<&'static str>,
#[serde(rename = "operationId")]
operation_id: Option<&'static str>,
#[serde(skip_serializing_if = "Vec::is_empty")]
tags: Vec<&'static str>,

Expand All @@ -25,15 +26,17 @@ pub struct Operation {
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<&'static str>,
#[serde(skip_serializing_if = "Option::is_none")]
externalDocs: Option<ExternalDoc>,
#[serde(rename = "externalDocs")]
external_docs: Option<ExternalDoc>,
#[serde(skip_serializing_if = "is_false")]
deprecated: bool,

#[serde(skip_serializing_if = "Vec::is_empty")]
parameters: Vec<Parameter>,

#[serde(skip_serializing_if = "Option::is_none")]
requestBody: Option<RequestBody>,
#[serde(rename = "requestBody")]
requestbody: Option<RequestBody>,

#[serde(skip_serializing_if = "Vec::is_empty")]
security: Vec<Map<SecuritySchemeName, Vec<&'static str>>>,
Expand Down Expand Up @@ -119,14 +122,14 @@ impl Operation {
pub fn with(responses: Responses) -> Self {
Self {
responses,
operationId: None,
operation_id: None,
tags: Vec::new(),
summary: None,
description: None,
externalDocs: None,
external_docs: None,
deprecated: false,
parameters: Vec::new(),
requestBody: None,
requestbody: None,
security: Vec::new(),
}
}
Expand All @@ -136,8 +139,8 @@ impl Operation {
self
}

pub fn requestBody(mut self, requestBody: RequestBody) -> Self {
self.requestBody = Some(requestBody);
pub fn requestbody(mut self, requestbody: RequestBody) -> Self {
self.requestbody = Some(requestbody);
self
}

Expand All @@ -146,8 +149,8 @@ impl Operation {
self
}

pub fn operationId(mut self, operationId: &'static str) -> Self {
self.operationId = Some(operationId);
pub fn operation_id(mut self, operation_id: &'static str) -> Self {
self.operation_id = Some(operation_id);
self
}
pub fn with_tag(mut self, tag: &'static str) -> Self {
Expand All @@ -162,8 +165,8 @@ impl Operation {
self.description = Some(description);
self
}
pub fn externalDocs(mut self, externalDocs: ExternalDoc) -> Self {
self.externalDocs = Some(externalDocs);
pub fn external_docs(mut self, external_docs: ExternalDoc) -> Self {
self.external_docs = Some(external_docs);
self
}
pub fn deprecated(mut self) -> Self {
Expand All @@ -175,7 +178,7 @@ impl Operation {
match inbound {
crate::Inbound::None => self,
crate::Inbound::Security { scheme, scopes } => self.security(scheme, scopes),
crate::Inbound::Body(body) => self.requestBody(body),
crate::Inbound::Body(body) => self.requestbody(body),
crate::Inbound::Param(param) => self.param(param),
crate::Inbound::Params(params) => {
for param in params {self = self.param(param)}
Expand All @@ -194,12 +197,12 @@ impl Operation {
}
self
}
pub fn requestBody_description(
pub fn requestbody_description(
mut self,
new_description: &'static str
) -> Self {
if let Some(requestBody) = &mut self.requestBody {
requestBody.set_description(new_description);
if let Some(requestbody) = &mut self.requestbody {
requestbody.set_description(new_description);
}
self
}
Expand All @@ -223,7 +226,7 @@ impl Operation {
}

#[doc(hidden)]
pub fn iter_securitySchemes(&self) -> impl Iterator<Item = SecurityScheme> {
pub fn iter_security_schemes(&self) -> impl Iterator<Item = SecurityScheme> {
self.security.clone().into_iter()
.map(|map| {
let [SecuritySchemeName(ss)] = map.clone()
Expand All @@ -238,7 +241,7 @@ impl Operation {
pub fn refize_schemas(&mut self) -> impl Iterator<Item = RawSchema> + '_ {
[/* RawSchema */].into_iter()
.chain(self.parameters.iter_mut().map(|p| p.schema.refize()).flatten())
.chain(self.requestBody.as_mut().map(RequestBody::refize_schemas).into_iter().flatten())
.chain(self.requestbody.as_mut().map(RequestBody::refize_schemas).into_iter().flatten())
.chain(self.responses.refize_schemas())
}
}
Expand All @@ -248,7 +251,7 @@ impl Operation {
#[allow(unused)]
fn map_openapi_operation(op: Operation) -> Operation {
op
.operationId("list_users")
.operation_id("list_users")
.description("This doc comment is used for the\n`description` field of OpenAPI document")
.summary("...")
.response_description(200, "List of all users")
Expand Down
Loading