Skip to content

Commit

Permalink
support server variable in multi-version
Browse files Browse the repository at this point in the history
  • Loading branch information
coliu19 committed Jan 24, 2024
1 parent 9aaffa8 commit 1636a5d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion functions/multiVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,17 @@ function* getAllServerURLs(doc) {

for (let i = 0; i < doc.servers.length; i++) {
item.path = ['servers', i];
item.url = doc.servers[i].url;

let { url } = doc.servers[i];
const vars = url.match(/{([^}]+)}/g);

if (vars) {
for (const v of vars) {
url = url.replace(v, doc.servers[i].variables?.[v.slice(1, -1)]?.default);
}
}

item.url = url;
yield item;
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/resources/multi-versions/positive-v3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ servers:
- url: http://api.example.com/v1
- url: http://api.example3.com/v1
- url: http://api.example2.com/v1/
- url: https://api.example4.com:{port}/{basePath}
variables:
basePath:
default: api/v1
port:
default: '80'
tags:
- name: Sample
paths:
Expand Down

0 comments on commit 1636a5d

Please sign in to comment.