Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function processFile(doc, file, type, destPath, resolution, flattened) {
// @ts-ignore
let compactOpts = amf.render.RenderOptions().withSourceMaps.withCompactUris;
if (flattened) {
compactOpts = fullOpts.withFlattenedJsonLd;
compactOpts = compactOpts.withFlattenedJsonLd;
}
// withRawSourceMaps.
const compactData = await generator.generateString(doc, compactOpts);
Expand Down
170 changes: 92 additions & 78 deletions 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,6 +1,6 @@
{
"name": "@api-components/api-model-generator",
"version": "0.2.12",
"version": "0.2.13",
"description": "AMF model generator for API components",
"main": "index.js",
"scripts": {
Expand Down
27 changes: 20 additions & 7 deletions test/api-generation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ describe('API generation', () => {
describe('Api list config file with options', () => {
const modelFile = path.join(dest, 'raml1.json');
const compactModelFile = path.join(dest, 'raml1-compact.json');
const flattenedModelFile = path.join(dest, 'flattenedApi-compact.json');
const flattenedModelFile = path.join(dest, 'flattenedApi.json');
const compactFlattenedModelFile = path.join(dest, 'flattenedApi-compact.json');
const configFile = path.join('test', 'apis-options.json');

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

it('Generates data model for compact model', () => generator(configFile)
it('Generates flattened data model for compact model', () => generator(configFile)
.then(() => fs.pathExists(compactModelFile))
.then((exists) => assert.isTrue(exists))
.then(() => fs.readJson(compactModelFile))
.then((data) => {
assert.typeOf(data, 'array');
}));

it('Generates flattened data model for regular model', () => generator(configFile)
.then(() => fs.pathExists(flattenedModelFile))
.then((exists) => assert.isTrue(exists))
.then(() => fs.readJson(flattenedModelFile))
.then((data) => {
const graph = data['@graph'];
assert.isDefined(graph);
const ctx = data['@context'];
assert.isUndefined(ctx);
}));


it('Generates flattened data model', () => generator(configFile)
.then(() => fs.pathExists(compactModelFile))
it('Generates flattened data model for compact model', () => generator(configFile)
.then(() => fs.pathExists(compactFlattenedModelFile))
.then((exists) => assert.isTrue(exists))
.then(() => fs.readJson(compactModelFile))
.then(() => fs.readJson(compactFlattenedModelFile))
.then((data) => {
assert.typeOf(data, 'array');
const graph = data['@graph'];
assert.isDefined(graph);
const ctx = data['@context'];
assert.typeOf(ctx, 'object');
}));
});

Expand Down