From 2c1441ad9a4103ccdd4132b547770e078b9bd0c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Saint-F=C3=A9lix?= Date: Mon, 6 Oct 2025 20:30:33 +0200 Subject: [PATCH 1/2] Compiler: sync endpoints json-spec availability only if typescript has none. --- compiler/src/compiler.ts | 7 ++++++- compiler/src/model/build-model.ts | 27 ++++++++++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/compiler/src/compiler.ts b/compiler/src/compiler.ts index 6eeed8ef51..e3ff58f39a 100644 --- a/compiler/src/compiler.ts +++ b/compiler/src/compiler.ts @@ -21,7 +21,11 @@ import { writeFile, mkdir } from 'fs/promises' import { join } from 'path' import stringify from 'safe-stable-stringify' import { Model } from './model/metamodel' -import { compileEndpoints, compileSpecification } from './model/build-model' +import { + compileEndpoints, + compileSpecification, + reAddAvailability +} from './model/build-model' import buildJsonSpec, { JsonSpec } from './model/json-spec' import { ValidationErrors } from './validation-errors' @@ -54,6 +58,7 @@ export default class Compiler { this.jsonSpec = buildJsonSpec() const endpoints = compileEndpoints() this.model = compileSpecification(endpoints, this.specsFolder, this.outputFolder) + this.model = reAddAvailability(this.model) // resync availability information based on json spec if typescript has none. return this } diff --git a/compiler/src/model/build-model.ts b/compiler/src/model/build-model.ts index d320212a14..88dd919544 100644 --- a/compiler/src/model/build-model.ts +++ b/compiler/src/model/build-model.ts @@ -58,6 +58,24 @@ import { const jsonSpec = buildJsonSpec() +export function reAddAvailability (model: model.Model): model.Model { + for (const [api, spec] of jsonSpec.entries()) { + for (const endpoint of model.endpoints) { + if (endpoint.name === api) { + if ((spec.stability || spec.visibility) && (endpoint.availability.stack === undefined && endpoint.availability.serverless === undefined)) { + endpoint.availability = { + stack: { + stability: spec.stability, + visibility: spec.visibility + } + } + } + } + } + } + return model +} + export function compileEndpoints (): Record { // Create endpoints and merge them with // the recorded mappings if present. @@ -72,12 +90,7 @@ export function compileEndpoints (): Record { // Setting these values by default should be removed // when we no longer use rest-api-spec stubs as the // source of truth for stability/visibility. - availability: { - stack: { - stability: spec.stability, - visibility: spec.visibility - } - }, + availability: {}, request: null, requestBodyRequired: Boolean(spec.body?.required), response: null, @@ -90,7 +103,7 @@ export function compileEndpoints (): Record { }) } if (typeof spec.feature_flag === 'string') { - map[api].availability.stack.featureFlag = spec.feature_flag + map[api].availability.stack = {featureFlag: spec.feature_flag} } } return map From 979266acb3ea81ecc7df74b92f21af286f0534b7 Mon Sep 17 00:00:00 2001 From: Josh Mock Date: Mon, 6 Oct 2025 13:47:32 -0500 Subject: [PATCH 2/2] linter fixes --- compiler/src/model/build-model.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/model/build-model.ts b/compiler/src/model/build-model.ts index 88dd919544..e4124dd8d3 100644 --- a/compiler/src/model/build-model.ts +++ b/compiler/src/model/build-model.ts @@ -62,7 +62,7 @@ export function reAddAvailability (model: model.Model): model.Model { for (const [api, spec] of jsonSpec.entries()) { for (const endpoint of model.endpoints) { if (endpoint.name === api) { - if ((spec.stability || spec.visibility) && (endpoint.availability.stack === undefined && endpoint.availability.serverless === undefined)) { + if ((spec.stability != null || spec.visibility != null) && (endpoint.availability.stack === undefined && endpoint.availability.serverless === undefined)) { endpoint.availability = { stack: { stability: spec.stability, @@ -103,7 +103,7 @@ export function compileEndpoints (): Record { }) } if (typeof spec.feature_flag === 'string') { - map[api].availability.stack = {featureFlag: spec.feature_flag} + map[api].availability.stack = { featureFlag: spec.feature_flag } } } return map