diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index faf5a55..9dad932 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -13,13 +13,17 @@ on: - main jobs: test_linux: - name: Ubuntu - runs-on: ubuntu-latest + name: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-20.04] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 14 + node-version: 16 - uses: microsoft/playwright-github-action@v1 - uses: actions/cache@v1 with: @@ -38,7 +42,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 14 + node-version: 16 - uses: microsoft/playwright-github-action@v1 - uses: actions/cache@v1 with: @@ -53,7 +57,7 @@ jobs: tag: name: "Publishing release" if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' - needs: + needs: - test_linux - test_win runs-on: ubuntu-latest @@ -64,7 +68,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-node@v2 with: - node-version: '14.x' + node-version: '16.x' registry-url: 'https://registry.npmjs.org' - uses: actions/cache@v1 with: diff --git a/package-lock.json b/package-lock.json index 33101ed..f42b05b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@api-components/api-forms", - "version": "0.2.6", + "version": "0.2.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2fcfa53..1b202b2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@api-components/api-forms", "description": "A library containing helper classes to compute API data from the AMF web API model.", - "version": "0.2.6", + "version": "0.2.7", "license": "Apache-2.0", "main": "index.js", "module": "index.js", diff --git a/src/ApiViewModel.js b/src/ApiViewModel.js index c8cbae4..051b003 100644 --- a/src/ApiViewModel.js +++ b/src/ApiViewModel.js @@ -128,7 +128,7 @@ export class ApiViewModel extends AmfHelperMixin(Object) { /** * @param {ConstructorOptions=} [opts={}] */ - constructor(opts={}) { + constructor(opts = {}) { super(); /** * An array of properties for which view model is to be generated. @@ -220,7 +220,7 @@ export class ApiViewModel extends AmfHelperMixin(Object) { result[result.length] = data; } } else if (this._hasType(items, this.ns.aml.vocabularies.shapes.UnionShape)) { - result = this. _modelForUnion(items); + result = this._modelForUnion(items); } return result; } @@ -338,6 +338,9 @@ export class ApiViewModel extends AmfHelperMixin(Object) { if (!this.noDocs) { schemaItem.description = this._computeDescription(amfItem); } + if (schemaItem.isBool) { + result.value = schemaItem.defaultValue + } const valueDelimiter = this._computeValueDelimiter(binding); const decodeValues = this._computeDecodeValues(binding); const processOptions = { @@ -453,7 +456,7 @@ export class ApiViewModel extends AmfHelperMixin(Object) { * @param {ProcessOptions=} processOptions * @return {AmfFormItem[]} View model for items. */ - modelForRawObject(model, processOptions={}) { + modelForRawObject(model, processOptions = {}) { const result = []; const keys = Object.keys(model); const dataKey = this._getAmfKey(this.ns.raml.vocabularies.data.toString()); @@ -625,8 +628,8 @@ export class ApiViewModel extends AmfHelperMixin(Object) { } if (item.schema.required && typeof item.schema.defaultValue !== 'undefined') { item.value = item.schema.isArray ? - this._parseArrayExample(/** @type {string} */ (item.schema.defaultValue), processOptions) : - this._exampleAsValue(/** @type {string} */ (item.schema.defaultValue), processOptions); + this._parseArrayExample(/** @type {string} */(item.schema.defaultValue), processOptions) : + this._exampleAsValue(/** @type {string} */(item.schema.defaultValue), processOptions); } if (typeof item.value === 'undefined' && item.schema.required) { const { examples } = item.schema; @@ -1181,10 +1184,10 @@ export class ApiViewModel extends AmfHelperMixin(Object) { _computeInputType(type) { if (type && NUMBER_INPUT_TYPES.indexOf(type) !== -1) { return 'number'; - } + } if (type === 'boolean') { return 'boolean'; - } + } if (type === 'date-only' || type === 'date') { return 'date'; } /* else if (type === 'time-only' || type === 'time') { @@ -1268,7 +1271,7 @@ export class ApiViewModel extends AmfHelperMixin(Object) { * @param {string=} binding * @return {AmfFormItem} Generated basic view model. */ - buildProperty(defaults={ + buildProperty(defaults = { name: undefined, value: undefined, enabled: true, @@ -1367,7 +1370,7 @@ export class ApiViewModel extends AmfHelperMixin(Object) { return false; } for (let i = 0, len = values.length; i < len; i++) { - const id = this._ensureAmfPrefix(/** @type string */ (this._getValue(values[i], '@id'))); + const id = this._ensureAmfPrefix(/** @type string */(this._getValue(values[i], '@id'))); const node = shape[id]; const extensionNameKey = this._getAmfKey(this.ns.aml.vocabularies.core.extensionName); if (this._getValue(node, extensionNameKey) === 'no-auto-encoding') { @@ -1378,8 +1381,8 @@ export class ApiViewModel extends AmfHelperMixin(Object) { } /** - * - * @param {string} id + * + * @param {string} id * @return {string} */ _ensureAmfPrefix(id) {