Befor generating

This commit is contained in:
marys
2026-06-01 13:17:37 +02:00
parent 3383f4bf4a
commit 1aa1b5f625
6756 changed files with 649946 additions and 1 deletions
+46
View File
@@ -0,0 +1,46 @@
const { getMapValueByKey } = require('../models/utils');
/**
* Implements functions to deal with the common Bindings object.
* @mixin
*/
const MixinBindings = {
/**
* @returns {boolean}
*/
hasBindings() {
return !!(this._json.bindings && Object.keys(this._json.bindings).length);
},
/**
* @returns {Object}
*/
bindings() {
return this.hasBindings() ? this._json.bindings : {};
},
/**
* @returns {string[]}
*/
bindingProtocols() {
return Object.keys(this.bindings());
},
/**
* @param {string} name - Name of the binding.
* @returns {boolean}
*/
hasBinding(name) {
return this.hasBindings() && !!this._json.bindings[String(name)];
},
/**
* @param {string} name - Name of the binding.
* @returns {(Object | null)}
*/
binding(name) {
return getMapValueByKey(this._json.bindings, name);
},
};
module.exports = MixinBindings;
@@ -0,0 +1,23 @@
const { getMapValueByKey } = require('../models/utils');
/**
* Implements functions to deal with the description field.
* @mixin
*/
const MixinDescription = {
/**
* @returns {boolean}
*/
hasDescription() {
return !!this._json.description;
},
/**
* @returns {(string | null)}
*/
description() {
return getMapValueByKey(this._json, 'description');
},
};
module.exports = MixinDescription;
@@ -0,0 +1,25 @@
const { getMapValueOfType } = require('../models/utils');
const ExternalDocs = require('../models/external-docs');
/**
* Implements functions to deal with the ExternalDocs object.
* @mixin
*/
const MixinExternalDocs = {
/**
* @returns {boolean}
*/
hasExternalDocs() {
return !!(this._json.externalDocs && Object.keys(this._json.externalDocs).length);
},
/**
* @returns {(ExternalDocs | null)}
*/
externalDocs() {
return getMapValueOfType(this._json, 'externalDocs', ExternalDocs);
},
};
module.exports = MixinExternalDocs;
@@ -0,0 +1,79 @@
/**
* Implements functions to deal with the SpecificationExtensions object.
* @mixin
*/
const MixinSpecificationExtensions = {
/**
* @returns {boolean}
*/
hasExtensions() {
return !!this.extensionKeys().length;
},
/**
* @returns {Object<string, any>}
*/
extensions() {
const result = {};
Object.entries(this._json).forEach(([key, value]) => {
if ((/^x-[\w\d\.\-\_]+$/).test(key)) {
result[String(key)] = value;
}
});
return result;
},
/**
* @returns {string[]}
*/
extensionKeys() {
return Object.keys(this.extensions());
},
/**
* @returns {string[]}
*/
extKeys() {
return this.extensionKeys();
},
/**
* @param {string} key - Extension key.
* @returns {boolean}
*/
hasExtension(key) {
if (!key.startsWith('x-')) {
return false;
}
return !!this._json[String(key)];
},
/**
* @param {string} key - Extension key.
* @returns {any}
*/
extension(key) {
if (!key.startsWith('x-')) {
return null;
}
return this._json[String(key)];
},
/**
* @param {string} key - Extension key.
* @returns {boolean}
*/
hasExt(key) {
return this.hasExtension(key);
},
/**
* @param {string} key - Extension key.
* @returns {any}
*/
ext(key) {
return this.extension(key);
},
};
module.exports = MixinSpecificationExtensions;
+47
View File
@@ -0,0 +1,47 @@
const Tag = require('../models/tag');
/**
* Implements functions to deal with the Tags object.
* @mixin
*/
const MixinTags = {
/**
* @returns {boolean}
*/
hasTags() {
return !!(Array.isArray(this._json.tags) && this._json.tags.length);
},
/**
* @returns {Tag[]}
*/
tags() {
return this.hasTags() ? this._json.tags.map(t => new Tag(t)) : [];
},
/**
* @returns {string[]}
*/
tagNames() {
return this.hasTags() ? this._json.tags.map(t => t.name) : [];
},
/**
* @param {string} name - Name of the tag.
* @returns {boolean}
*/
hasTag(name) {
return this.hasTags() && this._json.tags.some(t => t.name === name);
},
/**
* @param {string} name - Name of the tag.
* @returns {(Tag | null)}
*/
tag(name) {
const tg = this.hasTags() && this._json.tags.find(t => t.name === name);
return tg ? new Tag(tg) : null;
},
};
module.exports = MixinTags;