Skip to content

Commit 470f4f6

Browse files
committed
Merge branch 'main' into mark-role-apis-serverless-available
2 parents c25af2c + afcfe48 commit 470f4f6

File tree

186 files changed

+3663
-3214
lines changed

Some content is hidden

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

186 files changed

+3663
-3214
lines changed

.github/CODEOWNERS

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
/specification/ml/** @elastic/ml-core @elastic/ml-ui
33

44
# Specification tooling owners
5-
/.github/ @elastic/clients-team
6-
/compiler/ @elastic/clients-team
7-
/compiler-rs/ @elastic/clients-team
8-
/typescript-generator/ @elastic/clients-team
9-
/specification/_json_spec/ @elastic/clients-team
10-
/specification/_spec_utils/ @elastic/clients-team
5+
/.github/ @elastic/devtools-team
6+
/compiler/ @elastic/devtools-team
7+
/compiler-rs/ @elastic/devtools-team
8+
/typescript-generator/ @elastic/devtools-team
9+
/specification/_json_spec/ @elastic/devtools-team
10+
/specification/_spec_utils/ @elastic/devtools-team

.github/download-artifacts/index.js

Lines changed: 22 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,21 @@ const downloadedSpec = join(esFolder, 'rest-api-spec', 'api')
4040
const specFolder = join(__dirname, '..', '..', 'specification', '_json_spec')
4141

4242
async function downloadArtifacts (opts) {
43-
if (typeof opts.version !== 'string' && typeof opts.branch !== 'string') {
44-
throw new Error('Missing version or branch')
43+
if (typeof opts.branch !== 'string') {
44+
throw new Error('Missing branch')
4545
}
4646

47-
core.info('Checking out spec and test')
47+
core.info('Resolving artifact URL')
4848

49-
core.info('Resolving version')
5049
let resolved
5150
try {
52-
resolved = await resolve(opts.version || fromBranch(opts.branch), opts.hash)
51+
resolved = await resolve(opts.branch)
5352
} catch (err) {
5453
core.error(err.message)
5554
process.exit(1)
5655
}
5756

58-
opts.version = resolved.version
59-
core.info(`Resolved version ${opts.version}`)
57+
core.info(`Resolved artifact URL for ${resolved.commit_url}`)
6058

6159
core.info('Cleanup')
6260
await rm(esFolder)
@@ -96,74 +94,29 @@ async function downloadArtifacts (opts) {
9694
core.info('Done')
9795
}
9896

99-
async function resolve (version, hash) {
100-
if (version === 'latest') {
101-
const response = await fetch('https://artifacts-api.elastic.co/v1/versions')
102-
if (!response.ok) {
103-
throw new Error(`unexpected response ${response.statusText}`)
104-
}
105-
const { versions } = await response.json()
106-
version = versions.pop()
97+
async function resolve (branch) {
98+
if (branch == 'main') {
99+
branch = 'master'
107100
}
108-
109-
core.info(`Resolving version ${version}`)
110-
const response = await fetch(`https://artifacts-api.elastic.co/v1/versions/${version}`)
101+
const url = `https://artifacts-snapshot.elastic.co/elasticsearch/latest/${branch}.json`
102+
const response = await fetch(url)
111103
if (!response.ok) {
112-
throw new Error(`unexpected response ${response.statusText}`)
104+
throw new Error(`Unexpected response. Invalid version? ${url}: ${response.statusText}`)
113105
}
114-
115106
const data = await response.json()
116-
const esBuilds = data.version.builds
117-
.filter(build => build.projects.elasticsearch != null)
118-
.map(build => {
119-
return {
120-
projects: build.projects.elasticsearch,
121-
buildId: build.build_id,
122-
date: build.start_time,
123-
version: build.version
124-
}
125-
})
126-
.sort((a, b) => {
127-
const dA = new Date(a.date)
128-
const dB = new Date(b.date)
129-
if (dA > dB) return -1
130-
if (dA < dB) return 1
131-
return 0
132-
})
133-
134-
if (hash != null) {
135-
const build = esBuilds.find(build => build.projects.commit_hash === hash)
136-
if (!build) {
137-
throw new Error(`Can't find any build with hash '${hash}'`)
138-
}
139-
const zipKey = Object.keys(build.projects.packages).find(key => key.startsWith('rest-resources-zip-') && key.endsWith('.zip'))
140-
return {
141-
url: build.projects.packages[zipKey].url,
142-
id: build.buildId,
143-
hash: build.projects.commit_hash,
144-
version: build.version
145-
}
146-
}
147107

148-
const lastBuild = esBuilds[0]
149-
const zipKey = Object.keys(lastBuild.projects.packages).find(key => key.startsWith('rest-resources-zip-') && key.endsWith('.zip'))
150-
return {
151-
url: lastBuild.projects.packages[zipKey].url,
152-
id: lastBuild.buildId,
153-
hash: lastBuild.projects.commit_hash,
154-
version: lastBuild.version
108+
let manifest_url = data.manifest_url
109+
const manifestResponse = await fetch(manifest_url)
110+
if (!manifestResponse.ok) {
111+
throw new Error(`Unexpected manifestResponse. ${manifest_url}: ${manifestResponse.statusText}`)
155112
}
156-
}
113+
const manifestData = await manifestResponse.json()
114+
const elasticsearch = manifestData.projects.elasticsearch
115+
const restResourceName = `rest-resources-zip-${manifestData.version}.zip`
157116

158-
function fromBranch (branch) {
159-
if (branch === 'main') {
160-
return 'latest'
161-
} else if (branch === '7.x') {
162-
return '7.x-SNAPSHOT'
163-
} else if ((branch.startsWith('7.') || branch.startsWith('8.')) && !isNaN(Number(branch.split('.')[1]))) {
164-
return `${branch}-SNAPSHOT`
165-
} else {
166-
throw new Error(`Cannot derive version from branch '${branch}'`)
117+
return {
118+
url: elasticsearch.packages[restResourceName].url,
119+
commit_url: elasticsearch.commit_url,
167120
}
168121
}
169122

@@ -172,7 +125,7 @@ async function main (options) {
172125
}
173126

174127
const options = minimist(process.argv.slice(2), {
175-
string: ['id', 'version', 'hash', 'branch']
128+
string: ['branch']
176129
})
177130
main(options).catch(t => {
178131
core.error(t)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
3838
- name: Generate output
3939
run: |
40-
SKIP_VERSION_UPDATE=true make contrib
40+
make contrib
4141
4242
- name: Debug git status
4343
run: |

.spectral.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ rules:
1717
operation-operationId: warn
1818
operation-operationId-unique: warn
1919
operation-operationId-valid-in-url: warn
20-
operation-tag-defined: warn
20+
operation-tag-defined: error
2121
operation-tags: warn
2222
# Responses
2323
operation-success-response: warn
@@ -26,7 +26,7 @@ rules:
2626
oas2-schema: warn
2727
# Tags
2828
openapi-tags: warn
29-
openapi-tags-alphabetical: info
29+
openapi-tags-alphabetical: false
3030
# Turn off some built-in rules
3131
operation-description: false
3232
operation-singular-tag: false

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ overlay-docs: ## Apply overlays to OpenAPI documents
6969
rm output/openapi/elasticsearch-serverless-openapi.tmp*.json
7070
rm output/openapi/elasticsearch-openapi.tmp*.json
7171

72-
lint-docs: ## Lint the OpenAPI documents
73-
@npx @stoplight/spectral-cli lint output/openapi/*.json --ruleset .spectral.yaml
72+
lint-docs: ## Lint the OpenAPI documents after overlays
73+
@npx @stoplight/spectral-cli lint output/openapi/elasticsearch-*.examples.json --ruleset .spectral.yaml
7474

75-
lint-docs-errs: ## Lint the OpenAPI documents and return only errors
76-
@npx @stoplight/spectral-cli lint output/openapi/*.json --ruleset .spectral.yaml -D
75+
lint-docs-errs: ## Lint the OpenAPI documents after overlays and return only errors
76+
@npx @stoplight/spectral-cli lint output/openapi/elasticsearch-*.examples.json --ruleset .spectral.yaml -D
7777

78-
lint-docs-serverless: ## Lint only the serverless OpenAPI document
79-
@npx @stoplight/spectral-cli lint output/openapi/elasticsearch-serverless-openapi.json --ruleset .spectral.yaml
78+
lint-docs-serverless: ## Lint only the serverless OpenAPI document after overlays
79+
@npx @stoplight/spectral-cli lint output/openapi/elasticsearch-serverless-openapi.examples.json --ruleset .spectral.yaml
8080

8181
help: ## Display help
8282
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

api-design-guidelines/naming.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ Care should be given to ensure that:
100100
- All member APIs of a given namespace are logically related and form a coherent set.
101101
- Related functionality is not distributed across multiple arbitrary namespaces
102102

103+
NOTE: The endpoint namespaces are used to generate tags in the OpenAPI documents. The tags are ultimately used to group the endpoints in the API documentation. To override the default tag, use `@doc_tag`.
104+
103105
### Use the global namespace sparingly
104106

105107
The top-level global namespace should be treated with particular care. It is traditionally reserved for search and document endpoints only. A case should be made and a broader discussion carried out before new endpoints unrelated to these functions are added to the global namespace.

compiler-rs/clients_schema/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,9 @@ pub struct Endpoint {
815815
#[serde(skip_serializing_if = "Option::is_none")]
816816
pub availability: Option<Availabilities>,
817817

818+
#[serde(skip_serializing_if = "Option::is_none")]
819+
pub doc_tag: Option<String>,
820+
818821
/// If missing, there is not yet a request definition for this endpoint.
819822
#[serde(skip_serializing_if = "Option::is_none")]
820823
pub request: Option<TypeName>,

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/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,20 @@ pub fn availability_as_extensions(availabilities: &Option<Availabilities>) -> In
155155
if let Some(avails) = availabilities {
156156
// We may have several availabilities, but since generally exists only on stateful (stack)
157157
for (_, availability) in avails {
158-
if let Some(since) = &availability.since {
159-
result.insert("x-available-since".to_string(), serde_json::Value::String(since.clone()));
160-
}
161158
if let Some(stability) = &availability.stability {
162159
match stability {
163160
Stability::Beta => {
164161
result.insert("x-beta".to_string(), serde_json::Value::Bool(true));
165162
}
166163
Stability::Experimental => {
167-
result.insert("x-technical-preview".to_string(), serde_json::Value::Bool(true));
164+
result.insert("x-state".to_string(), serde_json::Value::String("Technical preview".to_string()));
165+
}
166+
Stability::Stable => {
167+
if let Some(since) = &availability.since {
168+
let stable_since = "Added in ".to_string() + since;
169+
result.insert("x-state".to_string(), serde_json::Value::String(stable_since));
170+
}
168171
}
169-
_ => {}
170172
}
171173
}
172174
}

compiler-rs/clients_schema_to_openapi/src/paths.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ pub fn add_endpoint(
196196

197197
// Create the operation, it will be repeated if we have several methods
198198
let operation = openapiv3::Operation {
199-
tags: vec![namespace.to_string()],
199+
tags: if let Some(doc_tag) = &endpoint.doc_tag {
200+
vec![doc_tag.clone()]
201+
} else {
202+
vec![namespace.to_string()]
203+
},
200204
summary: sum_desc.summary,
201205
description: sum_desc.description,
202206
// external_docs: tac.convert_external_docs(endpoint),

0 commit comments

Comments
 (0)