@@ -20,9 +20,10 @@ amf.plugins.features.AMFValidation.register();
2020 * @param {string } type
2121 * @param {string } destPath
2222 * @param {string } resolution
23+ * @param {boolean } flattened
2324 * @return {Promise<void> }
2425 */
25- async function processFile ( doc , file , type , destPath , resolution ) {
26+ async function processFile ( doc , file , type , destPath , resolution , flattened ) {
2627 let validateProfile ;
2728 switch ( type ) {
2829 case 'RAML 1.0' : validateProfile = amf . ProfileNames . RAML ; break ;
@@ -63,13 +64,19 @@ async function processFile(doc, file, type, destPath, resolution) {
6364 const compactFile = path . join ( destPath , compactDest ) ;
6465
6566 // @ts -ignore
66- const fullOpts = amf . render . RenderOptions ( ) . withSourceMaps ;
67+ let fullOpts = amf . render . RenderOptions ( ) . withSourceMaps ;
68+ if ( flattened ) {
69+ fullOpts = fullOpts . withFlattenedJsonLd ;
70+ }
6771 const fullData = await generator . generateString ( doc , fullOpts ) ;
6872 await fs . ensureFile ( fullFile ) ;
6973 await fs . writeFile ( fullFile , fullData , 'utf8' ) ;
7074
7175 // @ts -ignore
72- const compactOpts = amf . render . RenderOptions ( ) . withSourceMaps . withCompactUris ;
76+ let compactOpts = amf . render . RenderOptions ( ) . withSourceMaps . withCompactUris ;
77+ if ( flattened ) {
78+ compactOpts = fullOpts . withFlattenedJsonLd ;
79+ }
7380 // withRawSourceMaps.
7481 const compactData = await generator . generateString ( doc , compactOpts ) ;
7582 await fs . ensureFile ( compactFile ) ;
@@ -83,9 +90,9 @@ async function processFile(doc, file, type, destPath, resolution) {
8390 */
8491function normalizeOptions ( input ) {
8592 if ( Array . isArray ( input ) ) {
86- const [ type , mime , resolution ] = input ;
93+ const [ type , mime , resolution , flattened ] = input ;
8794 // @ts -ignore
88- return { type, mime, resolution } ;
95+ return { type, mime, resolution, flattened } ;
8996 }
9097 if ( typeof input === 'object' ) {
9198 return input ;
@@ -111,10 +118,10 @@ async function parseFile(file, cnf, opts) {
111118 if ( ! dest . endsWith ( '/' ) ) {
112119 dest += '/' ;
113120 }
114- const { type, mime= 'application/yaml' , resolution= 'editing' } = normalizeOptions ( cnf ) ;
121+ const { type, mime= 'application/yaml' , resolution= 'editing' , flattened = false } = normalizeOptions ( cnf ) ;
115122 const parser = amf . Core . parser ( type , mime ) ;
116123 const doc = await parser . parseFileAsync ( `file://${ src } ${ file } ` ) ;
117- return processFile ( doc , file , type , dest , resolution ) ;
124+ return processFile ( doc , file , type , dest , resolution , flattened ) ;
118125}
119126
120127/**
0 commit comments