@@ -9,8 +9,9 @@ export class ApiDescribe {
99 /**
1010 * @param {string } label
1111 * @param {boolean } compact
12+ * @param {boolean } flattened
1213 */
13- constructor ( label , compact = false ) {
14+ constructor ( label , compact = false , flattened = false ) {
1415 /**
1516 * @type {string }
1617 */
@@ -19,6 +20,10 @@ export class ApiDescribe {
1920 * @type {boolean }
2021 */
2122 this . compact = compact ;
23+ /**
24+ * @type {boolean }
25+ */
26+ this . flattened = flattened ;
2227 }
2328}
2429
@@ -35,6 +40,7 @@ const helper = new HelperElement();
3540 * @typedef {Object } ApiLoadOptions
3641 * @property {boolean= } compact Whether to download a compact version of an API
3742 * @property {string= } fileName Name of the API file, without the extension
43+ * @property {boolean= } flattened Whether to generate flattened model or not
3844 */
3945
4046/**
@@ -80,10 +86,10 @@ const helper = new HelperElement();
8086 * @return {Promise<ApiModel> } Promise resolved to API object.
8187 */
8288AmfLoader . load = async ( config = { } ) => {
83- const { compact= false , fileName= 'demo-api' } = config ;
89+ const { compact= false , fileName= 'demo-api' , flattened = false } = config ;
8490 const suffix = compact ? '-compact' : '' ;
8591 const file = `${ fileName } ${ suffix } .json` ;
86- const url = `${ window . location . protocol } //${ window . location . host } /base/demo/models/${ file } ` ;
92+ const url = `${ window . location . protocol } //${ window . location . host } /base/demo/models/${ flattened ? 'flattened/' : '' } ${ file } ` ;
8793 const response = await fetch ( url ) ;
8894 if ( ! response . ok ) {
8995 throw new Error ( `Unable to download ${ url } ` ) ;
@@ -97,7 +103,7 @@ AmfLoader.load = async (config = {}) => {
97103 * @param {ApiModel } model Api model.
98104 * @return {WebApiModel } Model for the WebApi
99105 */
100- AmfLoader . lookupWebApi = function ( model ) {
106+ AmfLoader . lookupWebApi = ( model ) => {
101107 helper . amf = model ;
102108 return helper . _computeApi ( model ) ;
103109} ;
@@ -108,7 +114,7 @@ AmfLoader.lookupWebApi = function(model) {
108114 * @param {string } endpoint Endpoint path
109115 * @return {EndpointModel|undefined } Model for the endpoint
110116 */
111- AmfLoader . lookupEndpoint = function ( model , endpoint ) {
117+ AmfLoader . lookupEndpoint = ( model , endpoint ) => {
112118 helper . amf = model ;
113119 const webApi = helper . _computeApi ( model ) ;
114120 return helper . _computeEndpointByPath ( webApi , endpoint ) ;
@@ -121,7 +127,7 @@ AmfLoader.lookupEndpoint = function(model, endpoint) {
121127 * @param {string } operation Operation name (the verb, lowercase)
122128 * @return {OperationModel|undefined } Model for the endpoint
123129 */
124- AmfLoader . lookupOperation = function ( model , endpoint , operation ) {
130+ AmfLoader . lookupOperation = ( model , endpoint , operation ) => {
125131 const endPoint = AmfLoader . lookupEndpoint ( model , endpoint ) ;
126132 const opKey = helper . _getAmfKey ( helper . ns . aml . vocabularies . apiContract . supportedOperation ) ;
127133 const ops = helper . _ensureArray ( endPoint [ opKey ] ) ;
@@ -135,7 +141,7 @@ AmfLoader.lookupOperation = function(model, endpoint, operation) {
135141 * @param {string } operation Operation name (the verb, lowercase)
136142 * @return {PayloadModel[]|undefined } Model for the payload
137143 */
138- AmfLoader . lookupPayload = function ( model , endpoint , operation ) {
144+ AmfLoader . lookupPayload = ( model , endpoint , operation ) => {
139145 const op = AmfLoader . lookupOperation ( model , endpoint , operation ) ;
140146 const expects = helper . _computeExpects ( op ) ;
141147 return helper . _ensureArray ( helper . _computePayload ( expects ) ) ;
@@ -154,7 +160,7 @@ AmfLoader.lookupPayload = function(model, endpoint, operation) {
154160 * @param {string } operation Operation name (the verb, lowercase)
155161 * @return {Array<EndpointModel|OperationModel> } First item is the endpoint model and the second is the operation model.
156162 */
157- AmfLoader . lookupEndpointOperation = function ( model , endpoint , operation ) {
163+ AmfLoader . lookupEndpointOperation = ( model , endpoint , operation ) => {
158164 const endPoint = AmfLoader . lookupEndpoint ( model , endpoint ) ;
159165 const opKey = helper . _getAmfKey ( helper . ns . aml . vocabularies . apiContract . supportedOperation ) ;
160166 const ops = helper . _ensureArray ( endPoint [ opKey ] ) ;
@@ -168,11 +174,9 @@ AmfLoader.lookupEndpointOperation = function(model, endpoint, operation) {
168174 * @param {string } name Name of the security scheme
169175 * @return {SecurityModel }
170176 */
171- AmfLoader . lookupSecurity = function ( model , name ) {
177+ AmfLoader . lookupSecurity = ( model , name ) => {
172178 helper . amf = model ;
173- const webApi = helper . _hasType ( model , helper . ns . aml . vocabularies . document . Document ) ?
174- helper . _computeApi ( model ) :
175- model ;
179+ const webApi = helper . _hasType ( model , helper . ns . aml . vocabularies . document . Document ) ? helper . _computeApi ( model ) : model ;
176180 const declares = helper . _computeDeclares ( webApi ) || [ ] ;
177181 let result = declares . find ( ( item ) => {
178182 if ( item instanceof Array ) {
@@ -208,11 +212,9 @@ AmfLoader.lookupSecurity = function(model, name) {
208212 * @param {string } name Name of the data type
209213 * @return {TypeModel }
210214 */
211- AmfLoader . lookupType = function ( model , name ) {
215+ AmfLoader . lookupType = ( model , name ) => {
212216 helper . amf = model ;
213- const webApi = helper . _hasType ( model , helper . ns . aml . vocabularies . document . Document ) ?
214- helper . _computeApi ( model ) :
215- model ;
217+ const webApi = helper . _hasType ( model , helper . ns . aml . vocabularies . document . Document ) ? helper . _computeApi ( model ) : model ;
216218 const declares = helper . _computeDeclares ( webApi ) || [ ] ;
217219 let result = declares . find ( ( item ) => {
218220 if ( item instanceof Array ) {
@@ -244,7 +246,7 @@ AmfLoader.lookupType = function(model, name) {
244246 * @param {string } name Name of the documentation
245247 * @return {DocumentationModel }
246248 */
247- AmfLoader . lookupDocumentation = function ( model , name ) {
249+ AmfLoader . lookupDocumentation = ( model , name ) => {
248250 helper . amf = model ;
249251 const webApi = helper . _computeApi ( model ) ;
250252 const key = helper . _getAmfKey ( helper . ns . aml . vocabularies . core . documentation ) ;
@@ -262,7 +264,7 @@ AmfLoader.lookupDocumentation = function(model, name) {
262264 * @param {ApiModel } model Api model.
263265 * @return {EncodeModel[] }
264266 */
265- AmfLoader . lookupEncodes = function ( model ) {
267+ AmfLoader . lookupEncodes = ( model ) => {
266268 if ( model instanceof Array ) {
267269 model = model [ 0 ] ;
268270 }
0 commit comments