mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
OpenAPI CRUD views (#6702)
Dynamically generate views from OpenAPI document to List/CRUD LDAP users and groups in the UI
This commit is contained in:
@@ -1,35 +1,37 @@
|
||||
import DS from 'ember-data';
|
||||
const { attr } = DS;
|
||||
import { assign } from '@ember/polyfills';
|
||||
import { isEmpty } from '@ember/utils';
|
||||
import { camelize, capitalize } from '@ember/string';
|
||||
|
||||
export const expandOpenApiProps = function(props) {
|
||||
let attrs = {};
|
||||
// expand all attributes
|
||||
for (let prop in props) {
|
||||
let details = props[prop];
|
||||
if (details.deprecated === true) {
|
||||
continue;
|
||||
for (const propName in props) {
|
||||
const prop = props[propName];
|
||||
let { description, items, type, format, isId, label } = prop;
|
||||
let { name, value, group, sensitive } = prop['x-vault-displayAttrs'] || {};
|
||||
|
||||
if (type === 'integer') {
|
||||
type = 'number';
|
||||
}
|
||||
if (details.type === 'integer') {
|
||||
details.type = 'number';
|
||||
}
|
||||
let editType = details.type;
|
||||
if (details.format === 'seconds') {
|
||||
let editType = type;
|
||||
|
||||
if (format === 'seconds') {
|
||||
editType = 'ttl';
|
||||
} else if (details.items) {
|
||||
editType = details.items.type + capitalize(details.type);
|
||||
} else if (items) {
|
||||
editType = items.type + capitalize(type);
|
||||
}
|
||||
let attrDefn = {
|
||||
editType: editType,
|
||||
type: details.type,
|
||||
helpText: details.description,
|
||||
sensitive: details['x-vault-displaySensitive'],
|
||||
label: details['x-vault-displayName'],
|
||||
possibleValues: details['enum'],
|
||||
defaultValue:
|
||||
details['x-vault-displayValue'] || (!isEmpty(details['default']) ? details['default'] : null),
|
||||
editType,
|
||||
type: type,
|
||||
helpText: description,
|
||||
sensitive: sensitive,
|
||||
label: name || label,
|
||||
possibleValues: prop['enum'],
|
||||
fieldValue: isId ? 'id' : null,
|
||||
fieldGroup: group || 'default',
|
||||
readOnly: isId,
|
||||
defaultValue: value || null,
|
||||
};
|
||||
// loop to remove empty vals
|
||||
for (let attrProp in attrDefn) {
|
||||
@@ -37,7 +39,7 @@ export const expandOpenApiProps = function(props) {
|
||||
delete attrDefn[attrProp];
|
||||
}
|
||||
}
|
||||
attrs[camelize(prop)] = attrDefn;
|
||||
attrs[camelize(propName)] = attrDefn;
|
||||
}
|
||||
return attrs;
|
||||
};
|
||||
@@ -45,13 +47,15 @@ export const expandOpenApiProps = function(props) {
|
||||
export const combineAttributes = function(oldAttrs, newProps) {
|
||||
let newAttrs = {};
|
||||
let newFields = [];
|
||||
oldAttrs.forEach(function(value, name) {
|
||||
if (newProps[name]) {
|
||||
newAttrs[name] = attr(newProps[name].type, assign({}, newProps[name], value.options));
|
||||
} else {
|
||||
newAttrs[name] = attr(value.type, value.options);
|
||||
}
|
||||
});
|
||||
if (oldAttrs) {
|
||||
oldAttrs.forEach(function(value, name) {
|
||||
if (newProps[name]) {
|
||||
newAttrs[name] = attr(newProps[name].type, assign({}, newProps[name], value.options));
|
||||
} else {
|
||||
newAttrs[name] = attr(value.type, value.options);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (let prop in newProps) {
|
||||
if (newAttrs[prop]) {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user