Skip to content

Commit c4a813a

Browse files
committed
feat: add support for openapi version bumping (almost identical to yaml-updater)
1 parent 9d1b2e0 commit c4a813a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/updaters/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const updatersByType = {
77
gradle: require('./types/gradle'),
88
csproj: require('./types/csproj'),
99
yaml: require('./types/yaml'),
10+
openapi: require('./types/openapi'),
1011
};
1112
const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt'];
1213

@@ -37,6 +38,9 @@ function getUpdaterByFilename(filename) {
3738
if (/\.ya?ml$/.test(filename)) {
3839
return getUpdaterByType('yaml');
3940
}
41+
if (/openapi.yaml/.test(filename)) {
42+
return getUpdaterByType('openapi');
43+
}
4044
throw Error(
4145
`Unsupported file (${filename}) provided for bumping.\n Please specify the updater \`type\` or use a custom \`updater\`.`,
4246
);

lib/updaters/types/openapi.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const yaml = require('yaml');
2+
const detectNewline = require('detect-newline');
3+
4+
module.exports.readVersion = function (contents) {
5+
return yaml.parse(contents).info.version;
6+
};
7+
8+
module.exports.writeVersion = function (contents, version) {
9+
const newline = detectNewline(contents);
10+
const document = yaml.parseDocument(contents);
11+
12+
document.get('info').set('version', version);
13+
14+
return document.toString().replace(/\r?\n/g, newline);
15+
};

0 commit comments

Comments
 (0)