fluid-oas
Version:
Build declarative OpenApiv3.* specifications.
32 lines (31 loc) • 841 B
JavaScript
import { SchemaBase } from "../lib/base";
const EnumBase = (SchemaBase);
class _OpenApiEnum extends EnumBase {
_val;
constructor(...val) {
super();
if (val.length == 0) {
throw new Error("Enums cannot be empty.");
}
this._val = val;
}
toJSON() {
const json = super.toJSON();
if (this._val) {
Object.defineProperty(json, "enum", {
value: this._val,
enumerable: true,
});
}
return json;
}
}
/**
* A Special Utility type for defining arbitrary enumerable values.
*
* This is different from the addEnums method on other schemas, as those restrict
* the enumerable types to be contained with the type of Schema.
*/
export const Enum = (...val) => {
return new _OpenApiEnum(...val);
};