Skip to content

Commit 9791615

Browse files
authored
Merge branch 'main' into fix/logstash-pipeline-settings
2 parents c6dd8eb + e50b886 commit 9791615

File tree

245 files changed

+61301
-35757
lines changed

Some content is hidden

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

245 files changed

+61301
-35757
lines changed

.buildkite/kibana.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@ set -euo pipefail
55
# Since we're into the current repo, move to the top-level
66
cd ..
77

8+
echo "--- Install dependencies"
9+
lsb_release -a
10+
apt-get update -y
11+
apt-get install -y unzip
12+
813
echo "--- Clone elasticsearch-js"
914
git clone -v -- [email protected]:elastic/elasticsearch-js.git
10-
pushd elasticsearch-js
11-
git checkout $BUILDKITE_BRANCH
12-
popd
15+
16+
echo "--- Clone elastic-client-generator-js"
17+
git clone -v -- [email protected]:elastic/elastic-client-generator-js.git
18+
mkdir elastic-client-generator-js/output
1319

1420
echo "--- Clone Kibana"
1521
git clone -v --reference /usr/local/git-references/git-github-com-elastic-kibana-git -- [email protected]:elastic/kibana.git
16-
cd kibana
22+
pushd kibana
1723

1824
echo "--- Install Node.js and Yarn"
1925
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
@@ -25,13 +31,17 @@ set -e
2531
nvm install
2632
nvm use
2733
npm install --global yarn
34+
popd
2835

2936
echo "--- Install elasticsearch-js"
30-
pushd ../elasticsearch-js
37+
pushd elasticsearch-js
3138
npm install
39+
node .buildkite/make.mjs --task codegen main
3240
npm run build
3341
npm pack
3442
popd
43+
44+
pushd kibana
3545
yarn add ../elasticsearch-js/elastic-elasticsearch-*.tgz
3646

3747
echo "--- Bootstrap Kibana"

.buildkite/kibana.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ agents:
33
cpu: "4"
44
ephemeralStorage: 15Gi
55

6-
76
steps:
87
- label: "Run Kibana type checks"
98
command: .buildkite/kibana.sh

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Update rest-api-spec
33
on:
44
workflow_dispatch:
55
schedule:
6-
- cron: '0 4 * * *' # At 04:00.
6+
- cron: '0 4 * * *' # At 04:00.
77

88
jobs:
99
update-rest-api:
@@ -49,7 +49,7 @@ jobs:
4949
title: Update rest-api-spec ${{ matrix.branch }}
5050
body: 'As titled.'
5151
commit-message: 'Update rest-api-spec'
52-
labels: specification
52+
labels: specification,skip-backport
5353
delete-branch: true
5454
reviewers: Anaethelion,ezimuel,flobernd,JoshMock,l-trotta,miguelgrinberg,picandocodigo,pquentin,swallez,technige
5555
branch: automated/rest-api-spec-update-${{ matrix.branch }}
@@ -62,4 +62,3 @@ jobs:
6262
token: ${{ secrets.GITHUB_TOKEN }}
6363
labels: bug
6464
body: The rest-api-spec action is currently failing, see [here](https://github.com/elastic/elasticsearch-specification/actions/workflows/update-rest-api-json.yml).
65-

compiler-rs/clients_schema/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,23 @@ impl TypeDefinition {
482482
}
483483
}
484484

485+
/// The Example type is used for both requests and responses.
486+
///
487+
/// This type definition is taken from the OpenAPI spec
488+
/// https://spec.openapis.org/oas/v3.1.0#example-object
489+
/// with the exception of using String as the 'value' type.
490+
///
491+
/// The OpenAPI v3 spec also defines the 'Example' type, so
492+
/// to distinguish them, this type is called SchemaExample.
493+
494+
#[derive(Debug, Clone, Serialize, Deserialize)]
495+
pub struct SchemaExample {
496+
pub summary: Option<String>,
497+
pub description: Option<String>,
498+
pub value: Option<String>,
499+
pub external_value: Option<String>,
500+
}
501+
485502
/// Common attributes for all type definitions
486503
#[derive(Debug, Clone, Serialize, Deserialize)]
487504
#[serde(rename_all = "camelCase")]
@@ -675,6 +692,8 @@ pub struct Request {
675692

676693
#[serde(default, skip_serializing_if = "Vec::is_empty")]
677694
pub attached_behaviors: Vec<String>,
695+
696+
pub examples: Option<IndexMap<String, SchemaExample>>
678697
}
679698

680699
impl WithBaseType for Request {
@@ -703,6 +722,8 @@ pub struct Response {
703722

704723
#[serde(default, skip_serializing_if = "Vec::is_empty")]
705724
pub exceptions: Vec<ResponseException>,
725+
726+
pub examples: Option<IndexMap<String, SchemaExample>>
706727
}
707728

708729
impl WithBaseType for Response {

compiler-rs/clients_schema_to_openapi/package-lock.json

Lines changed: 16 additions & 16 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/paths.rs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ use std::fmt::Write;
2020

2121
use anyhow::{anyhow, bail};
2222
use clients_schema::Property;
23+
use indexmap::IndexMap;
2324
use indexmap::indexmap;
2425
use icu_segmenter::SentenceSegmenter;
2526
use openapiv3::{
2627
MediaType, Parameter, ParameterData, ParameterSchemaOrContent, PathItem, PathStyle, Paths, QueryStyle, ReferenceOr,
27-
RequestBody, Response, Responses, StatusCode,
28+
RequestBody, Response, Responses, StatusCode, Example
2829
};
30+
use clients_schema::SchemaExample;
31+
use serde_json::json;
2932

3033
use crate::components::TypesAndComponents;
3134

@@ -116,15 +119,42 @@ pub fn add_endpoint(
116119

117120
//---- Prepare request body
118121

122+
// This function converts the IndexMap<String, SchemaExample> examples of
123+
// schema.json to IndexMap<String, ReferenceOr<Example>> which is the format
124+
// that OpenAPI expects.
125+
fn get_openapi_examples(schema_examples: IndexMap<String, SchemaExample>) -> IndexMap<String, ReferenceOr<Example>> {
126+
let mut openapi_examples = indexmap! {};
127+
for (name, schema_example) in schema_examples {
128+
let openapi_example = Example {
129+
value: Some(json!(schema_example.value)),
130+
description: schema_example.description.clone(),
131+
summary: schema_example.summary.clone(),
132+
external_value: None,
133+
extensions: Default::default(),
134+
};
135+
openapi_examples.insert(name.clone(), ReferenceOr::Item(openapi_example));
136+
}
137+
return openapi_examples;
138+
}
139+
140+
141+
let mut request_examples: IndexMap<String, ReferenceOr<Example>> = indexmap! {};
142+
// If this endpoint request has examples in schema.json, convert them to the
143+
// OpenAPI format and add them to the endpoint request in the OpenAPI document.
144+
if request.examples.is_some() {
145+
request_examples = get_openapi_examples(request.examples.as_ref().unwrap().clone());
146+
}
147+
119148
let request_body = tac.convert_request(request)?.map(|schema| {
120149
let media = MediaType {
121150
schema: Some(schema),
122151
example: None,
123-
examples: Default::default(),
152+
examples: request_examples,
124153
encoding: Default::default(),
125154
extensions: Default::default(),
126155
};
127156

157+
128158
let body = RequestBody {
129159
description: None,
130160
// FIXME: nd-json requests
@@ -142,17 +172,24 @@ pub fn add_endpoint(
142172

143173
//---- Prepare request responses
144174

175+
145176
// FIXME: buggy for responses with no body
146177
// TODO: handle binary responses
147178
let response_def = tac.model.get_response(endpoint.response.as_ref().unwrap())?;
179+
let mut response_examples: IndexMap<String, ReferenceOr<Example>> = indexmap! {};
180+
// If this endpoint response has examples in schema.json, convert them to the
181+
// OpenAPI format and add them to the endpoint response in the OpenAPI document.
182+
if response_def.examples.is_some() {
183+
response_examples = get_openapi_examples(response_def.examples.as_ref().unwrap().clone());
184+
}
148185
let response = Response {
149186
description: "".to_string(),
150187
headers: Default::default(),
151188
content: indexmap! {
152189
"application/json".to_string() => MediaType {
153190
schema: tac.convert_response(response_def)?,
154191
example: None,
155-
examples: Default::default(),
192+
examples: response_examples,
156193
encoding: Default::default(),
157194
extensions: Default::default(),
158195
}
Binary file not shown.

compiler/run-validations.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ try {
3131
closest = fl.closest
3232
minimist = require('minimist')
3333
} catch (err) {
34-
console.log('It looks like you didn\'t install the project dependencies, please run \'make setup\'')
34+
console.log(
35+
"It looks like you didn't install the project dependencies, please run 'make setup'"
36+
)
3537
process.exit(1)
3638
}
3739

@@ -60,7 +62,8 @@ const apis = require('../output/schema/schema.json')
6062
async function run () {
6163
const options = minimist(process.argv.slice(2), {
6264
string: ['api', 'type', 'branch'],
63-
boolean: ['cache']
65+
boolean: ['cache'],
66+
default: { cache: true }
6467
})
6568

6669
spinner.text = 'Checking requirements'
@@ -93,7 +96,7 @@ async function run () {
9396

9497
const isFlightRecorderCloned = await $`[[ -d ${path.join(__dirname, '..', '..', 'clients-flight-recorder')} ]]`.exitCode === 0
9598
if (!isFlightRecorderCloned) {
96-
spinner.text = 'It looks like you didn\'t cloned the flight recorder, doing that for you'
99+
spinner.text = 'It looks like you didn\'t clone the flight recorder, doing that for you'
97100
await $`git clone https://github.com/elastic/clients-flight-recorder.git ${path.join(__dirname, '..', '..', 'clients-flight-recorder')}`
98101
} else if (isStale) {
99102
spinner.text = 'Pulling the latest flight recorder changes'
@@ -105,7 +108,7 @@ async function run () {
105108
const isCompilerInstalled = await $`[[ -d ${path.join(compilerPath, 'node_modules')} ]]`.exitCode === 0
106109
const isTsGeneratorInstalled = await $`[[ -d ${path.join(tsGeneratorPath, 'node_modules')} ]]`.exitCode === 0
107110
if (noCache || !isCompilerInstalled || !isTsGeneratorInstalled) {
108-
spinner.text = 'It looks like you didn\'t installed the project dependencies, doing that for you'
111+
spinner.text = "It looks like you didn't install the project dependencies, doing that for you"
109112
await $`npm install --prefix ${compilerPath}`
110113
await $`npm install --prefix ${tsGeneratorPath}`
111114
}

compiler/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import validateModel from './steps/validate-model'
2828
import addContentType from './steps/add-content-type'
2929
import readDefinitionValidation from './steps/read-definition-validation'
3030
import addDeprecation from './steps/add-deprecation'
31+
import ExamplesProcessor from './steps/add-examples'
3132

3233
const nvmrc = readFileSync(join(__dirname, '..', '..', '.nvmrc'), 'utf8')
3334
const nodejsMajor = process.version.split('.').shift()?.slice(1) ?? ''
@@ -65,6 +66,9 @@ if (outputFolder === '' || outputFolder === undefined) {
6566

6667
const compiler = new Compiler(specsFolder, outputFolder)
6768

69+
const examplesProcessor = new ExamplesProcessor(specsFolder)
70+
const addExamples = examplesProcessor.addExamples.bind(examplesProcessor)
71+
6872
compiler
6973
.generateModel()
7074
.step(addInfo)
@@ -74,6 +78,7 @@ compiler
7478
.step(validateRestSpec)
7579
.step(addDescription)
7680
.step(validateModel)
81+
.step(addExamples)
7782
.write()
7883
.then(() => {
7984
console.log('Done')

compiler/src/model/build-model.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,18 @@ function compileClassOrInterfaceDeclaration (declaration: ClassDeclaration | Int
383383
if (property.valueOf.kind === 'instance_of' && property.valueOf.type.name === 'Void') {
384384
type.body = { kind: 'no_body' }
385385
} else {
386-
type.body = { kind: 'value', value: property.valueOf }
386+
const tags = parseJsDocTags((member as PropertySignature).getJsDocs())
387+
// TODO: Enable this after adding the missing codegen names.
388+
// assert(
389+
// member as Node,
390+
// tags.codegen_name != null,
391+
// 'You should configure a body @codegen_name'
392+
// )
393+
type.body = {
394+
kind: 'value',
395+
value: property.valueOf,
396+
codegenName: tags.codegen_name
397+
}
387398
}
388399
} else {
389400
type.body = { kind: 'properties', properties: property.properties }

0 commit comments

Comments
 (0)