Skip to content

Commit eca6d46

Browse files
Compiler: late sync endpoints availability from json-spec (#5432)
* Compiler: sync endpoints json-spec availability only if typescript has none. * linter fixes --------- Co-authored-by: Josh Mock <[email protected]>
1 parent 6ff7908 commit eca6d46

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
@@ -58,6 +58,24 @@ import {
5858

5959
const jsonSpec = buildJsonSpec()
6060

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

99112
if (typeof spec.feature_flag === 'string') {
100-
map[api].availability.stack.featureFlag = spec.feature_flag
113+
map[api].availability.stack = { featureFlag: spec.feature_flag }
101114
}
102115
}
103116
return map

0 commit comments

Comments
 (0)