Skip to content

W-17655986 Ensure Default Boolean Values Are Loaded from Schema #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -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:
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
25 changes: 14 additions & 11 deletions src/ApiViewModel.js
Original file line number Diff line number Diff line change
@@ -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) {