Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.
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
6 changes: 6 additions & 0 deletions packages/fury-adapter-oas3-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Fury OAS3 Parser Changelog

## Master

### Enhancements

- Added support for `info.license` (License Object).

## 0.9.1 (2019-08-08)

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion packages/fury-adapter-oas3-parser/STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Key:
| description | ✓ |
| termsOfService | [✕](https://github.com/apiaryio/api-elements.js/issues/78) |
| contact | [✕](https://github.com/apiaryio/api-elements.js/issues/79) |
| license | [✕](https://github.com/apiaryio/api-elements.js/issues/80) |
| license | |
| version | ✓ |

## Paths Object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ const {
createInvalidMemberWarning,
} = require('../annotations');
const {
isObject, hasKey, isExtension,
isObject, hasKey, getValue, isExtension,
} = require('../../predicates');
const parseObject = require('../parseObject');
const parseString = require('../parseString');
const parseCopy = require('../parseCopy');
const pipeParseResult = require('../../pipeParseResult');
const parseLicenseObject = require('./parseLicenseObject');

const name = 'Info Object';
const requiredKeys = ['title', 'version'];
const unsupportedKeys = ['termsOfService', 'contact', 'license'];
const unsupportedKeys = ['termsOfService', 'contact'];

/**
* Returns whether the given member element is unsupported
Expand All @@ -38,6 +39,7 @@ function parseInfo(context, info) {
[hasKey('title'), parseString(context, name, true)],
[hasKey('version'), parseString(context, name, true)],
[hasKey('description'), parseCopy(context, name, false)],
[hasKey('license'), R.compose(parseLicenseObject(context), getValue)],
[isUnsupportedKey, createUnsupportedMemberWarning(namespace, name)],

// FIXME Support exposing extensions into parse result
Expand All @@ -60,6 +62,10 @@ function parseInfo(context, info) {
api.push(info.get('description'));
}

if (info.get('license')) {
api.links.push(info.get('license'));
}

return api;
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

const R = require('ramda');
const { createWarning } = require('../../elements');
const {
createInvalidMemberWarning,
} = require('../annotations');
const {
isObject, hasKey, isExtension,
} = require('../../predicates');
const parseObject = require('../parseObject');
const parseString = require('../parseString');
const pipeParseResult = require('../../pipeParseResult');

const name = 'License Object';
const requiredKeys = ['name'];

const parseMember = context => R.cond([
[hasKey('name'), parseString(context, name, false)],
[hasKey('url'), parseString(context, name, false)],
[isExtension, () => new context.namespace.elements.ParseResult()],
[R.T, createInvalidMemberWarning(context.namespace, name)],
]);

/**
* Parse the OpenAPI 'License Object' (`#/info/license`)
* @see http://spec.openapis.org/oas/v3.0.2#license-object
* @returns ParseResult<Link>
* @private
*/
const parseLicenseObject = context => pipeParseResult(context.namespace,
R.unless(isObject, createWarning(context.namespace, `'${name}' is not an object`)),
parseObject(context, name, parseMember(context), requiredKeys, [], true),
(object) => {
const link = new context.namespace.elements.Link();
link.relation = 'license';
link.title = object.get('name');
link.href = object.getValue('url') || 'http://purl.org/atompub/license#unspecified';
return link;
});

module.exports = parseLicenseObject;
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@
"title": {
"element": "string",
"content": "Swagger Petstore"
},
"links": {
"element": "array",
"content": [
{
"element": "link",
"meta": {
"title": {
"element": "string",
"content": "MIT"
}
},
"attributes": {
"relation": {
"element": "string",
"content": "license"
},
"href": {
"element": "string",
"content": "http://purl.org/atompub/license#unspecified"
}
}
}
]
}
},
"attributes": {
Expand Down Expand Up @@ -527,66 +551,6 @@
}
]
},
{
"element": "annotation",
"meta": {
"classes": {
"element": "array",
"content": [
{
"element": "string",
"content": "warning"
}
]
}
},
"attributes": {
"sourceMap": {
"element": "array",
"content": [
{
"element": "sourceMap",
"content": [
{
"element": "array",
"content": [
{
"element": "number",
"attributes": {
"line": {
"element": "number",
"content": 5
},
"column": {
"element": "number",
"content": 3
}
},
"content": 68
},
{
"element": "number",
"attributes": {
"line": {
"element": "number",
"content": 5
},
"column": {
"element": "number",
"content": 10
}
},
"content": 7
}
]
}
]
}
]
}
},
"content": "'Info Object' contains unsupported key 'license'"
},
{
"element": "annotation",
"meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,55 @@
}
},
"content": "Swagger Petstore"
},
"links": {
"element": "array",
"content": [
{
"element": "link",
"meta": {
"title": {
"element": "string",
"attributes": {
"sourceMap": {
"element": "array",
"content": [
{
"element": "sourceMap",
"content": [
{
"element": "array",
"content": [
{
"element": "number",
"content": 87
},
{
"element": "number",
"content": 3
}
]
}
]
}
]
}
},
"content": "MIT"
}
},
"attributes": {
"relation": {
"element": "string",
"content": "license"
},
"href": {
"element": "string",
"content": "http://purl.org/atompub/license#unspecified"
}
}
}
]
}
},
"attributes": {
Expand Down Expand Up @@ -1277,66 +1326,6 @@
}
]
},
{
"element": "annotation",
"meta": {
"classes": {
"element": "array",
"content": [
{
"element": "string",
"content": "warning"
}
]
}
},
"attributes": {
"sourceMap": {
"element": "array",
"content": [
{
"element": "sourceMap",
"content": [
{
"element": "array",
"content": [
{
"element": "number",
"attributes": {
"line": {
"element": "number",
"content": 5
},
"column": {
"element": "number",
"content": 3
}
},
"content": 68
},
{
"element": "number",
"attributes": {
"line": {
"element": "number",
"content": 5
},
"column": {
"element": "number",
"content": 10
}
},
"content": 7
}
]
}
]
}
]
}
},
"content": "'Info Object' contains unsupported key 'license'"
},
{
"element": "annotation",
"meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,6 @@ describe('#parseInfoObject', () => {
expect(parseResult).to.contain.warning("'Info Object' contains unsupported key 'contact'");
});

it('provides warning for unsupported license key', () => {
const object = new namespace.elements.Object({
title: 'My API',
version: '1.0.0',
license: {},
});

const parseResult = parse(context, object);

expect(parseResult).to.contain.warning("'Info Object' contains unsupported key 'license'");
});

it('does not provide warning for Info Object extensions', () => {
const object = new namespace.elements.Object({
title: 'My API',
Expand Down Expand Up @@ -172,4 +160,22 @@ describe('#parseInfoObject', () => {
expect(parseResult.length).to.equal(1);
expect(parseResult.api.copy.toValue()).to.deep.equal(['My API Description']);
});

it('provides api category with license', () => {
const info = new namespace.elements.Object({
title: 'My API',
version: '1.0.0',
license: {
name: 'Apache 2.0',
url: 'https://www.apache.org/licenses/LICENSE-2.0.html',
},
});

const parseResult = parse(context, info);
expect(parseResult.length).to.equal(1);

const license = parseResult.api.links.get(0);
expect(license.relation.toValue()).to.equal('license');
expect(license.href.toValue()).to.equal('https://www.apache.org/licenses/LICENSE-2.0.html');
});
});
Loading