diff --git a/compiler-rs/clients_schema_to_openapi/src/lib.rs b/compiler-rs/clients_schema_to_openapi/src/lib.rs index e82b4b30b8..2f6048147e 100644 --- a/compiler-rs/clients_schema_to_openapi/src/lib.rs +++ b/compiler-rs/clients_schema_to_openapi/src/lib.rs @@ -20,57 +20,45 @@ mod paths; mod schemas; mod utils; -use std::collections::HashSet; -use std::io::{BufWriter, Write}; -use std::path::Path; use indexmap::IndexMap; -use clients_schema::{Availabilities, Endpoint, IndexedModel, Stability}; +use clients_schema::{Availabilities, Flavor, IndexedModel, Stability, Visibility}; use openapiv3::{Components, OpenAPI}; -use tracing::warn; - +use clients_schema::transform::ExpandConfig; use crate::components::TypesAndComponents; -pub fn convert_schema_file( - path: impl AsRef, - filter: Option) -> bool>, - endpoint_filter: fn(e: &Endpoint) -> bool, - out: impl Write, -) -> anyhow::Result<()> { - // Parsing from a string is faster than using a buffered reader when there is a need for look-ahead - // See https://github.com/serde-rs/json/issues/160 - let json = &std::fs::read_to_string(path)?; - let json_deser = &mut serde_json::Deserializer::from_str(json); - - let mut unused = HashSet::new(); - let mut model: IndexedModel = serde_ignored::deserialize(json_deser, |path| { - if let serde_ignored::Path::Map { parent: _, key } = path { - unused.insert(key); - } - })?; - if !unused.is_empty() { - let msg = unused.into_iter().collect::>().join(", "); - warn!("Unknown fields found in schema.json: {}", msg); - } +/// Convert an API model into an OpenAPI v3 schema, optionally filtered for a given flavor +pub fn convert_schema(mut schema: IndexedModel, flavor: Option) -> anyhow::Result { + // Expand generics + schema = clients_schema::transform::expand_generics(schema, ExpandConfig::default())?; + + // Filter flavor + let filter: Option) -> bool> = match flavor { + None => None, + Some(Flavor::Stack) => Some(|a| { + // Generate only public items for Stack + Flavor::Stack.visibility(a) == Some(Visibility::Public) + }), + Some(Flavor::Serverless) => Some(|a| { + // Generate only public items for Serverless + Flavor::Serverless.visibility(a) == Some(Visibility::Public) + }), + }; if let Some(filter) = filter { - model = clients_schema::transform::filter_availability(model, filter)?; + schema = clients_schema::transform::filter_availability(schema, filter)?; } - model.endpoints.retain(endpoint_filter); - - let openapi = convert_schema(&model)?; - serde_json::to_writer_pretty(BufWriter::new(out), &openapi)?; - Ok(()) + convert_expanded_schema(&schema) } -/// Convert an API model into an OpenAPI v3 schema. The input model must have all generics expanded, converstion +/// Convert an API model into an OpenAPI v3 schema. The input model must have all generics expanded, conversion /// will fail otherwise. /// -/// Note: there are ways to represent [generics in JSON Schema], but its unlikely that tooling will understood it. +/// Note: there are ways to represent [generics in JSON Schema], but its unlikely that tooling will understand it. /// /// [generics in JSON Schema]: https://json-schema.org/blog/posts/dynamicref-and-generics -pub fn convert_schema(model: &IndexedModel) -> anyhow::Result { +pub fn convert_expanded_schema(model: &IndexedModel) -> anyhow::Result { let mut openapi = OpenAPI { openapi: "3.0.3".into(), info: info(model), diff --git a/compiler-rs/clients_schema_to_openapi/src/main.rs b/compiler-rs/clients_schema_to_openapi/src/main.rs index 4fe74a7589..7f255be80a 100644 --- a/compiler-rs/clients_schema_to_openapi/src/main.rs +++ b/compiler-rs/clients_schema_to_openapi/src/main.rs @@ -19,7 +19,7 @@ use std::path::{Path, PathBuf}; use anyhow::bail; use clap::{Parser, ValueEnum}; -use clients_schema::{Availabilities, Visibility}; +use clients_schema::Flavor; use tracing::Level; use tracing_subscriber::fmt::format::FmtSpan; use tracing_subscriber::FmtSubscriber; @@ -72,33 +72,18 @@ impl Cli { std::fs::read_to_string(self.schema)? }; - let mut model: clients_schema::IndexedModel = match serde_json::from_str(&json) { + let model: clients_schema::IndexedModel = match serde_json::from_str(&json) { Ok(indexed_model) => indexed_model, Err(e) => bail!("cannot parse schema json: {}", e) }; - if let Some(flavor) = self.flavor { - if flavor != SchemaFlavor::All { - let filter: fn(&Option) -> bool = match flavor { - SchemaFlavor::All => |_| true, - SchemaFlavor::Stack => |a| { - // Generate public and private items for Stack - clients_schema::Flavor::Stack.available(a) - }, - SchemaFlavor::Serverless => |a| { - // Generate only public items for Serverless - clients_schema::Flavor::Serverless.visibility(a) == Some(Visibility::Public) - }, - }; - - use clients_schema::transform::*; - - model = expand_generics(model, ExpandConfig::default())?; - model = filter_availability(model, filter)?; - } - } + let flavor = match self.flavor { + Some(SchemaFlavor::All) | None => None, + Some(SchemaFlavor::Stack) => Some(Flavor::Stack), + Some(SchemaFlavor::Serverless) => Some(Flavor::Serverless), + }; - let openapi = clients_schema_to_openapi::convert_schema(&model)?; + let openapi = clients_schema_to_openapi::convert_schema(model, flavor)?; let output: Box = { if let Some(output) = self.output { diff --git a/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm b/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm index 1a8bba3604..051e8ee86c 100644 Binary files a/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm and b/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm differ diff --git a/compiler-rs/compiler-wasm-lib/src/lib.rs b/compiler-rs/compiler-wasm-lib/src/lib.rs index c4bccbbe05..cf3e9f41c7 100644 --- a/compiler-rs/compiler-wasm-lib/src/lib.rs +++ b/compiler-rs/compiler-wasm-lib/src/lib.rs @@ -16,9 +16,8 @@ // under the License. use anyhow::bail; -use clients_schema::{Availabilities, Visibility}; +use clients_schema::{Flavor, IndexedModel}; use wasm_bindgen::prelude::*; -use clients_schema::transform::ExpandConfig; #[wasm_bindgen] pub fn convert_schema_to_openapi(json: &str, flavor: &str) -> Result { @@ -27,25 +26,15 @@ pub fn convert_schema_to_openapi(json: &str, flavor: &str) -> Result anyhow::Result { - let filter: Option) -> bool> = match flavor { + let flavor = match flavor { "all" => None, - "stack" => Some(|a| { - // Generate public and private items for Stack - clients_schema::Flavor::Stack.available(a) - }), - "serverless" => Some(|a| { - // Generate only public items for Serverless - clients_schema::Flavor::Serverless.visibility(a) == Some(Visibility::Public) - }), + "stack" => Some(Flavor::Stack), + "serverless" => Some(Flavor::Serverless), _ => bail!("Unknown flavor {}", flavor), }; - let mut schema = clients_schema::IndexedModel::from_reader(json.as_bytes())?; - schema = clients_schema::transform::expand_generics(schema, ExpandConfig::default())?; - if let Some(filter) = filter { - schema = clients_schema::transform::filter_availability(schema, filter)?; - } - let openapi = clients_schema_to_openapi::convert_schema(&schema)?; + let schema = IndexedModel::from_reader(json.as_bytes())?; + let openapi = clients_schema_to_openapi::convert_schema(schema, flavor)?; let result = serde_json::to_string_pretty(&openapi)?; Ok(result) } diff --git a/output/openapi/elasticsearch-openapi.json b/output/openapi/elasticsearch-openapi.json index 67c12225ee..6565ab014c 100644 --- a/output/openapi/elasticsearch-openapi.json +++ b/output/openapi/elasticsearch-openapi.json @@ -4419,98 +4419,6 @@ "x-beta": true } }, - "/_connector/{connector_id}/_last_sync": { - "put": { - "tags": [ - "connector" - ], - "summary": "Update the connector last sync stats", - "description": "Update the fields related to the last sync of a connector.\nThis action is used for analytics and monitoring.", - "operationId": "connector-last-sync", - "parameters": [ - { - "in": "path", - "name": "connector_id", - "description": "The unique identifier of the connector to be updated", - "required": true, - "deprecated": false, - "schema": { - "$ref": "#/components/schemas/_types:Id" - }, - "style": "simple" - } - ], - "requestBody": { - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "last_access_control_sync_error": { - "type": "string" - }, - "last_access_control_sync_scheduled_at": { - "$ref": "#/components/schemas/_types:DateTime" - }, - "last_access_control_sync_status": { - "$ref": "#/components/schemas/connector._types:SyncStatus" - }, - "last_deleted_document_count": { - "type": "number" - }, - "last_incremental_sync_scheduled_at": { - "$ref": "#/components/schemas/_types:DateTime" - }, - "last_indexed_document_count": { - "type": "number" - }, - "last_seen": { - "$ref": "#/components/schemas/_types:DateTime" - }, - "last_sync_error": { - "type": "string" - }, - "last_sync_scheduled_at": { - "$ref": "#/components/schemas/_types:DateTime" - }, - "last_sync_status": { - "$ref": "#/components/schemas/connector._types:SyncStatus" - }, - "last_synced": { - "$ref": "#/components/schemas/_types:DateTime" - }, - "sync_cursor": { - "type": "object" - } - } - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "result": { - "$ref": "#/components/schemas/_types:Result" - } - }, - "required": [ - "result" - ] - } - } - } - } - }, - "x-state": "Technical preview" - } - }, "/_connector": { "get": { "tags": [ @@ -6305,16 +6213,6 @@ }, "style": "simple" }, - { - "in": "query", - "name": "force_synthetic_source", - "description": "Should this request force synthetic _source?\nUse this to test if the mapping supports synthetic _source and to get a sense of the worst case performance.\nFetches with this enabled will be slower the enabling synthetic source natively in the index.", - "deprecated": false, - "schema": { - "type": "boolean" - }, - "style": "form" - }, { "in": "query", "name": "preference", @@ -16287,9 +16185,6 @@ "description": "Get multiple JSON documents by ID from one or more indices.\nIf you specify an index in the request URI, you only need to specify the document IDs in the request body.\nTo ensure fast responses, this multi get (mget) API responds with partial results if one or more shards fail.", "operationId": "mget", "parameters": [ - { - "$ref": "#/components/parameters/mget#force_synthetic_source" - }, { "$ref": "#/components/parameters/mget#preference" }, @@ -16333,9 +16228,6 @@ "description": "Get multiple JSON documents by ID from one or more indices.\nIf you specify an index in the request URI, you only need to specify the document IDs in the request body.\nTo ensure fast responses, this multi get (mget) API responds with partial results if one or more shards fail.", "operationId": "mget-1", "parameters": [ - { - "$ref": "#/components/parameters/mget#force_synthetic_source" - }, { "$ref": "#/components/parameters/mget#preference" }, @@ -16384,9 +16276,6 @@ { "$ref": "#/components/parameters/mget#index" }, - { - "$ref": "#/components/parameters/mget#force_synthetic_source" - }, { "$ref": "#/components/parameters/mget#preference" }, @@ -16433,9 +16322,6 @@ { "$ref": "#/components/parameters/mget#index" }, - { - "$ref": "#/components/parameters/mget#force_synthetic_source" - }, { "$ref": "#/components/parameters/mget#preference" }, @@ -22522,99 +22408,6 @@ "x-state": "Added in 5.4.0" } }, - "/_ml/anomaly_detectors/_validate": { - "post": { - "tags": [ - "ml" - ], - "summary": "Validates an anomaly detection job", - "operationId": "ml-validate", - "requestBody": { - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "job_id": { - "$ref": "#/components/schemas/_types:Id" - }, - "analysis_config": { - "$ref": "#/components/schemas/ml._types:AnalysisConfig" - }, - "analysis_limits": { - "$ref": "#/components/schemas/ml._types:AnalysisLimits" - }, - "data_description": { - "$ref": "#/components/schemas/ml._types:DataDescription" - }, - "description": { - "type": "string" - }, - "model_plot": { - "$ref": "#/components/schemas/ml._types:ModelPlotConfig" - }, - "model_snapshot_id": { - "$ref": "#/components/schemas/_types:Id" - }, - "model_snapshot_retention_days": { - "type": "number" - }, - "results_index_name": { - "$ref": "#/components/schemas/_types:IndexName" - } - } - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/_types:AcknowledgedResponseBase" - } - } - } - } - }, - "x-state": "Added in 6.3.0" - } - }, - "/_ml/anomaly_detectors/_validate/detector": { - "post": { - "tags": [ - "ml" - ], - "summary": "Validates an anomaly detection detector", - "operationId": "ml-validate-detector", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ml._types:Detector" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/_types:AcknowledgedResponseBase" - } - } - } - } - }, - "x-state": "Added in 5.4.0" - } - }, "/_monitoring/bulk": { "put": { "tags": [ @@ -25775,9 +25568,6 @@ }, { "$ref": "#/components/parameters/search#sort" - }, - { - "$ref": "#/components/parameters/search#force_synthetic_source" } ], "requestBody": { @@ -25925,9 +25715,6 @@ }, { "$ref": "#/components/parameters/search#sort" - }, - { - "$ref": "#/components/parameters/search#force_synthetic_source" } ], "requestBody": { @@ -26080,9 +25867,6 @@ }, { "$ref": "#/components/parameters/search#sort" - }, - { - "$ref": "#/components/parameters/search#force_synthetic_source" } ], "requestBody": { @@ -26233,9 +26017,6 @@ }, { "$ref": "#/components/parameters/search#sort" - }, - { - "$ref": "#/components/parameters/search#force_synthetic_source" } ], "requestBody": { @@ -32100,121 +31881,6 @@ "x-state": "Added in 0.0.0" } }, - "/_snapshot/{repository}/_verify_integrity": { - "post": { - "tags": [ - "snapshot" - ], - "summary": "Verifies the integrity of the contents of a snapshot repository", - "operationId": "snapshot-repository-verify-integrity", - "parameters": [ - { - "in": "path", - "name": "repository", - "description": "A repository name", - "required": true, - "deprecated": false, - "schema": { - "$ref": "#/components/schemas/_types:Names" - }, - "style": "simple" - }, - { - "in": "query", - "name": "meta_thread_pool_concurrency", - "description": "Number of threads to use for reading metadata", - "deprecated": false, - "schema": { - "type": "number" - }, - "style": "form" - }, - { - "in": "query", - "name": "blob_thread_pool_concurrency", - "description": "Number of threads to use for reading blob contents", - "deprecated": false, - "schema": { - "type": "number" - }, - "style": "form" - }, - { - "in": "query", - "name": "snapshot_verification_concurrency", - "description": "Number of snapshots to verify concurrently", - "deprecated": false, - "schema": { - "type": "number" - }, - "style": "form" - }, - { - "in": "query", - "name": "index_verification_concurrency", - "description": "Number of indices to verify concurrently", - "deprecated": false, - "schema": { - "type": "number" - }, - "style": "form" - }, - { - "in": "query", - "name": "index_snapshot_verification_concurrency", - "description": "Number of snapshots to verify concurrently within each index", - "deprecated": false, - "schema": { - "type": "number" - }, - "style": "form" - }, - { - "in": "query", - "name": "max_failed_shard_snapshots", - "description": "Maximum permitted number of failed shard snapshots", - "deprecated": false, - "schema": { - "type": "number" - }, - "style": "form" - }, - { - "in": "query", - "name": "verify_blob_contents", - "description": "Whether to verify the contents of individual blobs", - "deprecated": false, - "schema": { - "type": "boolean" - }, - "style": "form" - }, - { - "in": "query", - "name": "max_bytes_per_sec", - "description": "Rate limit for individual blob verification", - "deprecated": false, - "schema": { - "type": "string" - }, - "style": "form" - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "object" - } - } - } - } - }, - "x-state": "Technical preview" - } - }, "/_snapshot/{repository}/{snapshot}/_restore": { "post": { "tags": [ @@ -98285,16 +97951,6 @@ }, "style": "simple" }, - "mget#force_synthetic_source": { - "in": "query", - "name": "force_synthetic_source", - "description": "Should this request force synthetic _source?\nUse this to test if the mapping supports synthetic _source and to get a sense of the worst case performance.\nFetches with this enabled will be slower the enabling synthetic source natively in the index.", - "deprecated": false, - "schema": { - "type": "boolean" - }, - "style": "form" - }, "mget#preference": { "in": "query", "name": "preference", @@ -100864,16 +100520,6 @@ }, "style": "form" }, - "search#force_synthetic_source": { - "in": "query", - "name": "force_synthetic_source", - "description": "Should this request force synthetic _source?\nUse this to test if the mapping supports synthetic _source and to get a sense of the worst case performance.\nFetches with this enabled will be slower the enabling synthetic source natively in the index.", - "deprecated": false, - "schema": { - "type": "boolean" - }, - "style": "form" - }, "search_application.get_behavioral_analytics#name": { "in": "path", "name": "name",