-
Couldn't load subscription status.
- Fork 251
Open
Description
Currently using Stoplight as a part of Huma. I've run into a nuance where Elements defaults the API Version into a formatted semantic version string which is obviously a common use-case. However, from what I can find there doesn't seem to be an alternative solution for versions that use a commit-hash or anything other than semantic versioning.
I believe this is the snippet that performs the formatting here:
const enhanceVersionString = (version: string): string => {
if (version[0] === 'v') return version;
return `v${version}`;
};If there's not a dedicated solution would it be a value add to RegEx check for a compatible semver and only format it IF there is not match?
// Matches semver + inclusion of initial 'v'
const semverReg = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
const enhanceVersionString = (version: string): string => {
if (!semverReg.test(version)) {
return version;
}
return version.startsWith('v') ? version : `v${version}`;
};RegEx Source: From the Semver page directly. Included some testing samples here.
Metadata
Metadata
Assignees
Labels
No labels