Skip to content

Commit

Permalink
Merge pull request #76 from advanced-rest-client/fix/W-13536254/requi…
Browse files Browse the repository at this point in the history
…red-fields

[W-13536254] Required fields
  • Loading branch information
carowright authored Jul 5, 2023
2 parents d95a9ea + 5506083 commit ea17cd1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
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-type-document",
"description": "A documentation table for type (resource) properties. Works with AMF data model",
"version": "4.2.26",
"version": "4.2.27",
"license": "Apache-2.0",
"main": "index.js",
"module": "index.js",
Expand Down
12 changes: 10 additions & 2 deletions src/PropertyShapeDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
return !!parentTypeName;
}

_toBoolean(value) {
if (typeof value === 'boolean') {
return value
}
return value === 'true'
}

/**
* Computes value for `isRequired` property.
* In AMF model a property is required when `http://www.w3.org/ns/shacl#minCount`
Expand All @@ -404,10 +411,11 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
}
shape = this._resolve(shape);
if (this._hasType(shape, this.ns.aml.vocabularies.apiContract.Parameter)) {
return /** @type boolean */ Boolean(this._getValue(
const required = this._getValue(
shape,
this.ns.aml.vocabularies.apiContract.required
));
)
return this._toBoolean(required);
}
const data = this._getValue(shape, this.ns.w3.shacl.minCount);
return data !== undefined && Number(data) !== 0;
Expand Down

0 comments on commit ea17cd1

Please sign in to comment.