@api-components/amf-helper-mixin
Advanced tools
Comparing version 3.0.2 to 3.1.0
@@ -16,58 +16,127 @@ /** | ||
import { IronMeta } from '@polymer/iron-meta/iron-meta.js'; | ||
export const ns = {}; | ||
// This URL is common to both models | ||
// used in the autodetection process | ||
const webApiDocumentType = 'http://a.ml/vocabularies/document#Document'; | ||
// Version 1 of the model: old version | ||
export const ns1 = {}; | ||
// RAML namespace | ||
ns.raml = {}; | ||
ns.raml.name = 'http://a.ml/'; | ||
ns.raml.vocabularies = {}; | ||
ns.raml.vocabularies.name = ns.raml.name + 'vocabularies/'; | ||
ns.raml.vocabularies.document = ns.raml.vocabularies.name + 'document#'; | ||
ns.raml.vocabularies.http = ns.raml.vocabularies.name + 'http#'; | ||
ns.raml.vocabularies.security = ns.raml.vocabularies.name + 'security#'; | ||
ns.raml.vocabularies.shapes = ns.raml.vocabularies.name + 'shapes#'; | ||
ns.raml.vocabularies.data = ns.raml.vocabularies.name + 'data#'; | ||
ns.raml.vocabularies.docSourceMaps = ns.raml.vocabularies.name + 'document-source-maps#'; | ||
ns1.raml = {}; | ||
ns1.raml.name = 'http://a.ml/'; | ||
ns1.raml.vocabularies = {}; | ||
ns1.raml.vocabularies.name = ns1.raml.name + 'vocabularies/'; | ||
ns1.raml.vocabularies.document = ns1.raml.vocabularies.name + 'document#'; | ||
ns1.raml.vocabularies.http = ns1.raml.vocabularies.name + 'http#'; | ||
ns1.raml.vocabularies.security = ns1.raml.vocabularies.name + 'security#'; | ||
ns1.raml.vocabularies.shapes = ns1.raml.vocabularies.name + 'shapes#'; | ||
ns1.raml.vocabularies.data = ns1.raml.vocabularies.name + 'data#'; | ||
ns1.raml.vocabularies.docSourceMaps = ns1.raml.vocabularies.name + 'document-source-maps#'; | ||
// mapping to aml namespace | ||
ns.aml = ns.raml; | ||
ns1.aml = ns1.raml; | ||
// W3 namespace | ||
ns.w3 = {}; | ||
ns.w3.name = 'http://www.w3.org/'; | ||
ns.w3.hydra = {}; | ||
ns.w3.hydra.name = ns.w3.name + 'ns/hydra/'; | ||
ns.w3.hydra.core = ns.w3.hydra.name + 'core#'; | ||
ns.w3.xmlSchema = ns.w3.name + '2001/XMLSchema#'; | ||
ns1.w3 = {}; | ||
ns1.w3.name = 'http://www.w3.org/'; | ||
ns1.w3.hydra = {}; | ||
ns1.w3.hydra.name = ns1.w3.name + 'ns/hydra/'; | ||
ns1.w3.hydra.core = ns1.w3.hydra.name + 'core#'; | ||
ns1.w3.xmlSchema = ns1.w3.name + '2001/XMLSchema#'; | ||
// w3 types | ||
ns.w3.shacl = {}; | ||
ns.w3.shacl.name = ns.w3.name + 'ns/shacl#'; | ||
ns.w3.shacl.in = ns.w3.shacl.name + 'in'; | ||
ns.w3.shacl.defaultValueStr = ns.w3.shacl.name + 'defaultValueStr'; | ||
ns.w3.shacl.pattern = ns.w3.shacl.name + 'pattern'; | ||
ns.w3.shacl.minInclusive = ns.w3.shacl.name + 'minInclusive'; | ||
ns.w3.shacl.maxInclusive = ns.w3.shacl.name + 'maxInclusive'; | ||
ns.w3.shacl.multipleOf = ns.w3.shacl.name + 'multipleOf'; | ||
ns.w3.shacl.minLength = ns.w3.shacl.name + 'minLength'; | ||
ns.w3.shacl.maxLength = ns.w3.shacl.name + 'maxLength'; | ||
ns.w3.shacl.fileType = ns.w3.shacl.name + 'fileType'; | ||
ns.w3.shacl.shape = ns.w3.shacl.name + 'Shape'; | ||
ns1.w3.shacl = {}; | ||
ns1.w3.shacl.name = ns1.w3.name + 'ns/shacl#'; | ||
ns1.w3.shacl.in = ns1.w3.shacl.name + 'in'; | ||
ns1.w3.shacl.defaultValueStr = ns1.w3.shacl.name + 'defaultValueStr'; | ||
ns1.w3.shacl.pattern = ns1.w3.shacl.name + 'pattern'; | ||
ns1.w3.shacl.minInclusive = ns1.w3.shacl.name + 'minInclusive'; | ||
ns1.w3.shacl.maxInclusive = ns1.w3.shacl.name + 'maxInclusive'; | ||
ns1.w3.shacl.multipleOf = ns1.w3.shacl.name + 'multipleOf'; | ||
ns1.w3.shacl.minLength = ns1.w3.shacl.name + 'minLength'; | ||
ns1.w3.shacl.maxLength = ns1.w3.shacl.name + 'maxLength'; | ||
ns1.w3.shacl.fileType = ns1.w3.shacl.name + 'fileType'; | ||
ns1.w3.shacl.shape = ns1.w3.shacl.name + 'Shape'; | ||
// Hydra shortcuts | ||
ns.w3.hydra.supportedOperation = ns.w3.hydra.core + 'supportedOperation'; | ||
ns1.w3.hydra.supportedOperation = ns1.w3.hydra.core + 'supportedOperation'; | ||
// Schema org namespace | ||
ns.schema = {}; | ||
ns.schema.name = 'http://schema.org/'; | ||
ns.schema.schemaName = ns.schema.name + 'name'; | ||
ns.schema.desc = ns.schema.name + 'description'; | ||
ns.schema.doc = ns.schema.name + 'documentation'; | ||
ns.schema.webApi = ns.schema.name + 'WebAPI'; | ||
ns.schema.creativeWork = ns.schema.name + 'CreativeWork'; | ||
ns.schema.displayName = ns.schema.name + 'displayName'; | ||
ns.schema.title = ns.schema.name + 'title'; | ||
ns1.schema = {}; | ||
ns1.schema.name = 'http://schema.org/'; | ||
ns1.schema.schemaName = ns1.schema.name + 'name'; | ||
ns1.schema.desc = ns1.schema.name + 'description'; | ||
ns1.schema.doc = ns1.schema.name + 'documentation'; | ||
ns1.schema.webApi = ns1.schema.name + 'WebAPI'; | ||
ns1.schema.creativeWork = ns1.schema.name + 'CreativeWork'; | ||
ns1.schema.displayName = ns1.schema.name + 'displayName'; | ||
ns1.schema.title = ns1.schema.name + 'title'; | ||
Object.freeze(ns.raml); | ||
Object.freeze(ns.raml.vocabularies); | ||
Object.freeze(ns.aml.vocabularies); | ||
Object.freeze(ns.aml); | ||
Object.freeze(ns.w3); | ||
Object.freeze(ns.w3.hydra); | ||
Object.freeze(ns.w3.shacl); | ||
Object.freeze(ns.schema); | ||
Object.freeze(ns); | ||
Object.freeze(ns1.raml); | ||
Object.freeze(ns1.raml.vocabularies); | ||
Object.freeze(ns1.aml.vocabularies); | ||
Object.freeze(ns1.aml); | ||
Object.freeze(ns1.w3); | ||
Object.freeze(ns1.w3.hydra); | ||
Object.freeze(ns1.w3.shacl); | ||
Object.freeze(ns1.schema); | ||
Object.freeze(ns1); | ||
// version 2 of the model: new model | ||
const ns2 = {}; | ||
// RAML namespace | ||
ns2.raml = {}; | ||
ns2.raml.name = 'http://a.ml/'; | ||
ns2.raml.vocabularies = {}; | ||
ns2.raml.vocabularies.name = ns2.raml.name + 'vocabularies/'; | ||
ns2.raml.vocabularies.document = ns2.raml.vocabularies.name + 'document#'; | ||
ns2.raml.vocabularies.core = ns2.raml.vocabularies.name + 'core#'; | ||
ns2.raml.vocabularies.apiContract = ns2.raml.vocabularies.name + 'apiContract#'; | ||
ns2.raml.vocabularies.http = ns2.raml.vocabularies.apiContract; | ||
ns2.raml.vocabularies.security = ns2.raml.vocabularies.name + 'security#'; | ||
ns2.raml.vocabularies.shapes = ns2.raml.vocabularies.name + 'shapes#'; | ||
ns2.raml.vocabularies.data = ns2.raml.vocabularies.name + 'data#'; | ||
ns2.raml.vocabularies.docSourceMaps = ns2.raml.vocabularies.name + 'document-source-maps#'; | ||
// mapping to aml namespace | ||
ns2.aml = ns2.raml; | ||
// W3 namespace | ||
ns2.w3 = {}; | ||
ns2.w3.name = 'http://www.w3.org/'; | ||
ns2.w3.hydra = {}; | ||
ns2.w3.hydra.name = ns2.w3.name + 'ns/hydra/'; | ||
ns2.w3.hydra.core = ns2.raml.vocabularies.apiContract; | ||
ns2.w3.xmlSchema = ns2.w3.name + '2001/XMLSchema#'; | ||
// w3 types | ||
ns2.w3.shacl = {}; | ||
ns2.w3.shacl.name = ns2.w3.name + 'ns/shacl#'; | ||
ns2.w3.shacl.in = ns2.w3.shacl.name + 'in'; | ||
ns2.w3.shacl.defaultValueStr = ns2.w3.shacl.name + 'defaultValueStr'; | ||
ns2.w3.shacl.pattern = ns2.w3.shacl.name + 'pattern'; | ||
ns2.w3.shacl.minInclusive = ns2.w3.shacl.name + 'minInclusive'; | ||
ns2.w3.shacl.maxInclusive = ns2.w3.shacl.name + 'maxInclusive'; | ||
ns2.w3.shacl.multipleOf = ns2.w3.shacl.name + 'multipleOf'; | ||
ns2.w3.shacl.minLength = ns2.w3.shacl.name + 'minLength'; | ||
ns2.w3.shacl.maxLength = ns2.w3.shacl.name + 'maxLength'; | ||
ns2.w3.shacl.fileType = ns2.w3.shacl.name + 'fileType'; | ||
ns2.w3.shacl.shape = ns2.w3.shacl.name + 'Shape'; | ||
// ApiContracts | ||
ns2.apiContract = {}; | ||
ns2.apiContract.supportedOperation = ns2.raml.vocabularies.apiContract + 'supportedOperation'; | ||
// Hydra shortcuts | ||
ns2.w3.hydra.supportedOperation = ns2.raml.vocabularies.apiContract + 'supportedOperation'; | ||
// Schema org namespace | ||
ns2.schema = {}; | ||
ns2.schema.name = ns2.raml.vocabularies.core; | ||
ns2.schema.schemaName = ns2.schema.name + 'name'; | ||
ns2.schema.desc = ns2.schema.name + 'description'; | ||
ns2.schema.doc = ns2.schema.name + 'documentation'; | ||
ns2.schema.webApi = ns2.raml.vocabularies.apiContract + 'WebAPI'; | ||
ns2.schema.creativeWork = ns2.raml.vocabularies.core + 'CreativeWork'; | ||
ns2.schema.displayName = ns2.raml.vocabularies.core + 'displayName'; | ||
ns2.schema.title = ns2.raml.vocabularies.core + 'title'; | ||
Object.freeze(ns2.raml); | ||
Object.freeze(ns2.raml.vocabularies); | ||
Object.freeze(ns2.aml.vocabularies); | ||
Object.freeze(ns2.aml); | ||
Object.freeze(ns2.w3); | ||
Object.freeze(ns2.w3.hydra); | ||
Object.freeze(ns2.w3.shacl); | ||
Object.freeze(ns2.schema); | ||
Object.freeze(ns2); | ||
/** | ||
@@ -131,3 +200,3 @@ * Common functions used by AMF components to compute AMF values. | ||
set amfModel(value) { | ||
console.warn(this.nodeName + `: "amfModel" property is deprecated. Use "amf" instead.`); | ||
// console.warn(this.nodeName + `: "amfModel" property is deprecated. Use "amf" instead.`); | ||
this.amf = value; | ||
@@ -141,5 +210,46 @@ } | ||
get ns() { | ||
return ns; | ||
return this._version === 2 ? ns2 : ns1; | ||
} | ||
get amf() { | ||
return this._amf; | ||
} | ||
set amf(value) { | ||
this._amf = value; | ||
this._version = this.__detectModelVersion(value); | ||
} | ||
get version() { | ||
return this._version; | ||
} | ||
/** | ||
* Checks for AMF model version. | ||
* @param {[type]} model [description] | ||
* @return {Number} Model major version when defined, `1` when version is | ||
* not defined, and `0` when the model is not valid or not set. | ||
*/ | ||
__detectModelVersion(model) { | ||
if (!model) { | ||
return 0; | ||
} | ||
const doc = this._ensureAmfModel(model); | ||
if (!doc) { | ||
return 0; | ||
} | ||
const ctx = doc['@context']; | ||
let versionString; | ||
if (ctx) { | ||
versionString = this._getValue(doc, 'doc:version'); | ||
} else { | ||
versionString = this._getValue(doc, 'http://a.ml/vocabularies/document#version'); | ||
} | ||
if (versionString) { | ||
const major = versionString.split('.')[0]; | ||
return major === '2' ? 2 : 1; | ||
} | ||
return 1; | ||
} | ||
/** | ||
* Returns compact model key for given value. | ||
@@ -168,3 +278,3 @@ * @param {String} property AMF orioginal property | ||
const hashProperty = property.substr(0, hashIndex + 1); | ||
for (let k in ctx) { | ||
for (const k in ctx) { | ||
if (ctx.hasOwnProperty(k)) { | ||
@@ -197,3 +307,3 @@ if (ctx[k] === property) { | ||
} | ||
if (this._hasType(amf, ns.raml.vocabularies.document + 'Document')) { | ||
if (this._hasType(amf, webApiDocumentType)) { | ||
return amf; | ||
@@ -253,3 +363,3 @@ } | ||
key = this._getAmfKey(key); | ||
let data = (model && this._ensureArray(model[key])); | ||
const data = model && this._ensureArray(model[key]); | ||
if (!data || !(data instanceof Array)) { | ||
@@ -287,3 +397,3 @@ return; | ||
key = this._getAmfKey(key); | ||
return !!(shape && key && (key in shape)); | ||
return !!(shape && key && key in shape); | ||
} | ||
@@ -302,3 +412,3 @@ /** | ||
key = this._getAmfKey(key); | ||
let data = this._ensureArray(shape && shape[key]); | ||
const data = this._ensureArray(shape && shape[key]); | ||
if (!data || !(data instanceof Array)) { | ||
@@ -346,15 +456,27 @@ return; | ||
_computeDescription(shape) { | ||
return this._getValue(shape, ns.schema.desc); | ||
return this._getValue(shape, this.ns.schema.desc); | ||
} | ||
_computeHeaders(shape) { | ||
return this._computePropertyArray(shape, ns.raml.vocabularies.http + 'header'); | ||
if (this.version === 1) { | ||
return this._computePropertyArray(shape, this.ns.raml.vocabularies.http + 'header'); | ||
} else { | ||
return this._computePropertyArray(shape, this.ns.raml.vocabularies.apiContract + 'header'); | ||
} | ||
} | ||
_computeQueryParameters(shape) { | ||
return this._computePropertyArray(shape, ns.raml.vocabularies.http + 'parameter'); | ||
if (this.version === 1) { | ||
return this._computePropertyArray(shape, this.ns.raml.vocabularies.http + 'parameter'); | ||
} else { | ||
return this._computePropertyArray(shape, this.ns.raml.vocabularies.apiContract + 'parameter'); | ||
} | ||
} | ||
_computeResponses(shape) { | ||
return this._computePropertyArray(shape, ns.w3.hydra.core + 'response'); | ||
if (this.version === 1) { | ||
return this._computePropertyArray(shape, this.ns.w3.hydra.core + 'response'); | ||
} else { | ||
return this._computePropertyArray(shape, this.ns.raml.vocabularies.apiContract + 'response'); | ||
} | ||
} | ||
@@ -368,3 +490,7 @@ /** | ||
_computeServerVariables(server) { | ||
return this._computePropertyArray(server, ns.raml.vocabularies.http + 'variable'); | ||
if (this.version === 1) { | ||
return this._computePropertyArray(server, this.ns.raml.vocabularies.http + 'variable'); | ||
} else { | ||
return this._computePropertyArray(server, this.ns.raml.vocabularies.apiContract + 'variable'); | ||
} | ||
} | ||
@@ -387,3 +513,7 @@ /** | ||
_computePayload(expects) { | ||
return this._computePropertyArray(expects, ns.raml.vocabularies.http + 'payload'); | ||
if (this.version === 1) { | ||
return this._computePropertyArray(expects, this.ns.raml.vocabularies.http + 'payload'); | ||
} else { | ||
return this._computePropertyArray(expects, this.ns.raml.vocabularies.apiContract + 'payload'); | ||
} | ||
} | ||
@@ -397,3 +527,7 @@ /** | ||
_computeReturns(method) { | ||
return this._computePropertyArray(method, ns.w3.hydra.core + 'returns'); | ||
if (this.version === 1) { | ||
return this._computePropertyArray(method, this.ns.w3.hydra.core + 'returns'); | ||
} else { | ||
return this._computePropertyArray(method, this.ns.raml.vocabularies.apiContract + 'returns'); | ||
} | ||
} | ||
@@ -407,3 +541,3 @@ /** | ||
_computeSecurity(method) { | ||
return this._computePropertyArray(method, ns.raml.vocabularies.security + 'security'); | ||
return this._computePropertyArray(method, this.ns.raml.vocabularies.security + 'security'); | ||
} | ||
@@ -417,3 +551,3 @@ /** | ||
_computeHasCustomProperties(shape) { | ||
return this._hasProperty(shape, ns.raml.vocabularies.document + 'customDomainProperties'); | ||
return this._hasProperty(shape, this.ns.raml.vocabularies.document + 'customDomainProperties'); | ||
} | ||
@@ -431,3 +565,7 @@ /** | ||
} | ||
return this._getValue(api, ns.schema.name + 'version'); | ||
if (this.version === 1) { | ||
return this._getValue(api, this.ns.schema.name + 'version'); | ||
} else { | ||
return this._getValue(api, this.ns.raml.vocabularies.core + 'version'); | ||
} | ||
} | ||
@@ -447,3 +585,3 @@ /** | ||
} | ||
const key = this._getAmfKey(ns.raml.vocabularies.document + 'encodes'); | ||
const key = this._getAmfKey(this.ns.raml.vocabularies.document + 'encodes'); | ||
const data = model[key]; | ||
@@ -470,3 +608,3 @@ if (data) { | ||
} | ||
const key = this._getAmfKey(ns.raml.vocabularies.document + 'declares'); | ||
const key = this._getAmfKey(this.ns.raml.vocabularies.document + 'declares'); | ||
const data = this._ensureArray(model[key]); | ||
@@ -491,3 +629,3 @@ return data instanceof Array ? data : undefined; | ||
} | ||
const key = this._getAmfKey(ns.raml.vocabularies.document + 'references'); | ||
const key = this._getAmfKey(this.ns.raml.vocabularies.document + 'references'); | ||
const data = this._ensureArray(model[key]); | ||
@@ -507,3 +645,3 @@ return data instanceof Array ? data : undefined; | ||
} | ||
if (this._hasType(enc, ns.schema.webApi)) { | ||
if (this._hasType(enc, this.ns.schema.webApi)) { | ||
return enc; | ||
@@ -523,3 +661,8 @@ } | ||
} | ||
const key = this._getAmfKey(ns.raml.vocabularies.http + 'server'); | ||
let key; | ||
if (this.version === 1) { | ||
key = this._getAmfKey(this.ns.raml.vocabularies.http + 'server'); | ||
} else { | ||
key = this._getAmfKey(this.ns.raml.vocabularies.apiContract + 'server'); | ||
} | ||
const srv = this._ensureArray(api[key]); | ||
@@ -543,3 +686,8 @@ return srv ? srv[0] : undefined; | ||
base = this._ensureUrlScheme(base); | ||
const path = this._getValue(endpoint, ns.raml.vocabularies.http + 'path'); | ||
let path; | ||
if (this.version === 1) { | ||
path = this._getValue(endpoint, this.ns.raml.vocabularies.http + 'path'); | ||
} else { | ||
path = this._getValue(endpoint, this.ns.raml.vocabularies.apiContract + 'path'); | ||
} | ||
let result = base + (path || ''); | ||
@@ -565,3 +713,3 @@ if (version && result) { | ||
if (IronMeta) { | ||
let value = new IronMeta({key: 'ApiBaseUri'}).value; | ||
const value = new IronMeta({ key: 'ApiBaseUri' }).value; | ||
if (value) { | ||
@@ -583,3 +731,9 @@ return value; | ||
_getAmfBaseUri(server, protocols) { | ||
let value = this._getValue(server, ns.raml.vocabularies.http + 'url'); | ||
let key; | ||
if (this.version === 1) { | ||
key = this.ns.raml.vocabularies.http + 'url'; | ||
} else { | ||
key = this.ns.raml.vocabularies.core + 'urlTemplate'; | ||
} | ||
let value = this._getValue(server, key); | ||
value = this._ensureUrlScheme(value, protocols); | ||
@@ -625,3 +779,7 @@ return value; | ||
} | ||
return this._getValueArray(api, ns.raml.vocabularies.http + 'scheme'); | ||
if (this.version === 1) { | ||
return this._getValueArray(api, this.ns.raml.vocabularies.http + 'scheme'); | ||
} else { | ||
return this._getValueArray(api, this.ns.raml.vocabularies.apiContract + 'scheme'); | ||
} | ||
} | ||
@@ -635,4 +793,13 @@ /** | ||
_computeExpects(method) { | ||
if (this._hasType(method, ns.w3.hydra.core + 'Operation')) { | ||
const key = this._getAmfKey(ns.w3.hydra.core + 'expects'); | ||
let operationKey; | ||
let expectsKey; | ||
if (this.version === 1) { | ||
operationKey = this.ns.w3.hydra.core + 'Operation'; | ||
expectsKey = this.ns.w3.hydra.core + 'expects'; | ||
} else { | ||
operationKey = this.ns.raml.vocabularies.apiContract + 'Operation'; | ||
expectsKey = this.ns.raml.vocabularies.apiContract + 'expects'; | ||
} | ||
if (this._hasType(method, operationKey)) { | ||
const key = this._getAmfKey(expectsKey); | ||
const expects = this._ensureArray(method[key]); | ||
@@ -652,3 +819,24 @@ if (expects) { | ||
_computePropertyValue(item) { | ||
const skey = this._getAmfKey(ns.raml.vocabularies.http + 'schema'); | ||
let exKey; | ||
if (this.version === 1) { | ||
exKey = this.ns.raml.vocabularies.document + 'examples'; | ||
} else { | ||
exKey = this.ns.raml.vocabularies.apiContract + 'examples'; | ||
} | ||
let schemaKey; | ||
if (this.version === 1) { | ||
schemaKey = this.ns.raml.vocabularies.http + 'schema'; | ||
} else { | ||
schemaKey = this.ns.raml.vocabularies.shapes + 'schema'; | ||
} | ||
let rawKey; | ||
if (this.version === 1) { | ||
rawKey = this.ns.w3.shacl.name + 'raw'; | ||
} else { | ||
rawKey = this.ns.raml.vocabularies.document + 'raw'; | ||
} | ||
const skey = this._getAmfKey(schemaKey); | ||
let schema = item && item[skey]; | ||
@@ -661,5 +849,5 @@ if (!schema) { | ||
} | ||
let value = this._getValue(schema, ns.w3.shacl.name + 'defaultValue'); | ||
let value = this._getValue(schema, this.ns.w3.shacl.name + 'defaultValue'); | ||
if (!value) { | ||
const examplesKey = this._getAmfKey(ns.raml.vocabularies.document + 'examples'); | ||
const examplesKey = this._getAmfKey(exKey); | ||
let example = schema[examplesKey]; | ||
@@ -670,3 +858,3 @@ if (example) { | ||
} | ||
value = this._getValue(example, ns.w3.shacl.name + 'raw'); | ||
value = this._getValue(example, rawKey); | ||
} | ||
@@ -685,3 +873,11 @@ } | ||
} | ||
const key = this._getAmfKey(ns.raml.vocabularies.http + 'endpoint'); | ||
let endpointKey; | ||
if (this.version === 1) { | ||
endpointKey = this.ns.raml.vocabularies.http + 'endpoint'; | ||
} else { | ||
endpointKey = this.ns.raml.vocabularies.apiContract + 'endpoint'; | ||
} | ||
const key = this._getAmfKey(endpointKey); | ||
return this._ensureArray(webApi[key]); | ||
@@ -718,4 +914,12 @@ } | ||
} | ||
let pathKey; | ||
if (this.version === 1) { | ||
pathKey = this.ns.raml.vocabularies.http + 'path'; | ||
} else { | ||
pathKey = this.ns.raml.vocabularies.apiContract + 'path'; | ||
} | ||
for (let i = 0; i < endpoints.length; i++) { | ||
const ePath = this._getValue(endpoints[i], this.ns.raml.vocabularies.http + 'path'); | ||
const ePath = this._getValue(endpoints[i], pathKey); | ||
if (ePath === path) { | ||
@@ -751,3 +955,11 @@ return endpoints[i]; | ||
} | ||
const opKey = this._getAmfKey(ns.w3.hydra.supportedOperation); | ||
let supportedOperationKey; | ||
if (this.version === 1) { | ||
supportedOperationKey = this.ns.w3.hydra.supportedOperation; | ||
} else { | ||
supportedOperationKey = this.ns.apiContract.supportedOperation; | ||
} | ||
const opKey = this._getAmfKey(supportedOperationKey); | ||
return this._ensureArray(endpoint[opKey]); | ||
@@ -769,3 +981,11 @@ } | ||
} | ||
const opKey = this._getAmfKey(ns.w3.hydra.supportedOperation); | ||
let supportedOperationKey; | ||
if (this.version === 1) { | ||
supportedOperationKey = this.ns.w3.hydra.supportedOperation; | ||
} else { | ||
supportedOperationKey = this.ns.apiContract.supportedOperation; | ||
} | ||
const opKey = this._getAmfKey(supportedOperationKey); | ||
for (let i = 0, len = endpoints.length; i < len; i++) { | ||
@@ -800,3 +1020,11 @@ const endpoint = endpoints[i]; | ||
} | ||
const opKey = this._getAmfKey(ns.w3.hydra.supportedOperation); | ||
let supportedOperationKey; | ||
if (this.version === 1) { | ||
supportedOperationKey = this.ns.w3.hydra.supportedOperation; | ||
} else { | ||
supportedOperationKey = this.ns.apiContract.supportedOperation; | ||
} | ||
const opKey = this._getAmfKey(supportedOperationKey); | ||
return this._ensureArray(endpoint[opKey]); | ||
@@ -819,3 +1047,3 @@ } | ||
for (let i = 0, len = references.length; i < len; i++) { | ||
if (!this._hasType(references[i], ns.raml.vocabularies.document + 'Module')) { | ||
if (!this._hasType(references[i], this.ns.raml.vocabularies.document + 'Module')) { | ||
continue; | ||
@@ -877,3 +1105,3 @@ } | ||
} | ||
const key = this._getAmfKey(ns.schema.doc); | ||
const key = this._getAmfKey(this.ns.schema.doc); | ||
const docs = this._ensureArray(webApi[key]); | ||
@@ -893,3 +1121,3 @@ return docs && docs.find((item) => item['@id'] === selected); | ||
} | ||
let refKey = this._getAmfKey(ns.raml.vocabularies.document + 'link-target'); | ||
let refKey = this._getAmfKey(this.ns.raml.vocabularies.document + 'link-target'); | ||
let refValue = this._ensureArray(shape[refKey]); | ||
@@ -906,3 +1134,3 @@ let refData; | ||
} else { | ||
refKey = this._getAmfKey(ns.raml.vocabularies.document + 'reference-id'); | ||
refKey = this._getAmfKey(this.ns.raml.vocabularies.document + 'reference-id'); | ||
refValue = this._ensureArray(shape[refKey]); | ||
@@ -965,2 +1193,10 @@ if (refValue) { | ||
_getSchemaKey(element) { | ||
if (element.version === 1) { | ||
return element._getAmfKey(element.ns.raml.vocabularies.http + 'schema'); | ||
} else { | ||
return element._getAmfKey(element.ns.raml.vocabularies.shapes + 'schema'); | ||
} | ||
} | ||
_getReferenceId(amf, id) { | ||
@@ -1008,6 +1244,6 @@ if (!amf || !id) { | ||
item = this._resolve(item); | ||
let data = this._getValue(item, ns.w3.shacl.name + 'raw'); | ||
let data = this._getValue(item, this.ns.w3.shacl.name + 'raw'); | ||
// This suppose to be a JSON data so lets test it. | ||
if (!data || (isJson && !(data[0] === '{' || data[0] === '['))) { | ||
const key = this._getAmfKey(ns.raml.vocabularies.document + 'structuredValue'); | ||
const key = this._getAmfKey(this.ns.raml.vocabularies.document + 'structuredValue'); | ||
const structured = this._ensureArray(item[key]); | ||
@@ -1029,7 +1265,6 @@ if (structured) { | ||
_computeExampleFromStructuredValue(model) { | ||
if (this._hasType(model, ns.raml.vocabularies.data + 'Scalar')) { | ||
return this._computeStructuredExampleValue( | ||
this._getValue(model, ns.raml.vocabularies.data + 'value')); | ||
if (this._hasType(model, this.ns.raml.vocabularies.data + 'Scalar')) { | ||
return this._computeStructuredExampleValue(this._getValue(model, this.ns.raml.vocabularies.data + 'value')); | ||
} | ||
const isObject = this._hasType(model, ns.raml.vocabularies.data + 'Object'); | ||
const isObject = this._hasType(model, this.ns.raml.vocabularies.data + 'Object'); | ||
const result = isObject ? {} : []; | ||
@@ -1064,4 +1299,4 @@ const modelKeys = ['@id', '@type']; | ||
} | ||
if (this._hasType(model, ns.raml.vocabularies.data + 'Scalar')) { | ||
const key = this._getAmfKey(ns.raml.vocabularies.data + 'value'); | ||
if (this._hasType(model, this.ns.raml.vocabularies.data + 'Scalar')) { | ||
const key = this._getAmfKey(this.ns.raml.vocabularies.data + 'value'); | ||
const mValue = this._ensureArray(model[key])[0]; | ||
@@ -1071,9 +1306,9 @@ const type = mValue['@type']; | ||
switch (type) { | ||
case ns.w3.xmlSchema + 'boolean': | ||
case this.ns.w3.xmlSchema + 'boolean': | ||
return value === 'true' ? true : false; | ||
case ns.w3.xmlSchema + 'integer': | ||
case ns.w3.xmlSchema + 'long': | ||
case ns.w3.xmlSchema + 'double': | ||
case ns.w3.xmlSchema + 'float': | ||
case ns.raml.vocabularies.shapes + 'number': | ||
case this.ns.w3.xmlSchema + 'integer': | ||
case this.ns.w3.xmlSchema + 'long': | ||
case this.ns.w3.xmlSchema + 'double': | ||
case this.ns.w3.xmlSchema + 'float': | ||
case this.ns.raml.vocabularies.shapes + 'number': | ||
return Number(value); | ||
@@ -1087,3 +1322,3 @@ default: | ||
} | ||
return AHmixin; | ||
return AHmixin; | ||
}); |
@@ -453,1 +453,5 @@ <a name="2.0.11"></a> | ||
## [3.0.2](https://github.com/advanced-rest-client/amf-helper-mixin/compare/2.0.0-preview...3.0.2) (2019-07-28) | ||
{ | ||
"name": "@api-components/amf-helper-mixin", | ||
"description": "A mixin with common functions user by most AMF components to compyte AMF values", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"license": "Apache-2.0", | ||
@@ -35,8 +35,8 @@ "main": "amf-helper-mixin.js", | ||
"@advanced-rest-client/prettier-config": "^0.1.0", | ||
"@advanced-rest-client/testing-karma-sl": "^1.0.2", | ||
"@advanced-rest-client/testing-karma-sl": "^1.0.3", | ||
"@api-components/api-model-generator": "^0.1.12", | ||
"@commitlint/cli": "^8.1.0", | ||
"@commitlint/config-conventional": "^7.0.0", | ||
"@open-wc/testing": "^2.1.2", | ||
"@open-wc/testing-karma": "^3.1.2", | ||
"@open-wc/testing": "^2.2.8", | ||
"@open-wc/testing-karma": "^3.1.24", | ||
"@polymer/gen-typescript-declarations": "^1.6.2", | ||
@@ -46,7 +46,7 @@ "lit-element": "^2.2.1", | ||
"deepmerge": "^4.0.0", | ||
"es-dev-server": "^1.5.0", | ||
"es-dev-server": "^1.14.2", | ||
"husky": "^1.0.0", | ||
"karma": "^4.2.0", | ||
"lint-staged": "^8.0.0", | ||
"sinon": "^7.3.2" | ||
"lint-staged": "^9.2.1", | ||
"sinon": "^7.4.1" | ||
}, | ||
@@ -72,3 +72,2 @@ "scripts": { | ||
"eslint --fix", | ||
"prettier --write", | ||
"git add" | ||
@@ -75,0 +74,0 @@ ] |
@@ -0,5 +1,5 @@ | ||
[](https://www.npmjs.com/package/@api-components/amf-helper-mixin) | ||
[](https://travis-ci.org/advanced-rest-client/amf-helper-mixin) | ||
[](https://www.webcomponents.org/element/advanced-rest-client/amf-helper-mixin) | ||
# amf-helper-mixin | ||
@@ -6,0 +6,0 @@ |
94243
1656