in compiler/src/steps/validate-model.ts [210:271]
function validateEndpoint (endpoint: model.Endpoint): void {
setRootContext(endpoint.name, 'request')
// Skip validation for internal endpoints
if (privateNamespaces.some(ns => endpoint.name.startsWith(ns))) {
return
}
if (endpoint.request !== null) {
const reqType = getTypeDef(endpoint.request)
if (reqType == null) {
modelError(`Type ${fqn(endpoint.request)} not found`)
} else if (reqType.kind !== 'request') {
modelError(`Type ${fqn(endpoint.request)} is not a request definition`)
} else {
validateTypeDef(reqType)
// Request path properties and url template properties should be the same
const reqProperties = new Set(reqType.path.map(p => p.name))
const urlProperties = new Set<string>()
for (const url of endpoint.urls) {
// Strip trailing slashes from paths
if (url.path !== '/' && url.path.endsWith('/')) {
modelError(`Url path '${url.path}' has a trailing slash`)
url.path = url.path.replace(/\/$/, '')
}
const re = /{([^}]+)}/g
let m
while ((m = re.exec(url.path)) != null) { // eslint-disable-line no-cond-assign
urlProperties.add(m[1])
}
}
for (const urlProp of urlProperties) {
if (!reqProperties.has(urlProp)) {
modelError(`Url path property '${urlProp}' is missing in request definition`)
}
}
for (const reqProp of reqProperties) {
if (!urlProperties.has(reqProp)) {
modelError(`Request path property '${reqProp}' doesn't exist in endpoint URL templates`)
}
}
}
}
setRootContext(endpoint.name, 'response')
if (endpoint.response !== null) {
const respType = getTypeDef(endpoint.response)
if (respType == null) {
modelError(`Type ${fqn(endpoint.response)} not found`)
} else {
validateTypeDef(respType)
}
}
}