Skip to content

Commit 1ce1f48

Browse files
authored
Merge pull request #8 from advanced-rest-client/fix/W-17655986/default-value-boolean-is-showing-wrong
W-17655986 Ensure Default Boolean Values Are Loaded from Schema
2 parents 91fc538 + 6ed1825 commit 1ce1f48

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

.github/workflows/deployment.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ on:
1313
- main
1414
jobs:
1515
test_linux:
16-
name: Ubuntu
17-
runs-on: ubuntu-latest
16+
name: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
os: [ubuntu-20.04]
21+
runs-on: ${{ matrix.os }}
1822
steps:
1923
- uses: actions/checkout@v2
2024
- uses: actions/setup-node@v1
2125
with:
22-
node-version: 14
26+
node-version: 16
2327
- uses: microsoft/playwright-github-action@v1
2428
- uses: actions/cache@v1
2529
with:
@@ -38,7 +42,7 @@ jobs:
3842
- uses: actions/checkout@v2
3943
- uses: actions/setup-node@v1
4044
with:
41-
node-version: 14
45+
node-version: 16
4246
- uses: microsoft/playwright-github-action@v1
4347
- uses: actions/cache@v1
4448
with:
@@ -53,7 +57,7 @@ jobs:
5357
tag:
5458
name: "Publishing release"
5559
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
56-
needs:
60+
needs:
5761
- test_linux
5862
- test_win
5963
runs-on: ubuntu-latest
@@ -64,7 +68,7 @@ jobs:
6468
fetch-depth: 0
6569
- uses: actions/setup-node@v2
6670
with:
67-
node-version: '14.x'
71+
node-version: '16.x'
6872
registry-url: 'https://registry.npmjs.org'
6973
- uses: actions/cache@v1
7074
with:

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@api-components/api-forms",
33
"description": "A library containing helper classes to compute API data from the AMF web API model.",
4-
"version": "0.2.6",
4+
"version": "0.2.7",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/ApiViewModel.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class ApiViewModel extends AmfHelperMixin(Object) {
128128
/**
129129
* @param {ConstructorOptions=} [opts={}]
130130
*/
131-
constructor(opts={}) {
131+
constructor(opts = {}) {
132132
super();
133133
/**
134134
* An array of properties for which view model is to be generated.
@@ -220,7 +220,7 @@ export class ApiViewModel extends AmfHelperMixin(Object) {
220220
result[result.length] = data;
221221
}
222222
} else if (this._hasType(items, this.ns.aml.vocabularies.shapes.UnionShape)) {
223-
result = this. _modelForUnion(items);
223+
result = this._modelForUnion(items);
224224
}
225225
return result;
226226
}
@@ -338,6 +338,9 @@ export class ApiViewModel extends AmfHelperMixin(Object) {
338338
if (!this.noDocs) {
339339
schemaItem.description = this._computeDescription(amfItem);
340340
}
341+
if (schemaItem.isBool) {
342+
result.value = schemaItem.defaultValue
343+
}
341344
const valueDelimiter = this._computeValueDelimiter(binding);
342345
const decodeValues = this._computeDecodeValues(binding);
343346
const processOptions = {
@@ -453,7 +456,7 @@ export class ApiViewModel extends AmfHelperMixin(Object) {
453456
* @param {ProcessOptions=} processOptions
454457
* @return {AmfFormItem[]} View model for items.
455458
*/
456-
modelForRawObject(model, processOptions={}) {
459+
modelForRawObject(model, processOptions = {}) {
457460
const result = [];
458461
const keys = Object.keys(model);
459462
const dataKey = this._getAmfKey(this.ns.raml.vocabularies.data.toString());
@@ -625,8 +628,8 @@ export class ApiViewModel extends AmfHelperMixin(Object) {
625628
}
626629
if (item.schema.required && typeof item.schema.defaultValue !== 'undefined') {
627630
item.value = item.schema.isArray ?
628-
this._parseArrayExample(/** @type {string} */ (item.schema.defaultValue), processOptions) :
629-
this._exampleAsValue(/** @type {string} */ (item.schema.defaultValue), processOptions);
631+
this._parseArrayExample(/** @type {string} */(item.schema.defaultValue), processOptions) :
632+
this._exampleAsValue(/** @type {string} */(item.schema.defaultValue), processOptions);
630633
}
631634
if (typeof item.value === 'undefined' && item.schema.required) {
632635
const { examples } = item.schema;
@@ -1181,10 +1184,10 @@ export class ApiViewModel extends AmfHelperMixin(Object) {
11811184
_computeInputType(type) {
11821185
if (type && NUMBER_INPUT_TYPES.indexOf(type) !== -1) {
11831186
return 'number';
1184-
}
1187+
}
11851188
if (type === 'boolean') {
11861189
return 'boolean';
1187-
}
1190+
}
11881191
if (type === 'date-only' || type === 'date') {
11891192
return 'date';
11901193
} /* else if (type === 'time-only' || type === 'time') {
@@ -1268,7 +1271,7 @@ export class ApiViewModel extends AmfHelperMixin(Object) {
12681271
* @param {string=} binding
12691272
* @return {AmfFormItem} Generated basic view model.
12701273
*/
1271-
buildProperty(defaults={
1274+
buildProperty(defaults = {
12721275
name: undefined,
12731276
value: undefined,
12741277
enabled: true,
@@ -1367,7 +1370,7 @@ export class ApiViewModel extends AmfHelperMixin(Object) {
13671370
return false;
13681371
}
13691372
for (let i = 0, len = values.length; i < len; i++) {
1370-
const id = this._ensureAmfPrefix(/** @type string */ (this._getValue(values[i], '@id')));
1373+
const id = this._ensureAmfPrefix(/** @type string */(this._getValue(values[i], '@id')));
13711374
const node = shape[id];
13721375
const extensionNameKey = this._getAmfKey(this.ns.aml.vocabularies.core.extensionName);
13731376
if (this._getValue(node, extensionNameKey) === 'no-auto-encoding') {
@@ -1378,8 +1381,8 @@ export class ApiViewModel extends AmfHelperMixin(Object) {
13781381
}
13791382

13801383
/**
1381-
*
1382-
* @param {string} id
1384+
*
1385+
* @param {string} id
13831386
* @return {string}
13841387
*/
13851388
_ensureAmfPrefix(id) {

0 commit comments

Comments
 (0)