Skip to content

Commit 93976c7

Browse files
committed
Merge remote-tracking branch 'origin/main' into eis-rerank-task-type
2 parents 7d23007 + 7efcc50 commit 93976c7

File tree

978 files changed

+64617
-9871
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

978 files changed

+64617
-9871
lines changed

.github/workflows/update-rest-api-json.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
branch: ['main', '9.0', '8.19', '8.18', '8.17', '8.16', '7.17']
16+
branch: ['main', '9.0', '8.19', '8.18', '8.17']
1717

1818
steps:
1919
- uses: actions/checkout@v4
@@ -28,8 +28,7 @@ jobs:
2828
- name: Install deps
2929
run: |
3030
npm install --prefix .github/download-artifacts
31-
npm install --prefix compiler
32-
npm install --prefix typescript-generator
31+
make setup
3332
3433
- name: Download artifacts
3534
run: |
@@ -53,12 +52,3 @@ jobs:
5352
delete-branch: true
5453
reviewers: Anaethelion,ezimuel,flobernd,JoshMock,l-trotta,miguelgrinberg,picandocodigo,pquentin,swallez,technige
5554
branch: automated/rest-api-spec-update-${{ matrix.branch }}
56-
57-
- name: Open an issue if the action fails
58-
if: ${{ failure() }}
59-
uses: nashmaniac/[email protected]
60-
with:
61-
title: rest-api-spec update failed
62-
token: ${{ secrets.GITHUB_TOKEN }}
63-
labels: bug
64-
body: The rest-api-spec action is currently failing, see [here](https://github.com/elastic/elasticsearch-specification/actions/workflows/update-rest-api-json.yml).

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ compiler/test/**/output/
6969
output/openapi/elasticsearch-serverless-openapi.tmp*.json
7070
output/openapi/elasticsearch-serverless-openapi.examples.json
7171
output/openapi/elasticsearch-openapi.tmp*.json
72-
output/openapi/elasticsearch-openapi.examples.json
72+
output/openapi/elasticsearch-openapi.examples.json
73+
output/openapi/elasticsearch-serverless-openapi-docs.json
74+
output/openapi/elasticsearch-openapi-docs.json

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ setup: ## Install dependencies for contrib target
4343
@npm install --prefix validator
4444
@npm install --prefix specification
4545
@npm install @redocly/cli
46+
@npm install --prefix docs/examples
4647

4748
clean-dep: ## Clean npm dependencies
4849
@rm -rf compiler/node_modules
@@ -55,6 +56,12 @@ transform-to-openapi: ## Generate the OpenAPI definition from the compiled schem
5556
@npm run transform-to-openapi -- --schema output/schema/schema.json --flavor stack --output output/openapi/elasticsearch-openapi.json
5657
@npm run transform-to-openapi -- --schema output/schema/schema.json --flavor serverless --output output/openapi/elasticsearch-serverless-openapi.json
5758

59+
transform-to-openapi-for-docs: ## Generate the OpenAPI definition tailored for API docs generation
60+
@make generate-language-examples
61+
@make generate
62+
@npm run transform-to-openapi -- --schema output/schema/schema.json --flavor stack --lift-enum-descriptions --merge-multipath-endpoints --multipath-redirects --include-language-examples --output output/openapi/elasticsearch-openapi-docs.json
63+
@npm run transform-to-openapi -- --schema output/schema/schema.json --flavor serverless --lift-enum-descriptions --merge-multipath-endpoints --multipath-redirects --include-language-examples --output output/openapi/elasticsearch-serverless-openapi-docs.json
64+
5865
filter-for-serverless: ## Generate the serverless version from the compiled schema
5966
@npm run --prefix compiler filter-by-availability -- --serverless --visibility=public --input ../output/schema/schema.json --output ../output/output/openapi/elasticsearch-serverless-openapi.json
6067

@@ -71,6 +78,10 @@ overlay-docs: ## Apply overlays to OpenAPI documents
7178
rm output/openapi/elasticsearch-serverless-openapi.tmp*.json
7279
rm output/openapi/elasticsearch-openapi.tmp*.json
7380

81+
generate-language-examples:
82+
@node docs/examples/generate-language-examples.js
83+
@npm run format:fix-examples --prefix compiler
84+
7485
lint-docs: ## Lint the OpenAPI documents after overlays
7586
@npx @redocly/cli lint "output/openapi/elasticsearch-*.json" --config "docs/linters/redocly.yaml" --format stylish --max-problems 500
7687

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ Follow the steps to generate the JSON representation, then:
6060
```
6161
# Generate the OpenAPI representation
6262
$ make transform-to-openapi
63+
```
64+
65+
To generate the JSON representation that is used for documentation purposes, the commands are different:
66+
67+
```
68+
# Generate the OpenAPI files
69+
$ make transform-to-openapi-for-docs
6370
6471
# Apply fixes
6572
$ make overlay-docs

compiler-rs/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler-rs/clients_schema/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub struct Availability {
264264
pub visibility: Option<Visibility>,
265265
}
266266

267-
/// The availability of an
267+
/// The availability of an endpoint, field or parameter
268268
pub type Availabilities = IndexMap<Flavor, Availability>;
269269

270270
pub trait AvailabilityFilter: Fn(&Option<Availabilities>) -> bool {}
@@ -484,20 +484,28 @@ impl TypeDefinition {
484484

485485
/// The Example type is used for both requests and responses.
486486
///
487-
/// This type definition is taken from the OpenAPI spec
487+
/// This type definition is based on the OpenAPI spec
488488
/// https://spec.openapis.org/oas/v3.1.0#example-object
489-
/// with the exception of using String as the 'value' type.
489+
/// with the exception of using String as the 'value' type,
490+
/// and some custom additions.
490491
///
491492
/// The OpenAPI v3 spec also defines the 'Example' type, so
492493
/// to distinguish them, this type is called SchemaExample.
493494
495+
#[derive(Debug, Clone, Serialize, Deserialize)]
496+
pub struct ExampleAlternative {
497+
pub language: String,
498+
pub code: String,
499+
}
500+
494501
#[derive(Debug, Clone, Serialize, Deserialize)]
495502
pub struct SchemaExample {
496503
pub summary: Option<String>,
497504
pub method_request: Option<String>,
498505
pub description: Option<String>,
499506
pub value: Option<String>,
500507
pub external_value: Option<String>,
508+
pub alternatives: Option<Vec<ExampleAlternative>>,
501509
}
502510

503511
/// Common attributes for all type definitions

compiler-rs/clients_schema_to_openapi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ clients_schema = {path="../clients_schema"}
1010
argh = { workspace = true }
1111
derive_more = { version = "2", features = ["from_str"] }
1212
serde_json = { workspace = true }
13-
serde_ignored = { workspace = true }
13+
itertools = { workspace = true }
1414
icu_segmenter = { workspace = true }
1515
openapiv3 = { workspace = true }
1616
anyhow = { workspace = true }

compiler-rs/clients_schema_to_openapi/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler-rs/clients_schema_to_openapi/src/cli.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,37 @@ pub struct Cli {
2020
#[argh(option, default = "SchemaFlavor::All")]
2121
pub flavor: SchemaFlavor,
2222

23-
/// add enum descriptions to property descriptions [default = true]
24-
#[argh(option, default = "true")]
25-
pub lift_enum_descriptions: bool,
26-
2723
/// generate only this namespace (can be repeated)
2824
#[argh(option)]
2925
pub namespace: Vec<String>,
26+
27+
/// add enum descriptions to property descriptions [default = true]
28+
#[argh(switch)]
29+
pub lift_enum_descriptions: bool,
30+
31+
/// merge endpoints with multiple paths into a single OpenAPI operation [default = false]
32+
#[argh(switch)]
33+
pub merge_multipath_endpoints: bool,
34+
35+
/// output a redirection map when merging multipath endpoints
36+
#[argh(switch)]
37+
pub multipath_redirects: bool,
38+
39+
/// include the x-codeSamples extension with language examples for all endpoints
40+
#[argh(switch)]
41+
pub include_language_examples: bool,
42+
}
43+
44+
impl Cli {
45+
pub fn redirect_path(&self, output: &PathBuf) -> Option<String> {
46+
if self.multipath_redirects {
47+
let path = output.to_string_lossy();
48+
let path = path.rsplit_once('.').unwrap().0;
49+
Some(format!("{}.redirects.csv", path))
50+
} else {
51+
None
52+
}
53+
}
3054
}
3155

3256
use derive_more::FromStr;
@@ -42,20 +66,23 @@ pub enum SchemaFlavor {
4266
}
4367

4468
impl From<Cli> for Configuration {
45-
fn from(val: Cli) -> Configuration {
46-
let flavor = match val.flavor {
69+
fn from(cli: Cli) -> Configuration {
70+
let flavor = match cli.flavor {
4771
SchemaFlavor::All => None,
4872
SchemaFlavor::Serverless => Some(Flavor::Serverless),
4973
SchemaFlavor::Stack => Some(Flavor::Stack),
5074
};
5175

5276
Configuration {
5377
flavor,
54-
lift_enum_descriptions: val.lift_enum_descriptions,
55-
namespaces: if val.namespace.is_empty() {
78+
lift_enum_descriptions: cli.lift_enum_descriptions,
79+
merge_multipath_endpoints: cli.merge_multipath_endpoints,
80+
multipath_redirects: cli.multipath_redirects,
81+
include_language_examples: cli.include_language_examples,
82+
namespaces: if cli.namespace.is_empty() {
5683
None
5784
} else {
58-
Some(val.namespace)
85+
Some(cli.namespace)
5986
},
6087
}
6188
}

compiler-rs/clients_schema_to_openapi/src/components.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
use std::collections::BTreeMap;
1819
use clients_schema::TypeName;
1920
use openapiv3::{Components, Parameter, ReferenceOr, RequestBody, Response, Schema, StatusCode};
2021
use crate::Configuration;
@@ -32,11 +33,19 @@ pub struct TypesAndComponents<'a> {
3233
pub config: &'a Configuration,
3334
pub model: &'a clients_schema::IndexedModel,
3435
pub components: &'a mut Components,
36+
// Redirections (if paths multipaths endpoints are merged)
37+
pub redirects: Option<BTreeMap<String, String>>,
3538
}
3639

3740
impl<'a> TypesAndComponents<'a> {
3841
pub fn new(config: &'a Configuration, model: &'a clients_schema::IndexedModel, components: &'a mut Components) -> TypesAndComponents<'a> {
39-
TypesAndComponents { config, model, components }
42+
let redirects = if config.merge_multipath_endpoints && config.multipath_redirects {
43+
Some(BTreeMap::new())
44+
} else {
45+
None
46+
};
47+
48+
TypesAndComponents { config, model, components, redirects }
4049
}
4150

4251
pub fn add_request_body(&mut self, endpoint: &str, body: RequestBody) -> ReferenceOr<RequestBody> {

0 commit comments

Comments
 (0)