Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

feat(apib): add format link #534

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions packages/apib-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# API Elements: API Blueprint Parser Changelog

## Master

### Enhancements

- added a Link element to the specific format/version in the parse result.

## 0.20.1 (2020-08-05)

Adds compatibility for @apielements/core 0.2.0.
Expand Down
22 changes: 19 additions & 3 deletions packages/apib-parser/lib/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function validate({ source, requireBlueprintName }) {
*/
function parse({
source, generateSourceMap, generateMessageBody, generateMessageBodySchema,
requireBlueprintName,
requireBlueprintName, namespace,
}) {
const options = {
exportSourcemap: !!generateSourceMap,
Expand All @@ -42,9 +42,25 @@ function parse({
requireBlueprintName,
};

return drafter.parse(source, options);
return drafter.parse(source, options).then((result) => {
const parseResult = namespace.fromRefract(result);
const { Link } = namespace.elements;
const link = new Link();

link.title = 'API Blueprint';
link.relation = 'via';
link.href = 'https://apiblueprint.org/';

parseResult.links.push(link);

return parseResult;
});
}

module.exports = {
name, mediaTypes, detect, validate, parse,
name,
mediaTypes,
detect,
validate,
parse,
};
14 changes: 13 additions & 1 deletion packages/apib-parser/test/adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,23 @@ describe('API Blueprint parser adapter', () => {
});

it('has API category inside parse result', () => {
const filtered = result.children.filter(item => item.element === 'category' && item.classes.includes('api'));
const filtered = result.children.filter(
item => item.element === 'category' && item.classes.includes('api')
);

expect(filtered).to.have.length(1);
expect(filtered.first).to.be.an('object');
});

it('has the format link', () => {
const link = result.links.get(0);

expect(link.relation.toValue()).to.equal('via');
expect(link.title.toValue()).to.equal('API Blueprint');
expect(link.href.toValue()).to.equal(
'https://apiblueprint.org/'
);
});
});

it('can parse an API Blueprint with require blueprint name', (done) => {
Expand Down