diff --git a/ui/app/utils/openapi-to-attrs.js b/ui/app/utils/openapi-to-attrs.js index e31b3f31bc..abe1663430 100644 --- a/ui/app/utils/openapi-to-attrs.js +++ b/ui/app/utils/openapi-to-attrs.js @@ -2,6 +2,7 @@ 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 = {}; @@ -18,25 +19,25 @@ export const expandOpenApiProps = function(props) { if (details.format === 'seconds') { editType = 'ttl'; } else if (details.items) { - editType = details.items.type + details.type.capitalize(); + editType = details.items.type + capitalize(details.type); } - attrs[prop.camelize()] = { + 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), }; - if (details['x-vault-displayName']) { - attrs[prop.camelize()].label = details['x-vault-displayName']; - } - if (details['enum']) { - attrs[prop.camelize()].possibleValues = details['enum']; - } - if (details['x-vault-displayValue']) { - attrs[prop.camelize()].defaultValue = details['x-vault-displayValue']; - } else { - if (!isEmpty(details['default'])) { - attrs[prop.camelize()].defaultValue = details['default']; + // loop to remove empty vals + for (let attrProp in attrDefn) { + if (attrDefn[attrProp] == null) { + delete attrDefn[attrProp]; } } + attrs[camelize(prop)] = attrDefn; } return attrs; }; diff --git a/ui/tests/unit/utils/openapi-to-attrs-test.js b/ui/tests/unit/utils/openapi-to-attrs-test.js index 8b9464a22f..2f11256ede 100644 --- a/ui/tests/unit/utils/openapi-to-attrs-test.js +++ b/ui/tests/unit/utils/openapi-to-attrs-test.js @@ -8,6 +8,7 @@ module('Unit | Util | OpenAPI Data Utilities', function() { ttl: { type: 'string', format: 'seconds', + description: 'this is a TTL!', 'x-vault-displayName': 'TTL', }, 'awesome-people': { @@ -30,9 +31,15 @@ module('Unit | Util | OpenAPI Data Utilities', function() { default: 30, type: 'integer', }, + 'super-secret': { + type: 'string', + 'x-vault-displaySensitive': true, + description: 'A really secret thing', + }, }; const EXPANDED_PROPS = { ttl: { + helpText: 'this is a TTL!', editType: 'ttl', type: 'string', label: 'TTL', @@ -57,6 +64,13 @@ module('Unit | Util | OpenAPI Data Utilities', function() { type: 'number', defaultValue: 30, }, + + superSecret: { + type: 'string', + editType: 'string', + sensitive: true, + helpText: 'A really secret thing', + }, }; const EXISTING_MODEL_ATTRS = [ @@ -93,6 +107,7 @@ module('Unit | Util | OpenAPI Data Utilities', function() { editType: 'ttl', type: 'string', label: 'TTL', + helpText: 'this is a TTL!', }), awesomePeople: attr({ label: 'People Who Are Awesome', @@ -105,6 +120,12 @@ module('Unit | Util | OpenAPI Data Utilities', function() { editType: 'string', possibleValues: ['vanilla', 'chocolate', 'strawberry'], }), + superSecret: attr('string', { + type: 'string', + editType: 'string', + sensitive: true, + description: 'A really secret thing', + }), }; const NEW_FIELDS = ['one', 'two', 'three'];