Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtimes/js: add tags to api description #1741

Merged
merged 2 commits into from
Jan 28, 2025
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
14 changes: 13 additions & 1 deletion runtimes/core/src/api/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::api::schema::encoding::{
};
use crate::api::schema::{JSONPayload, Method};
use crate::api::{jsonschema, schema, ErrCode, Error};
use crate::encore::parser::meta::v1 as meta;
use crate::encore::parser::meta::v1::rpc;
use crate::encore::parser::meta::v1::{self as meta, selector};
use crate::log::LogFromRust;
use crate::model::StreamDirection;
use crate::names::EndpointName;
Expand Down Expand Up @@ -175,6 +175,9 @@ pub struct Endpoint {
/// The static assets to serve from this endpoint.
/// Set only for static asset endpoints.
pub static_assets: Option<meta::rpc::StaticAssets>,

/// The tags for this endpoint.
pub tags: Vec<String>,
}

impl Endpoint {
Expand Down Expand Up @@ -333,6 +336,14 @@ pub fn endpoints_from_meta(
let raw =
rpc::Protocol::try_from(ep.ep.proto).is_ok_and(|proto| proto == rpc::Protocol::Raw);

let tags = ep
.ep
.tags
.iter()
.filter(|item| item.r#type() == selector::Type::Tag)
.map(|item| item.value.clone())
.collect();

let endpoint = Endpoint {
name: EndpointName::new(ep.svc.name.clone(), ep.ep.name.clone()),
path: ep.ep.path.clone().unwrap_or_else(|| meta::Path {
Expand All @@ -356,6 +367,7 @@ pub fn endpoints_from_meta(
requires_auth: !ep.ep.allow_unauthenticated,
body_limit: ep.ep.body_limit,
static_assets: ep.ep.static_assets.clone(),
tags,
};

endpoint_map.insert(
Expand Down
6 changes: 5 additions & 1 deletion runtimes/js/encore.dev/req_meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export interface APIDesc {

/** Whether the endpoint requires auth. */
auth: boolean;

/** Tags specified on the endpoint. */
tags: string[];
}

export type Method =
Expand Down Expand Up @@ -171,7 +174,8 @@ export function currentRequest(): RequestMeta | undefined {
service: meta.apiCall.api.service,
endpoint: meta.apiCall.api.endpoint,
raw: meta.apiCall.api.raw,
auth: meta.apiCall.api.requiresAuth
auth: meta.apiCall.api.requiresAuth,
tags: meta.apiCall.api.tags
},
method: meta.apiCall.method as Method,
path: meta.apiCall.path,
Expand Down
3 changes: 3 additions & 0 deletions runtimes/js/src/request_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn meta(req: &model::Request) -> Result<RequestMeta, serde_json::Error> {
endpoint: rpc.endpoint.name.endpoint().to_string(),
raw: rpc.endpoint.raw,
requires_auth: rpc.endpoint.requires_auth,
tags: rpc.endpoint.tags.clone(),
},
method: rpc.method.as_str().to_string(),
path: rpc.path.clone(),
Expand All @@ -43,6 +44,7 @@ pub fn meta(req: &model::Request) -> Result<RequestMeta, serde_json::Error> {
endpoint: data.endpoint.name.endpoint().to_string(),
raw: data.endpoint.raw,
requires_auth: data.endpoint.requires_auth,
tags: data.endpoint.tags.clone(),
},
method: Default::default(),
path: data.path.clone(),
Expand Down Expand Up @@ -117,6 +119,7 @@ pub struct APIDesc {
pub endpoint: String,
pub raw: bool,
pub requires_auth: bool,
pub tags: Vec<String>,
}

#[napi(object)]
Expand Down
Loading