Skip to content

Commit 3ffc00c

Browse files
Fix/compact flattened model generation (#7)
* fix: was overwriting compact opts with fullOpts in flattened mode * 0.2.13 * chore: regenerate package-lock.json
1 parent 7e863aa commit 3ffc00c

4 files changed

Lines changed: 114 additions & 87 deletions

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async function processFile(doc, file, type, destPath, resolution, flattened) {
7575
// @ts-ignore
7676
let compactOpts = amf.render.RenderOptions().withSourceMaps.withCompactUris;
7777
if (flattened) {
78-
compactOpts = fullOpts.withFlattenedJsonLd;
78+
compactOpts = compactOpts.withFlattenedJsonLd;
7979
}
8080
// withRawSourceMaps.
8181
const compactData = await generator.generateString(doc, compactOpts);

package-lock.json

Lines changed: 92 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@api-components/api-model-generator",
3-
"version": "0.2.12",
3+
"version": "0.2.13",
44
"description": "AMF model generator for API components",
55
"main": "index.js",
66
"scripts": {

test/api-generation.test.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ describe('API generation', () => {
154154
describe('Api list config file with options', () => {
155155
const modelFile = path.join(dest, 'raml1.json');
156156
const compactModelFile = path.join(dest, 'raml1-compact.json');
157-
const flattenedModelFile = path.join(dest, 'flattenedApi-compact.json');
157+
const flattenedModelFile = path.join(dest, 'flattenedApi.json');
158+
const compactFlattenedModelFile = path.join(dest, 'flattenedApi-compact.json');
158159
const configFile = path.join('test', 'apis-options.json');
159160

160161
afterEach(() => fs.remove(dest));
@@ -167,22 +168,34 @@ describe('API generation', () => {
167168
assert.typeOf(data, 'array');
168169
}));
169170

170-
it('Generates data model for compact model', () => generator(configFile)
171+
it('Generates flattened data model for compact model', () => generator(configFile)
172+
.then(() => fs.pathExists(compactModelFile))
173+
.then((exists) => assert.isTrue(exists))
174+
.then(() => fs.readJson(compactModelFile))
175+
.then((data) => {
176+
assert.typeOf(data, 'array');
177+
}));
178+
179+
it('Generates flattened data model for regular model', () => generator(configFile)
171180
.then(() => fs.pathExists(flattenedModelFile))
172181
.then((exists) => assert.isTrue(exists))
173182
.then(() => fs.readJson(flattenedModelFile))
174183
.then((data) => {
175184
const graph = data['@graph'];
176185
assert.isDefined(graph);
186+
const ctx = data['@context'];
187+
assert.isUndefined(ctx);
177188
}));
178189

179-
180-
it('Generates flattened data model', () => generator(configFile)
181-
.then(() => fs.pathExists(compactModelFile))
190+
it('Generates flattened data model for compact model', () => generator(configFile)
191+
.then(() => fs.pathExists(compactFlattenedModelFile))
182192
.then((exists) => assert.isTrue(exists))
183-
.then(() => fs.readJson(compactModelFile))
193+
.then(() => fs.readJson(compactFlattenedModelFile))
184194
.then((data) => {
185-
assert.typeOf(data, 'array');
195+
const graph = data['@graph'];
196+
assert.isDefined(graph);
197+
const ctx = data['@context'];
198+
assert.typeOf(ctx, 'object');
186199
}));
187200
});
188201

0 commit comments

Comments
 (0)