Skip to content

Commit c58f293

Browse files
Merge branch 'main' into jdahlgren/get-snapshot-status-missing-stats-for-restarted-nodes
2 parents a85ad64 + 1adf40e commit c58f293

File tree

769 files changed

+66079
-12307
lines changed

Some content is hidden

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

769 files changed

+66079
-12307
lines changed

.github/validate-pr/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,10 @@ async function run() {
141141
}
142142
comment += `\nYou can validate ${table.length === 1 ? 'this' : 'these'} API${table.length === 1 ? '' : 's'} yourself by using the ${tick}make validate${tick} target.\n`
143143

144-
await octokit.rest.issues.createComment({
145-
owner: 'elastic',
146-
repo: 'elasticsearch-specification',
147-
issue_number: context.payload.pull_request.number,
148-
body: comment
149-
})
144+
core.setOutput('has_results', 'true')
145+
core.setOutput('comment_body', comment)
146+
} else {
147+
core.setOutput('has_results', 'false')
150148
}
151149

152150
core.info('Done!')

.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).

.github/workflows/validate-pr.yml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,26 @@ jobs:
6060
fi
6161
node scripts/upload-recording/download.js --branch $branch --git
6262
node scripts/clone-elasticsearch/index.js --branch $branch
63-
env:
64-
GCS_CREDENTIALS: ${{ secrets.GCS_CREDENTIALS }}
65-
66-
- name: Remove previous comment
67-
uses: maheshrayas/action-pr-comment-delete@v1
68-
with:
69-
github_token: ${{ secrets.GITHUB_TOKEN }}
70-
org: elastic
71-
repo: elasticsearch-specification
72-
user: github-actions[bot]
73-
issue: ${{ github.event.number }}
7463
7564
- name: Run validation
65+
id: validation
7666
working-directory: ./elasticsearch-specification
7767
run: node .github/validate-pr --token ${{ secrets.GITHUB_TOKEN }}
68+
69+
- name: Find existing comment
70+
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
71+
id: find-comment
72+
with:
73+
issue-number: ${{ github.event.pull_request.number }}
74+
comment-author: 'github-actions[bot]'
75+
body-includes: 'Following you can find the validation results'
76+
77+
- name: Create or update comment
78+
if: steps.validation.outputs.has_results == 'true'
79+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
80+
with:
81+
token: ${{ secrets.GITHUB_TOKEN }}
82+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
83+
issue-number: ${{ github.event.pull_request.number }}
84+
body: ${{ steps.validation.outputs.comment_body }}
85+
edit-mode: replace

.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: 13 additions & 1 deletion
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
@@ -56,7 +57,10 @@ transform-to-openapi: ## Generate the OpenAPI definition from the compiled schem
5657
@npm run transform-to-openapi -- --schema output/schema/schema.json --flavor serverless --output output/openapi/elasticsearch-serverless-openapi.json
5758

5859
transform-to-openapi-for-docs: ## Generate the OpenAPI definition tailored for API docs generation
59-
@npm run transform-to-openapi -- --schema output/schema/schema.json --flavor stack --lift-enum-descriptions --merge-multipath-endpoints --output output/openapi/elasticsearch-openapi-docs.json
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
6064

6165
filter-for-serverless: ## Generate the serverless version from the compiled schema
6266
@npm run --prefix compiler filter-by-availability -- --serverless --visibility=public --input ../output/schema/schema.json --output ../output/output/openapi/elasticsearch-serverless-openapi.json
@@ -74,6 +78,14 @@ overlay-docs: ## Apply overlays to OpenAPI documents
7478
rm output/openapi/elasticsearch-serverless-openapi.tmp*.json
7579
rm output/openapi/elasticsearch-openapi.tmp*.json
7680

81+
generate-language-examples:
82+
@node docs/examples/generate-language-examples.js
83+
@npm run format:fix-examples --prefix compiler
84+
85+
generate-language-examples-with-java:
86+
@node docs/examples/generate-language-examples.js java
87+
@npm run format:fix-examples --prefix compiler
88+
7789
lint-docs: ## Lint the OpenAPI documents after overlays
7890
@npx @redocly/cli lint "output/openapi/elasticsearch-*.json" --config "docs/linters/redocly.yaml" --format stylish --max-problems 500
7991

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

api-design-guidelines/data-modelling.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Or better yet, to completely avoid using dynamic keys the user-defined value can
150150

151151
### Model object variants in a consumable way
152152

153-
Sometimes an API accepts an object but the keys are determined by what "kind/variant" of the object is intended. An example of this is aggregations, queries, and pipeline steps. There are two ways the Elasticsearch API handles this situation. The first method is using an **internal variant type** property like "type" with analyzers:
153+
Sometimes an API accepts an object but the keys are determined by what "kind/variant" of the object is intended. An example of this is aggregations, queries, and pipeline steps. There are two ways the Elasticsearch API handles this situation. The first method is using **internal tagging** with property like "type" with analyzers:
154154

155155
```yaml
156156
{
@@ -159,7 +159,7 @@ Sometimes an API accepts an object but the keys are determined by what "kind/var
159159
}
160160
```
161161

162-
The second is using **external variants** where the inner object is wrapped with an object with a single key containing the kind of the inner object. This example changes the analyzer from above to use an external variant:
162+
The second is using **external tagging** where the inner object is wrapped with an object with a single key containing the kind of the inner object. This example changes the analyzer from above to use an external variant:
163163

164164
```yaml
165165
{
@@ -169,7 +169,7 @@ The second is using **external variants** where the inner object is wrapped with
169169
}
170170
```
171171

172-
When choosing between these two possibilities **favor using external variants** as it removes the requirement to buffer key-value pairs until the internal variant property is found. Using external variants also improves traversability of the API (ie auto-complete) as properties can be anticipated without waiting for the discriminant property.
172+
Internal tagging is a common way to identify variants and should usually be preferred. However, it may have performance implications when used to deserialize large objects in strongly-typed languages. In that case, external tagging should be considered instead, as it removes the requirement to buffer key-value pairs until the internal variant property is found. Using external tagging also improves traversability of the API (ie auto-complete) as properties can be anticipated without waiting for the discriminant property.
173173

174174
## Model enumerations in a portable way
175175

api-design-guidelines/requests-responses.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -97,34 +97,6 @@ It's best to use the body for large or high cardinality variable-length request
9797
- Large objects (Query DSL, aggregations, machine learning models)
9898
- High cardinality variable length values (list of fields, indices, shards, document IDs)
9999

100-
## Adhere to the robustness principle
101-
102-
The robustness principle states:
103-
104-
> "be conservative in what you do, be liberal in what you accept from others"
105-
106-
This principle can apply in a number of ways, but in particular it can determine the design of API requests and responses. An API request may be built flexibly so as to allow both verbose detailed payloads and terse convenience payloads. The corresponding response, however, should always be structured predictably, and not depend on a particular syntax used within the request.
107-
108-
As an example, consider an API that looks up entities based on their ID. The request may be structured to allow either a single ID or a collection of IDs to be passed in. However, the API response should always return a collection of entities, even if that collection only contains one entity.
109-
110-
This principle allows for simpler consumer code that neither has to remember state between request and response, nor needs to "sniff" the output to determine its structure. If multiple variants of the response are truly desired, this may suggest that multiple API endpoints should be introduced, for example called `get_single_entity` and `get_multiple_entities`.
111-
112-
An example of this is the datafeeds API which accepts either a string or list of strings for indices but always returns a list of strings:
113-
114-
```yaml
115-
PUT /_ml/datafeeds/feed-id
116-
{
117-
"indices": "index-name", // Input is a string.
118-
...
119-
}
120-
121-
GET /_ml/datafeeds/feed-id
122-
{
123-
"indices": ["index-name"], // Always returns a list of strings.
124-
...
125-
}
126-
```
127-
128100
## Consider how client functions would wrap the API endpoint
129101

130102
It is common within client-side architecture to provide a one-to-one mapping between API endpoint and client language function. This simplifies implementation and documentation, provides good developer experience, and makes tracking of endpoint usage straightforward.

compiler-rs/clients_schema/src/lib.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub trait Documented {
5858
pub trait ExternalDocument {
5959
fn ext_doc_id(&self) -> Option<&str>;
6060
fn ext_doc_url(&self) -> Option<&str>;
61+
fn ext_previous_version_doc_url(&self) -> Option<&str>;
6162
}
6263

6364
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -322,6 +323,9 @@ pub struct Property {
322323
#[serde(skip_serializing_if = "Option::is_none")]
323324
pub ext_doc_url: Option<String>,
324325

326+
#[serde(skip_serializing_if = "Option::is_none")]
327+
pub ext_previous_version_doc_url: Option<String>,
328+
325329
#[serde(skip_serializing_if = "Option::is_none")]
326330
pub ext_doc_id: Option<String>,
327331

@@ -371,6 +375,10 @@ impl ExternalDocument for Property {
371375
self.ext_doc_url.as_deref()
372376
}
373377

378+
fn ext_previous_version_doc_url(&self) -> Option<&str> {
379+
self.ext_previous_version_doc_url.as_deref()
380+
}
381+
374382
fn ext_doc_id(&self) -> Option<&str> {
375383
self.ext_doc_id.as_deref()
376384
}
@@ -484,20 +492,28 @@ impl TypeDefinition {
484492

485493
/// The Example type is used for both requests and responses.
486494
///
487-
/// This type definition is taken from the OpenAPI spec
495+
/// This type definition is based on the OpenAPI spec
488496
/// https://spec.openapis.org/oas/v3.1.0#example-object
489-
/// with the exception of using String as the 'value' type.
497+
/// with the exception of using String as the 'value' type,
498+
/// and some custom additions.
490499
///
491500
/// The OpenAPI v3 spec also defines the 'Example' type, so
492501
/// to distinguish them, this type is called SchemaExample.
493502
503+
#[derive(Debug, Clone, Serialize, Deserialize)]
504+
pub struct ExampleAlternative {
505+
pub language: String,
506+
pub code: String,
507+
}
508+
494509
#[derive(Debug, Clone, Serialize, Deserialize)]
495510
pub struct SchemaExample {
496511
pub summary: Option<String>,
497512
pub method_request: Option<String>,
498513
pub description: Option<String>,
499514
pub value: Option<String>,
500515
pub external_value: Option<String>,
516+
pub alternatives: Option<Vec<ExampleAlternative>>,
501517
}
502518

503519
/// Common attributes for all type definitions
@@ -520,6 +536,9 @@ pub struct BaseType {
520536
#[serde(skip_serializing_if = "Option::is_none")]
521537
pub ext_doc_url: Option<String>,
522538

539+
#[serde(skip_serializing_if = "Option::is_none")]
540+
pub ext_previous_version_doc_url: Option<String>,
541+
523542
#[serde(skip_serializing_if = "Option::is_none")]
524543
pub ext_doc_id: Option<String>,
525544

@@ -560,6 +579,7 @@ impl BaseType {
560579
spec_location: None,
561580
ext_doc_id: None,
562581
ext_doc_url: None,
582+
ext_previous_version_doc_url: None,
563583
}
564584
}
565585
}
@@ -583,6 +603,10 @@ impl ExternalDocument for BaseType {
583603
self.ext_doc_url.as_deref()
584604
}
585605

606+
fn ext_previous_version_doc_url(&self) -> Option<&str> {
607+
self.ext_previous_version_doc_url.as_deref()
608+
}
609+
586610
fn ext_doc_id(&self) -> Option<&str> {
587611
self.ext_doc_id.as_deref()
588612
}
@@ -611,6 +635,10 @@ impl<T: WithBaseType> ExternalDocument for T {
611635
self.base().doc_url()
612636
}
613637

638+
fn ext_previous_version_doc_url(&self) -> Option<&str> {
639+
self.base().ext_previous_version_doc_url()
640+
}
641+
614642
fn ext_doc_id(&self) -> Option<&str> {
615643
self.base().doc_id()
616644
}
@@ -887,6 +915,9 @@ pub struct Endpoint {
887915
#[serde(skip_serializing_if = "Option::is_none")]
888916
pub ext_doc_url: Option<String>,
889917

918+
#[serde(skip_serializing_if = "Option::is_none")]
919+
pub ext_previous_version_doc_url: Option<String>,
920+
890921
#[serde(skip_serializing_if = "Option::is_none")]
891922
pub deprecation: Option<Deprecation>,
892923

@@ -937,6 +968,10 @@ impl ExternalDocument for Endpoint {
937968
self.ext_doc_url.as_deref()
938969
}
939970

971+
fn ext_previous_version_doc_url(&self) -> Option<&str> {
972+
self.ext_previous_version_doc_url.as_deref()
973+
}
974+
940975
fn ext_doc_id(&self) -> Option<&str> {
941976
self.ext_doc_id.as_deref()
942977
}

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.

0 commit comments

Comments
 (0)