Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
}

Expand Down
27 changes: 20 additions & 7 deletions compiler/src/model/build-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 != null || spec.visibility != null) && (endpoint.availability.stack === undefined && endpoint.availability.serverless === undefined)) {
endpoint.availability = {
stack: {
stability: spec.stability,
visibility: spec.visibility
}
}
}
}
}
}
return model
}

export function compileEndpoints (): Record<string, model.Endpoint> {
// Create endpoints and merge them with
// the recorded mappings if present.
Expand All @@ -72,12 +90,7 @@ export function compileEndpoints (): Record<string, model.Endpoint> {
// 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,
Expand All @@ -97,7 +110,7 @@ export function compileEndpoints (): Record<string, model.Endpoint> {
}

if (typeof spec.feature_flag === 'string') {
map[api].availability.stack.featureFlag = spec.feature_flag
map[api].availability.stack = { featureFlag: spec.feature_flag }
}
}
return map
Expand Down
Loading