From fdd8f3e1eb93ba52369bfe201b433e9946bbd748 Mon Sep 17 00:00:00 2001 From: alexperez Date: Fri, 7 Feb 2025 17:48:38 -0300 Subject: [PATCH 1/5] Add default value to booleans params --- src/ApiViewModel.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) 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) { From dc6f30b55d1efebc2b27ab42c6fda8bdceb62cd6 Mon Sep 17 00:00:00 2001 From: alexperez Date: Fri, 7 Feb 2025 17:50:25 -0300 Subject: [PATCH 2/5] 0.2.7 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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", From 229f29d4cea94a54c3d724a27c07854ec77e0193 Mon Sep 17 00:00:00 2001 From: alexperez Date: Fri, 7 Feb 2025 21:00:42 -0300 Subject: [PATCH 3/5] chore: update Node.js version to 16 in deployment workflow --- .github/workflows/deployment.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index faf5a55..0985ef5 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -19,7 +19,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: @@ -38,7 +38,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 +53,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 +64,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: From 1ee7ca142d279f4b266e1f2693507ef3c87eaf2e Mon Sep 17 00:00:00 2001 From: alexperez Date: Fri, 7 Feb 2025 21:26:51 -0300 Subject: [PATCH 4/5] chore: update deployment workflow to use matrix strategy for OS --- .github/workflows/deployment.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 0985ef5..132a528 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -13,8 +13,13 @@ on: - main jobs: test_linux: - name: Ubuntu - runs-on: ubuntu-latest + name: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-20.04] + # os: [ubuntu-18.04, ubuntu-20.04] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 From 6ed1825f1e764de68264369b3999e5737b61340f Mon Sep 17 00:00:00 2001 From: alexperez Date: Fri, 7 Feb 2025 21:55:42 -0300 Subject: [PATCH 5/5] chore: simplify deployment workflow by removing deprecated OS version --- .github/workflows/deployment.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 132a528..9dad932 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -18,7 +18,6 @@ jobs: fail-fast: false matrix: os: [ubuntu-20.04] - # os: [ubuntu-18.04, ubuntu-20.04] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2