Skip to content

Commit

Permalink
check route and openApi are consistent on service load
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Jul 10, 2023
1 parent a5cc620 commit 5be537a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/base-service/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@ class BaseService {
this.examples.forEach((example, index) =>
validateExample(example, index, this)
)

// ensure openApi spec matches route
if (this.openApi) {
const preparedRoute = prepareRoute(this.route)
for (const [key, value] of Object.entries(this.openApi)) {
let example = key
for (const param of value.get.parameters) {
example = example.replace(`{${param.name}}`, param.example)
}
if (!example.match(preparedRoute.regex)) {
throw new Error(
`Inconsistent Open Api spec and Route found for service ${this.name}`
)
}
}
}
}

static getDefinition() {
Expand Down

0 comments on commit 5be537a

Please sign in to comment.