elements icon indicating copy to clipboard operation
elements copied to clipboard

Are there options for not defaulting to semver

Open dillon-glovebox opened this issue 6 months ago • 2 comments

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.

dillon-glovebox avatar Jul 01 '25 17:07 dillon-glovebox

+1 - it seems very prescriptive to force the use of a semver versioning format for this. We are also running into this inherited limitation with huma because we use an automated commit-hash versioning system.

gregtzar-glovebox avatar Jul 03 '25 21:07 gregtzar-glovebox

Bump, I have a PR tested and ready to go for this.

dillon-glovebox avatar Jul 23 '25 17:07 dillon-glovebox