Skip to content

Commit d76bc1c

Browse files
add language client examples to YAML files
1 parent 14cbbce commit d76bc1c

File tree

650 files changed

+34820
-737
lines changed

Some content is hidden

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

650 files changed

+34820
-737
lines changed

Makefile

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

4849
clean-dep: ## Clean npm dependencies
4950
@rm -rf compiler/node_modules
@@ -53,6 +54,7 @@ transform-expand-generics: ## Create a new schema with all generics expanded
5354
@npm run transform-expand-generics --prefix compiler
5455

5556
transform-to-openapi: ## Generate the OpenAPI definition from the compiled schema
57+
@make generate-language-examples
5658
@npm run transform-to-openapi -- --schema output/schema/schema.json --flavor stack --output output/openapi/elasticsearch-openapi.json
5759
@npm run transform-to-openapi -- --schema output/schema/schema.json --flavor serverless --output output/openapi/elasticsearch-serverless-openapi.json
5860

@@ -75,6 +77,10 @@ overlay-docs: ## Apply overlays to OpenAPI documents
7577
rm output/openapi/elasticsearch-serverless-openapi.tmp*.json
7678
rm output/openapi/elasticsearch-openapi.tmp*.json
7779

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

compiler/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"lint:fix": "ts-standard --fix src",
99
"format:check": "prettier --config .prettierrc.json --loglevel warn --check ../specification/",
1010
"format:fix": "prettier --config .prettierrc.json --loglevel warn --write ../specification/",
11+
"format:fix-examples": "prettier --config .prettierrc.json --loglevel warn --write ../specification/**/*.yaml",
1112
"generate-schema": "ts-node src/index.ts",
1213
"transform-expand-generics": "ts-node src/transform/expand-generics.ts",
1314
"transform-to-openapi": "ts-node src/transform/schema-to-openapi.ts",

specification/_global/bulk/examples/request/BulkRequestExample1.yaml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,174 @@ value: '{ "index" : { "_index" : "test", "_id" : "1" } }
1515
{ "update" : {"_id" : "1", "_index" : "test"} }
1616
1717
{ "doc" : {"field2" : "value2"} }'
18+
alternatives:
19+
- language: Python
20+
code: |-
21+
resp = client.bulk(
22+
operations=[
23+
{
24+
"index": {
25+
"_index": "test",
26+
"_id": "1"
27+
}
28+
},
29+
{
30+
"field1": "value1"
31+
},
32+
{
33+
"delete": {
34+
"_index": "test",
35+
"_id": "2"
36+
}
37+
},
38+
{
39+
"create": {
40+
"_index": "test",
41+
"_id": "3"
42+
}
43+
},
44+
{
45+
"field1": "value3"
46+
},
47+
{
48+
"update": {
49+
"_id": "1",
50+
"_index": "test"
51+
}
52+
},
53+
{
54+
"doc": {
55+
"field2": "value2"
56+
}
57+
}
58+
],
59+
)
60+
- language: JavaScript
61+
code: |-
62+
const response = await client.bulk({
63+
operations: [
64+
{
65+
index: {
66+
_index: "test",
67+
_id: "1",
68+
},
69+
},
70+
{
71+
field1: "value1",
72+
},
73+
{
74+
delete: {
75+
_index: "test",
76+
_id: "2",
77+
},
78+
},
79+
{
80+
create: {
81+
_index: "test",
82+
_id: "3",
83+
},
84+
},
85+
{
86+
field1: "value3",
87+
},
88+
{
89+
update: {
90+
_id: "1",
91+
_index: "test",
92+
},
93+
},
94+
{
95+
doc: {
96+
field2: "value2",
97+
},
98+
},
99+
],
100+
});
101+
- language: Ruby
102+
code: |-
103+
response = client.bulk(
104+
body: [
105+
{
106+
"index": {
107+
"_index": "test",
108+
"_id": "1"
109+
}
110+
},
111+
{
112+
"field1": "value1"
113+
},
114+
{
115+
"delete": {
116+
"_index": "test",
117+
"_id": "2"
118+
}
119+
},
120+
{
121+
"create": {
122+
"_index": "test",
123+
"_id": "3"
124+
}
125+
},
126+
{
127+
"field1": "value3"
128+
},
129+
{
130+
"update": {
131+
"_id": "1",
132+
"_index": "test"
133+
}
134+
},
135+
{
136+
"doc": {
137+
"field2": "value2"
138+
}
139+
}
140+
]
141+
)
142+
- language: PHP
143+
code: |-
144+
$resp = $client->bulk([
145+
"body" => array(
146+
[
147+
"index" => [
148+
"_index" => "test",
149+
"_id" => "1",
150+
],
151+
],
152+
[
153+
"field1" => "value1",
154+
],
155+
[
156+
"delete" => [
157+
"_index" => "test",
158+
"_id" => "2",
159+
],
160+
],
161+
[
162+
"create" => [
163+
"_index" => "test",
164+
"_id" => "3",
165+
],
166+
],
167+
[
168+
"field1" => "value3",
169+
],
170+
[
171+
"update" => [
172+
"_id" => "1",
173+
"_index" => "test",
174+
],
175+
],
176+
[
177+
"doc" => [
178+
"field2" => "value2",
179+
],
180+
],
181+
),
182+
]);
183+
- language: curl
184+
code:
185+
"curl -X POST -H \"Authorization: ApiKey $ELASTIC_API_KEY\" -H \"Content-Type: application/json\" -d
186+
'[{\"index\":{\"_index\":\"test\",\"_id\":\"1\"}},{\"field1\":\"value1\"},{\"delete\":{\"_index\":\"test\",\"_id\":\"2\"}},{\
187+
\"create\":{\"_index\":\"test\",\"_id\":\"3\"}},{\"field1\":\"value3\"},{\"update\":{\"_id\":\"1\",\"_index\":\"test\"}},{\"d\
188+
oc\":{\"field2\":\"value2\"}}]' \"http://localhost:9200/_bulk\""

0 commit comments

Comments
 (0)