ern-api-gen
Version:
Electrode Native API generator
56 lines • 1.76 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const RefFormat_1 = __importDefault(require("./RefFormat"));
/**
* A class the encapsulates logic that is common to RefModel, RefParameter, and RefProperty.
*/
class GenericRef {
constructor(type, ref) {
if (type != null && typeof ref === 'string') {
this.format = GenericRef.computeRefFormat(ref);
this.type = type;
if (this.format === RefFormat_1.default.INTERNAL && !ref.startsWith('#/')) {
this.ref = type.getInternalPrefix() + ref;
}
else {
this.ref = ref;
}
this.simpleRef = GenericRef.computeSimpleRef(this.ref, this.format, type);
}
}
getFormat() {
return this.format;
}
getType() {
return this.type;
}
getRef() {
return this.ref;
}
getSimpleRef() {
return this.simpleRef;
}
}
GenericRef.computeSimpleRef = (ref, format, type) => {
if (format === RefFormat_1.default.INTERNAL) {
return ref.substring(type.getInternalPrefix().length);
}
return ref;
};
GenericRef.computeRefFormat = ref => {
if (ref.startsWith('http:') || ref.startsWith('https:')) {
return RefFormat_1.default.URL;
}
else if (ref.startsWith('#/')) {
return RefFormat_1.default.INTERNAL;
}
else if (ref.startsWith('.') || ref.startsWith('/')) {
return RefFormat_1.default.RELATIVE;
}
return RefFormat_1.default.INTERNAL;
};
exports.default = GenericRef;
//# sourceMappingURL=GenericRef.js.map