Skip to content

web search done right

preliminary api docs

Mikkel Denker22a8e7d4df8e
diff --git a/Cargo.lock b/Cargo.lock
index c1473f4f..43ee9903 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2973,6 +2973,7 @@ dependencies = [
"once_cell",
"serde",
"thiserror",
+ "utoipa",
]
[[package]]
@@ -5254,6 +5255,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2 1.0.56",
"quote 1.0.26",
+ "regex",
"syn 2.0.15",
]
diff --git a/Cargo.toml b/Cargo.toml
index 559e419f..9bf3b0a3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -94,7 +94,7 @@ anyhow = { version = "1.0.72", features = ["backtrace"] }
bytemuck = { version = "1.13.1", features = ["derive"] }
proptest = "1.2.0"
proptest-derive = "0.3.0"
-utoipa = "3.4.4"
+utoipa = { version = "3.4.4", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "3.1.4", features = ["axum"] }
tikv-jemallocator = "0.5"
publicsuffix = "2.2.3"
diff --git a/configs/crawler/crawler.toml b/configs/crawler/crawler.toml
index d1141329..c9874527 100644
--- a/configs/crawler/crawler.toml
+++ b/configs/crawler/crawler.toml
@@ -5,7 +5,7 @@ coordinator_host = "0.0.0.0:8080"
[user_agent]
token = "StractBot"
-full = "Mozilla/5.0 (compatible; StractBot/0.1; +https://trystract.com/webmasters)"
+full = "Mozilla/5.0 (compatible; StractBot/0.1; open source search engine; +https://trystract.com/webmasters)"
[s3]
bucket = "crawl"
diff --git a/core/src/alice/mod.rs b/core/src/alice/mod.rs
index 4299ac24..02c3d32b 100644
--- a/core/src/alice/mod.rs
+++ b/core/src/alice/mod.rs
@@ -169,8 +169,8 @@ impl Searcher {
page: None,
selected_region: None,
site_rankings: None,
- return_ranking_signals: None,
- flatten_response: Some(false),
+ return_ranking_signals: false,
+ flatten_response: false,
};
tracing::debug!("searching at {:?}: {:#?}", self.url, query);
diff --git a/core/src/api/docs.rs b/core/src/api/docs.rs
index 1b1922d3..0c2d73fa 100644
--- a/core/src/api/docs.rs
+++ b/core/src/api/docs.rs
@@ -14,13 +14,43 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+use super::search;
use axum::Router;
use utoipa::{Modify, OpenApi};
use utoipa_swagger_ui::SwaggerUi;
#[derive(OpenApi)]
#[openapi(
- paths(),
+ paths(
+ search::api,
+ ),
+ components(
+ schemas(
+ crate::webpage::region::Region,
+ optics::SiteRankings,
+ search::ApiSearchQuery,
+ search::ApiSearchResult,
+ crate::searcher::WebsitesResult,
+ crate::search_prettifier::HighlightedSpellCorrection,
+ crate::search_prettifier::DisplayedWebpage,
+ crate::search_prettifier::DisplayedEntity,
+ crate::search_prettifier::DisplayedAnswer,
+ crate::search_prettifier::Sidebar,
+ crate::search_prettifier::Snippet,
+ crate::search_prettifier::StackOverflowAnswer,
+ crate::search_prettifier::StackOverflowQuestion,
+ crate::search_prettifier::CodeOrText,
+
+ crate::bangs::UrlWrapper,
+
+ crate::widgets::Widget,
+ crate::widgets::calculator::Calculation,
+ crate::widgets::calculator::Expr,
+ crate::ranking::signal::SignalScore,
+ crate::bangs::BangHit,
+ crate::bangs::Bang,
+ ),
+ ),
modifiers(&ApiModifier),
tags(
(name = "stract"),
@@ -43,5 +73,9 @@ pub fn router<S: Clone + Send + Sync + 'static, B: axum::body::HttpBody + Send +
) -> impl Into<Router<S, B>> {
SwaggerUi::new("/beta/api/docs")
.url("/beta/api/docs/openapi.json", ApiDoc::openapi())
- .config(utoipa_swagger_ui::Config::default().use_base_layout())
+ .config(
+ utoipa_swagger_ui::Config::default()
+ .use_base_layout()
+ .default_models_expand_depth(0),
+ )
}
diff --git a/core/src/api/search.rs b/core/src/api/search.rs
index 24085ff7..020ec93f 100644
--- a/core/src/api/search.rs
+++ b/core/src/api/search.rs
@@ -14,9 +14,11 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+use crate::config::defaults;
use http::{StatusCode, Uri};
use optics::{Optic, SiteRankings};
use std::sync::Arc;
+use utoipa::ToSchema;
use axum::Json;
use axum_macros::debug_handler;
@@ -267,7 +269,9 @@ fn next_page_url(uri: &Uri, params: SearchParams, skip_pages: usize) -> String {
next_page_url
}
-#[derive(Debug, serde::Serialize, serde::Deserialize)]
+#[derive(Debug, serde::Serialize, serde::Deserialize, ToSchema)]
+#[serde(rename_all = "camelCase")]
+#[schema(title = "SearchQuery", example = json!({"query": "hello world"}))]
pub struct ApiSearchQuery {
pub query: String,
pub page: Option<usize>,
@@ -275,8 +279,12 @@ pub struct ApiSearchQuery {
pub selected_region: Option<Region>,
pub optic: Option<String>,
pub site_rankings: Option<SiteRankings>,
- pub return_ranking_signals: Option<bool>,
- pub flatten_response: Option<bool>,
+
+ #[serde(default = "defaults::SearchQuery::return_ranking_signals")]
+ pub return_ranking_signals: bool,
+
+ #[serde(default = "defaults::SearchQuery::flatten_response")]
+ pub flatten_response: bool,
}
impl TryFrom<ApiSearchQuery> for SearchQuery {
@@ -298,14 +306,12 @@ impl TryFrom<ApiSearchQuery> for SearchQuery {
selected_region: api.selected_region,
optic,
site_rankings: api.site_rankings,
- return_ranking_signals: api
- .return_ranking_signals
- .unwrap_or(default.return_ranking_signals),
+ return_ranking_signals: api.return_ranking_signals,
})
}
}
-#[derive(Debug, serde::Serialize, serde::Deserialize)]
+#[derive(Debug, serde::Serialize, serde::Deserialize, ToSchema)]
#[serde(tag = "@type", rename_all = "camelCase")]
pub enum ApiSearchResult {
Websites(WebsitesResult),
@@ -324,11 +330,19 @@ impl From<SearchResult> for ApiSearchResult {
#[allow(clippy::unused_async)]
#[allow(clippy::match_wild_err_arm)]
#[debug_handler]
+#[utoipa::path(
+ post,
+ path = "/beta/api/search",
+ request_body(content = ApiSearchQuery),
+ responses(
+ (status = 200, description = "Search results", body = ApiSearchResult),
+ )
+)]
pub async fn api(
extract::State(state): extract::State<Arc<State>>,
extract::Json(query): extract::Json<ApiSearchQuery>,
) -> Result<impl IntoResponse, StatusCode> {
- let flatten_result = query.flatten_response.unwrap_or(true);
+ let flatten_result = query.flatten_response;
let query = SearchQuery::try_from(query);
if let Err(err) = query {
diff --git a/core/src/bangs.rs b/core/src/bangs.rs
index 3844c500..53afb33a 100644
--- a/core/src/bangs.rs
+++ b/core/src/bangs.rs
@@ -14,17 +14,23 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
-use std::{collections::HashMap, fs, path::Path};
+use std::{
+ collections::HashMap,
+ fs,
+ ops::{Deref, DerefMut},
+ path::Path,
+};
use itertools::intersperse;
use serde::{Deserialize, Serialize};
use url::Url;
+use utoipa::ToSchema;
use crate::query::parser::Term;
pub const BANG_PREFIX: char = '!';
-#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
+#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
pub struct Bang {
#[serde(rename = "c")]
pub(crate) category: Option<String>,
@@ -48,10 +54,35 @@ pub struct Bang {
pub(crate) url: String,
}
-#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
+/// Wrapper around `Url` that implements `ToSchema` for `Url`.
+#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, ToSchema)]
+#[schema(value_type = String, title = "Url")]
+pub struct UrlWrapper(Url);
+
+impl DerefMut for UrlWrapper {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.0
+ }
+}
+
+impl Deref for UrlWrapper {
+ type Target = Url;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+impl From<Url> for UrlWrapper {
+ fn from(url: Url) -> Self {
+ Self(url)
+ }
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, ToSchema)]
pub struct BangHit {
pub bang: Bang,
- pub redirect_to: Url,
+ pub redirect_to: UrlWrapper,
}
pub struct Bangs {
@@ -110,7 +141,7 @@ impl Bangs {
return Some(BangHit {
bang: bang.clone(),
- redirect_to: Url::parse(url.as_str()).unwrap(),
+ redirect_to: Url::parse(url.as_str()).unwrap().into(),
});
}
}
@@ -157,6 +188,7 @@ mod tests {
},
redirect_to: Url::parse("https://www.youtube.com/results?search_query=bangs")
.unwrap()
+ .into()
})
);
}
diff --git a/core/src/config/defaults.rs b/core/src/config/defaults.rs
index 8ec85ca0..7df47c1f 100644
--- a/core/src/config/defaults.rs
+++ b/core/src/config/defaults.rs
@@ -113,3 +113,15 @@ impl SearchServer {
true
}
}
+
+pub struct SearchQuery;
+
+impl SearchQuery {
+ pub fn flatten_response() -> bool {
+ true
+ }
+
+ pub fn return_ranking_signals() -> bool {
+ false
+ }
+}
diff --git a/core/src/ranking/signal.rs b/core/src/ranking/signal.rs
index ab2a76de..fb1f034f 100644
--- a/core/src/ranking/signal.rs
+++ b/core/src/ranking/signal.rs
@@ -35,6 +35,7 @@ use tantivy::postings::SegmentPostings;
use tantivy::query::{PhraseQuery, Query as _, Scorer};
use tantivy::tokenizer::Tokenizer;
use thiserror::Error;
+use utoipa::ToSchema;
use tantivy::DocSet;
use tantivy::{DocId, Postings};
@@ -1106,7 +1107,7 @@ pub struct ComputedSignal {
pub score: SignalScore,
}
-#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
pub struct SignalScore {
pub coefficient: f64,
pub value: f64,
diff --git a/core/src/search_prettifier/entity.rs b/core/src/search_prettifier/entity.rs
index 14424341..9f426d4d 100644
--- a/core/src/search_prettifier/entity.rs
+++ b/core/src/search_prettifier/entity.rs
@@ -18,13 +18,14 @@ use std::collections::BTreeMap;
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
+use utoipa::ToSchema;
use crate::{
entity_index::{entity::Span, EntityMatch},
searcher::LocalSearcher,
};
-#[derive(Debug, Serialize, Deserialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
pub struct DisplayedEntity {
pub title: String,
pub small_abstract: String,
diff --git a/core/src/search_prettifier/mod.rs b/core/src/search_prettifier/mod.rs
index 8e26d3b4..026630d9 100644
--- a/core/src/search_prettifier/mod.rs
+++ b/core/src/search_prettifier/mod.rs
@@ -23,6 +23,7 @@ use chrono::{NaiveDateTime, Utc};
use itertools::{intersperse, Itertools};
use serde::{Deserialize, Serialize};
use url::Url;
+use utoipa::ToSchema;
use crate::{
inverted_index::RetrievedWebpage,
@@ -34,9 +35,9 @@ use crate::{
pub use self::stack_overflow::{create_stackoverflow_sidebar, CodeOrText};
pub use entity::DisplayedEntity;
-use self::stack_overflow::{stackoverflow_snippet, StackOverflowAnswer, StackOverflowQuestion};
+pub use self::stack_overflow::{stackoverflow_snippet, StackOverflowAnswer, StackOverflowQuestion};
-#[derive(Debug, Serialize, Deserialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
pub enum Snippet {
Normal {
date: Option<String>,
@@ -48,7 +49,7 @@ pub enum Snippet {
},
}
-#[derive(Debug, Serialize, Deserialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
pub struct HighlightedSpellCorrection {
pub raw: String,
pub highlighted: String,
@@ -159,7 +160,7 @@ fn generate_snippet(webpage: &RetrievedWebpage) -> Snippet {
}
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct DisplayedWebpage {
pub title: String,
pub url: String,
@@ -171,7 +172,7 @@ pub struct DisplayedWebpage {
pub ranking_signals: Option<HashMap<Signal, SignalScore>>,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct DisplayedAnswer {
pub title: String,
pub url: String,
@@ -204,7 +205,7 @@ impl From<RetrievedWebpage> for DisplayedWebpage {
}
}
-#[derive(Debug, Serialize, Deserialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
pub enum Sidebar {
Entity(DisplayedEntity),
StackOverflow {
diff --git a/core/src/search_prettifier/stack_overflow.rs b/core/src/search_prettifier/stack_overflow.rs
index deb0dc90..629bb483 100644
--- a/core/src/search_prettifier/stack_overflow.rs
+++ b/core/src/search_prettifier/stack_overflow.rs
@@ -16,6 +16,7 @@
use serde::{Deserialize, Serialize};
use url::Url;
+use utoipa::ToSchema;
use crate::{
inverted_index::RetrievedWebpage,
@@ -26,7 +27,7 @@ use crate::{
use super::{Sidebar, Snippet};
use crate::Result;
-#[derive(Debug, Serialize, Deserialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
pub struct StackOverflowAnswer {
pub body: Vec<CodeOrText>,
pub date: String,
@@ -35,12 +36,12 @@ pub struct StackOverflowAnswer {
pub accepted: bool,
}
-#[derive(Debug, Serialize, Deserialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
pub struct StackOverflowQuestion {
pub body: Vec<CodeOrText>,
}
-#[derive(Debug, Serialize, Deserialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
pub enum CodeOrText {
Code(String),
Text(String),
diff --git a/core/src/searcher/frontend.rs b/core/src/searcher/frontend.rs
index 43f49995..f6988f47 100644
--- a/core/src/searcher/frontend.rs
+++ b/core/src/searcher/frontend.rs
@@ -213,7 +213,7 @@ impl FrontendSearcher {
tag: String::new(),
url: webpage.url.clone(),
},
- redirect_to: Url::parse(&webpage.url).unwrap(),
+ redirect_to: Url::parse(&webpage.url).unwrap().into(),
}));
}
diff --git a/core/src/searcher/mod.rs b/core/src/searcher/mod.rs
index 81ab2500..9a99f296 100644
--- a/core/src/searcher/mod.rs
+++ b/core/src/searcher/mod.rs
@@ -22,9 +22,11 @@ pub use distributed::*;
pub use local::*;
use optics::{Optic, SiteRankings};
use serde::{Deserialize, Serialize};
+use utoipa::ToSchema;
use crate::{
bangs::BangHit,
+ config::defaults,
ranking::pipeline::RankingWebsite,
search_prettifier::{
DisplayedAnswer, DisplayedEntity, DisplayedWebpage, HighlightedSpellCorrection, Sidebar,
@@ -42,7 +44,7 @@ pub enum SearchResult {
Bang(Box<BangHit>),
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct WebsitesResult {
pub spell_corrected_query: Option<HighlightedSpellCorrection>,
pub webpages: Vec<DisplayedWebpage>,
@@ -87,7 +89,7 @@ impl Default for SearchQuery {
selected_region: Default::default(),
optic: Default::default(),
site_rankings: Default::default(),
- return_ranking_signals: false,
+ return_ranking_signals: defaults::SearchQuery::return_ranking_signals(),
}
}
}
diff --git a/core/src/webpage/region.rs b/core/src/webpage/region.rs
index ecfbf648..ef4c10fa 100644
--- a/core/src/webpage/region.rs
+++ b/core/src/webpage/region.rs
@@ -17,12 +17,13 @@
use std::{collections::HashMap, fs::File, io::Write, path::Path};
use serde::{Deserialize, Serialize};
+use utoipa::ToSchema;
use crate::{Error, Result};
use super::Webpage;
-#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Serialize, Deserialize, Default)]
+#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Serialize, Deserialize, Default, ToSchema)]
pub enum Region {
#[default]
All,
diff --git a/core/src/widgets/calculator.rs b/core/src/widgets/calculator.rs
index 522b576d..dfcfa4c0 100644
--- a/core/src/widgets/calculator.rs
+++ b/core/src/widgets/calculator.rs
@@ -18,12 +18,13 @@ use crate::widgets::{Error, Result};
use lalrpop_util::lalrpop_mod;
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Display, Formatter};
+use utoipa::ToSchema;
lalrpop_mod!(pub parser, "/widgets/calculator.rs");
pub static PARSER: once_cell::sync::Lazy<parser::ExprParser> =
once_cell::sync::Lazy::new(parser::ExprParser::new);
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, ToSchema)]
pub enum Expr {
Number(f64),
Op(Box<Expr>, Opcode, Box<Expr>),
@@ -106,7 +107,7 @@ fn parse(expr: &str) -> Result<Box<Expr>> {
}
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct Calculation {
pub input: String,
pub expr: Box<Expr>,
diff --git a/core/src/widgets/mod.rs b/core/src/widgets/mod.rs
index fb1becf0..b89eb8aa 100644
--- a/core/src/widgets/mod.rs
+++ b/core/src/widgets/mod.rs
@@ -16,10 +16,11 @@
use serde::{Deserialize, Serialize};
use thiserror::Error;
+use utoipa::ToSchema;
use self::calculator::{try_calculate, Calculation};
-mod calculator;
+pub mod calculator;
pub type Result<T> = std::result::Result<T, Error>;
@@ -29,7 +30,7 @@ pub enum Error {
CalculatorParse,
}
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub enum Widget {
Calculator(Calculation),
}
diff --git a/docs/src/webgraph.md b/docs/src/webgraph.md
index 5cc12a6c..44218dc0 100644
--- a/docs/src/webgraph.md
+++ b/docs/src/webgraph.md
@@ -32,3 +32,4 @@ Inbound similarity plays a crucial role in enhancing personalized search results
Let's denote the set of inbound links for site $u$ as $I_{u}$ and $v$ for $I_{v}$. The similarity between two sites is calculated as the cosine similarity between their inbound link vectors:
$$S(u, v) = \frac{I_{u} \cdot I_{v}}{\|\|I_{u}\|\|\|\|I_{v}\|\|}$$
+It's also this inbound similarity metric that is used to find similar sites in the *explore* feature.
\ No newline at end of file
diff --git a/frontend/src/components/Footer.astro b/frontend/src/components/Footer.astro
index e27a5ad4..b1e67485 100644
--- a/frontend/src/components/Footer.astro
+++ b/frontend/src/components/Footer.astro
@@ -1,3 +1,6 @@
<div class="flex w-full items-center justify-center pt-5 pb-10 text-sm">
- <a href="/privacy-and-happy-lawyers">Terms & Privacy</a>
+ <div class="flex space-x-10">
+ <a href="/privacy-and-happy-lawyers">Terms & Privacy</a>
+ <a href="/beta/api/docs">API</a>
+ </div>
</div>
diff --git a/frontend/src/pages/crawler.mdx b/frontend/src/pages/crawler.mdx
index 6746d3a3..93102b49 100644
--- a/frontend/src/pages/crawler.mdx
+++ b/frontend/src/pages/crawler.mdx
@@ -6,7 +6,7 @@ title: Stract Crawler
# Stract Crawler
Stract is an [open source](https://github.com/StractOrg/stract/) web search engine. StractBot is the name of our crawler that collects pages from the web in order to build the index.
It is written in Rust and the source code can be found [here](https://github.com/StractOrg/stract/tree/main/core/src/crawler).
-The crawler uses the user agent `Mozilla/5.0 (compatible; StractBot/0.1; +https://trystract.com/webmasters)`.
+The crawler uses the user agent `Mozilla/5.0 (compatible; StractBot/0.1; open source search engine; +https://trystract.com/webmasters)`.
## Politeness
StractBot is a polite crawler. It respects the [robots.txt](https://en.wikipedia.org/wiki/Robots.txt) file of the website it is crawling and tries to not overload the server.
diff --git a/frontend/src/pages/privacy-and-happy-lawyers.mdx b/frontend/src/pages/privacy-and-happy-lawyers.mdx
index 6842e342..7203fb62 100644
--- a/frontend/src/pages/privacy-and-happy-lawyers.mdx
+++ b/frontend/src/pages/privacy-and-happy-lawyers.mdx
@@ -29,9 +29,6 @@ This data is solely used to train our ranking models which improves the search r
that can tie your searches back to you or even figure out which searches were performed by the same individual.
We hope you trust us with this limited data as it helps us improve our services tremendously. You can opt-out of this at any time from the [settings page](/settings/privacy) and we won't store anything at all.
-If you use Alice, by default we store your conversations and use them to train the model. We don't store anything that can tie the conversations back to you.
-Again, you can completely opt-out of this at any time from the [settings page](/settings/privacy) in which case we won't store anything at all.
-
You don't have to take our word for these claims as our [source code is available to everyone.](https://github.com/StractOrg/stract)
## Terms of Service
@@ -68,6 +65,10 @@ These Terms constitute the entire agreement between you and Stract concerning th
## Changelog
+#### 16-08-2023:
+
+No data is stored anymore when using Alice, so removed the section.
+
#### 25-06-2023:
Specified what data might be stored when using Alice.
diff --git a/optics-lsp/Cargo.lock b/optics-lsp/Cargo.lock
index 377d6e15..a83f3ee1 100644
--- a/optics-lsp/Cargo.lock
+++ b/optics-lsp/Cargo.lock
@@ -134,6 +134,12 @@ dependencies = [
"log",
]
+[[package]]
+name = "equivalent"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
+
[[package]]
name = "fixedbitset"
version = "0.4.2"
@@ -172,6 +178,12 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
+[[package]]
+name = "hashbrown"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
+
[[package]]
name = "hermit-abi"
version = "0.1.19"
@@ -198,7 +210,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
dependencies = [
"autocfg",
- "hashbrown",
+ "hashbrown 0.12.3",
+]
+
+[[package]]
+name = "indexmap"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
+dependencies = [
+ "equivalent",
+ "hashbrown 0.14.0",
+ "serde",
]
[[package]]
@@ -302,7 +325,7 @@ dependencies = [
"proc-macro2",
"quote",
"regex-syntax",
- "syn",
+ "syn 1.0.109",
]
[[package]]
@@ -347,6 +370,7 @@ dependencies = [
"once_cell",
"serde",
"thiserror",
+ "utoipa",
]
[[package]]
@@ -399,7 +423,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4"
dependencies = [
"fixedbitset",
- "indexmap",
+ "indexmap 1.9.2",
]
[[package]]
@@ -423,20 +447,44 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
+[[package]]
+name = "proc-macro-error"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
+dependencies = [
+ "proc-macro-error-attr",
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro-error-attr"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "version_check",
+]
+
[[package]]
name = "proc-macro2"
-version = "1.0.51"
+version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
+checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
-version = "1.0.23"
+version = "1.0.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
+checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965"
dependencies = [
"proc-macro2",
]
@@ -524,7 +572,7 @@ checksum = "4fc80d722935453bcafdc2c9a73cd6fac4dc1938f0346035d84bf99fa9e33217"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.109",
]
[[package]]
@@ -546,7 +594,7 @@ checksum = "395627de918015623b32e7669714206363a7fc00382bf477e72c1f7533e8eafc"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.109",
]
[[package]]
@@ -585,6 +633,17 @@ dependencies = [
"unicode-ident",
]
+[[package]]
+name = "syn"
+version = "2.0.28"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
[[package]]
name = "term"
version = "0.7.0"
@@ -613,7 +672,7 @@ checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.109",
]
[[package]]
@@ -679,6 +738,37 @@ dependencies = [
"serde",
]
+[[package]]
+name = "utoipa"
+version = "3.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "de634b7f8178c9c246c88ea251f3a0215c9a4d80778db2d7bd4423a78b5170ec"
+dependencies = [
+ "indexmap 2.0.0",
+ "serde",
+ "serde_json",
+ "utoipa-gen",
+]
+
+[[package]]
+name = "utoipa-gen"
+version = "3.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fcba79cb3e5020d9bcc8313cd5aadaf51d6d54a6b3fd08c3d0360ae6b3c83d0"
+dependencies = [
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "regex",
+ "syn 2.0.28",
+]
+
+[[package]]
+name = "version_check"
+version = "0.9.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
+
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
@@ -706,7 +796,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.109",
"wasm-bindgen-shared",
]
@@ -728,7 +818,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 1.0.109",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
diff --git a/optics/Cargo.toml b/optics/Cargo.toml
index 8c5269ac..3ecf105a 100644
--- a/optics/Cargo.toml
+++ b/optics/Cargo.toml
@@ -10,6 +10,7 @@ once_cell = { workspace = true }
itertools = { workspace = true }
logos = { workspace = true }
serde = { workspace = true }
+utoipa = { workspace = true }
[build-dependencies]
lalrpop = { workspace = true }
\ No newline at end of file
diff --git a/optics/src/lib.rs b/optics/src/lib.rs
index 2bea67e4..b9853f34 100644
--- a/optics/src/lib.rs
+++ b/optics/src/lib.rs
@@ -22,6 +22,7 @@ use std::convert::TryFrom;
use ast::RankingCoeff;
use serde::{Deserialize, Serialize};
use thiserror::Error;
+use utoipa::ToSchema;
use self::ast::{RawAction, RawMatchPart, RawOptic, RawRule};
pub use lexer::lex;
@@ -370,7 +371,7 @@ impl ToString for Rule {
}
}
-#[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)]
+#[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone, ToSchema)]
pub struct SiteRankings {
pub liked: Vec<String>,
pub disliked: Vec<String>,