Skip to content

Commit 226befa

Browse files
github-actions[bot]AnaethelionJoshMock
authored
Compiler: late sync endpoints availability from json-spec (#5432) (#5837)
* Compiler: sync endpoints json-spec availability only if typescript has none. * linter fixes --------- (cherry picked from commit eca6d46) Co-authored-by: Laurent Saint-Félix <laurent.saintfelix@elastic.co> Co-authored-by: Josh Mock <joshua.mock@elastic.co>
1 parent 45a2b8e commit 226befa

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

compiler/src/compiler.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ import { writeFile, mkdir } from 'fs/promises'
2121
import { join } from 'path'
2222
import stringify from 'safe-stable-stringify'
2323
import { Model } from './model/metamodel'
24-
import { compileEndpoints, compileSpecification } from './model/build-model'
24+
import {
25+
compileEndpoints,
26+
compileSpecification,
27+
reAddAvailability
28+
} from './model/build-model'
2529
import buildJsonSpec, { JsonSpec } from './model/json-spec'
2630
import { ValidationErrors } from './validation-errors'
2731

@@ -54,6 +58,7 @@ export default class Compiler {
5458
this.jsonSpec = buildJsonSpec()
5559
const endpoints = compileEndpoints()
5660
this.model = compileSpecification(endpoints, this.specsFolder, this.outputFolder)
61+
this.model = reAddAvailability(this.model) // resync availability information based on json spec if typescript has none.
5762
return this
5863
}
5964

compiler/src/model/build-model.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ import {
5959

6060
const jsonSpec = buildJsonSpec()
6161

62+
export function reAddAvailability (model: model.Model): model.Model {
63+
for (const [api, spec] of jsonSpec.entries()) {
64+
for (const endpoint of model.endpoints) {
65+
if (endpoint.name === api) {
66+
if ((spec.stability != null || spec.visibility != null) && (endpoint.availability.stack === undefined && endpoint.availability.serverless === undefined)) {
67+
endpoint.availability = {
68+
stack: {
69+
stability: spec.stability,
70+
visibility: spec.visibility
71+
}
72+
}
73+
}
74+
}
75+
}
76+
}
77+
return model
78+
}
79+
6280
export function compileEndpoints (): Record<string, model.Endpoint> {
6381
// Create endpoints and merge them with
6482
// the recorded mappings if present.
@@ -73,12 +91,7 @@ export function compileEndpoints (): Record<string, model.Endpoint> {
7391
// Setting these values by default should be removed
7492
// when we no longer use rest-api-spec stubs as the
7593
// source of truth for stability/visibility.
76-
availability: {
77-
stack: {
78-
stability: spec.stability,
79-
visibility: spec.visibility
80-
}
81-
},
94+
availability: {},
8295
request: null,
8396
requestBodyRequired: Boolean(spec.body?.required),
8497
response: null,
@@ -91,7 +104,7 @@ export function compileEndpoints (): Record<string, model.Endpoint> {
91104
})
92105
}
93106
if (typeof spec.feature_flag === 'string') {
94-
map[api].availability.stack.featureFlag = spec.feature_flag
107+
map[api].availability.stack = { featureFlag: spec.feature_flag }
95108
}
96109
}
97110
return map

0 commit comments

Comments
 (0)