Skip to content

Commit

Permalink
feat: add OpenApi 3.1 support
Browse files Browse the repository at this point in the history
Refs #2
  • Loading branch information
char0n committed Jul 14, 2020
1 parent fe35ab7 commit 9d48576
Show file tree
Hide file tree
Showing 76 changed files with 179 additions and 58 deletions.
10 changes: 5 additions & 5 deletions apidom/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions apidom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"bootstrap": "cross-env lerna bootstrap && npm run link-parent-bin",
"build": "lerna run build",
"lint": "lerna run lint",
"lint:fix": "lerna run lint",
"typescript:check-types": "lerna run typescript:check-types",
"typescript:declaration": "lerna run typescript:declaration",
"clean": "lerna run clean",
Expand Down Expand Up @@ -38,8 +39,8 @@
"@typescript-eslint/eslint-plugin": "=3.0.2",
"@typescript-eslint/parser": "=3.0.2",
"apidom": "file:packages/apidom",
"apidom-ns-openapi3": "file:packages/apidom-ns-openapi3",
"apidom-parser-adapter-openapi3": "file:packages/apidom-parser-adapter-openapi3",
"apidom-ns-openapi3-1": "file:packages/apidom-ns-openapi3-1",
"apidom-parser-adapter-openapi3-1": "file:packages/apidom-parser-adapter-openapi3-1",
"babel-loader": "=8.1.0",
"core-js": "=3.6.5",
"cross-env": "=7.0.2",
Expand All @@ -64,8 +65,8 @@
},
"dependencies": {
"apidom": "file:packages/apidom",
"apidom-ns-openapi3": "file:packages/apidom-ns-openapi3",
"apidom-ns-openapi3-1": "file:packages/apidom-ns-openapi3-1",
"apidom-parser": "file:packages/apidom-parser",
"apidom-parser-adapter-openapi3": "file:packages/apidom-parser-adapter-openapi3"
"apidom-parser-adapter-openapi3-1": "file:packages/apidom-parser-adapter-openapi3-1"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const browser = {
},
output: {
path: path.resolve('./dist'),
filename: 'apidom-ns-openapi3.browser.js',
filename: 'apidom-ns-openapi3-1.browser.js',
libraryTarget: 'umd',
library: 'apidomNsOpenapi3',
},
Expand Down Expand Up @@ -44,7 +44,7 @@ const browserMin = {
target: 'web',
output: {
path: path.resolve('./dist'),
filename: 'apidom-ns-openapi3.browser.min.js',
filename: 'apidom-ns-openapi3-1.browser.min.js',
libraryTarget: 'umd',
library: 'apidomNsOpenapi3',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const node = {
target: 'node',
output: {
path: path.resolve('./dist'),
filename: 'apidom-ns-openapi3.node.js',
filename: 'apidom-ns-openapi3-1.node.js',
libraryTarget: 'umd',
library: 'apidom',
},
Expand Down Expand Up @@ -40,7 +40,7 @@ const nodeMin = {
target: 'node',
output: {
path: path.resolve('./dist'),
filename: 'apidom-ns-openapi3.node.min.js',
filename: 'apidom-ns-openapi3-1.node.min.js',
libraryTarget: 'umd',
library: 'apidom',
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "apidom-ns-openapi3",
"name": "apidom-ns-openapi3-1",
"version": "0.1.0",
"description": "OpenAPI3 profile for ApiDOM",
"description": "OpenAPI 3.1 profile for ApiDOM",
"main": "lib/namespace.js",
"module": "es/namespace.js",
"jsnext:main": "es/namespace.js",
"browser": "dist/apidom-ns-openapi3.browser.js",
"unpkg": "dist/apidom-ns-openapi3.browser.min.js",
"browser": "dist/apidom-ns-openapi3-1.browser.js",
"unpkg": "dist/apidom-ns-openapi3-1.browser.min.js",
"types": "types/namespace.d.ts",
"scripts": {
"build": "cross-env npm run build:es && npm run build:commonjs && npm run build:umd",
"build": "npm run typescript:declaration && npm run build:es && npm run build:commonjs && npm run build:umd",
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es --extensions '.ts' --root-mode 'upward'",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib --extensions '.ts' --root-mode 'upward'",
"build:umd": "cross-env npm run build:umd:node && npm run build:umd:browser",
"build:umd": "npm run build:umd:node && npm run build:umd:browser",
"build:umd:node": "cross-env BABEL_ENV=node webpack --config config/webpack/node.config.js --progress",
"build:umd:browser": "cross-env BABEL_ENV=browser webpack --config config/webpack/browser.config.js --progress",
"lint": "eslint ./",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class Info extends ObjectElement {
this.set('description', description);
}

get summary(): string {
return this.get('summary');
}

set summary(description: string) {
this.set('summary', description);
}

get termsOfService(): string {
return this.get('termsOfService');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ class License extends ObjectElement {
this.set('name', name);
}

get identifier(): string {
return this.get('identifier');
}

set identifier(name: string) {
this.set('identifier', name);
}

get url(): string {
return this.get('url');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/lib
/types
/config
/.eslintrc.js
/.nyc_output
/node_modules
/**/*.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const browser = {
},
output: {
path: path.resolve('./dist'),
filename: 'apidom-parser-adapter-openapi3.browser.js',
filename: 'apidom-parser-adapter-openapi3-1.browser.js',
libraryTarget: 'umd',
library: 'apidom',
},
Expand Down Expand Up @@ -44,7 +44,7 @@ const browserMin = {
target: 'web',
output: {
path: path.resolve('./dist'),
filename: 'apidom-parser-adapter-openapi3.browser.min.js',
filename: 'apidom-parser-adapter-openapi3-1.browser.min.js',
libraryTarget: 'umd',
library: 'apidom',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const node = {
target: 'node',
output: {
path: path.resolve('./dist'),
filename: 'apidom-parser-adapter-openapi3.node.js',
filename: 'apidom-parser-adapter-openapi3-1.node.js',
libraryTarget: 'umd',
library: 'apidom',
},
Expand Down Expand Up @@ -40,7 +40,7 @@ const nodeMin = {
target: 'node',
output: {
path: path.resolve('./dist'),
filename: 'apidom-parser-adapter-openapi3.node.min.js',
filename: 'apidom-parser-adapter-openapi3-1.node.min.js',
libraryTarget: 'umd',
library: 'apidom',
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "apidom-parser-adapter-openapi3",
"name": "apidom-parser-adapter-openapi3-1",
"version": "0.1.0",
"description": "OpenAPI3 adapter for ApiDOM parser",
"description": "OpenAPI 3.1 adapter for ApiDOM parser",
"main": "lib/adapter.js",
"module": "es/adapter.js",
"jsnext:main": "es/adapter.js",
"browser": "dist/apidom-parser-adapter-openapi3.browser.js",
"unpkg": "dist/apidom-parser-apdater-openapi3.browser.min.js",
"browser": "dist/apidom-parser-adapter-openapi3-1.browser.js",
"unpkg": "dist/apidom-parser-apdater-openapi3-1.browser.min.js",
"scripts": {
"build": "cross-env npm run build:es && npm run build:commonjs && npm run build:umd",
"build": "npm run build:es && npm run build:commonjs && npm run build:umd",
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es --extensions '.ts' --root-mode 'upward'",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib --extensions '.ts' --root-mode 'upward'",
"build:umd": "cross-env npm run build:umd:node && npm run build:umd:browser",
"build:umd": "npm run build:umd:node && npm run build:umd:browser",
"build:umd:node": "cross-env BABEL_ENV=node webpack --config config/webpack/node.config.js --progress",
"build:umd:browser": "cross-env BABEL_ENV=browser webpack --config config/webpack/browser.config.js --progress",
"lint": "eslint ./",
Expand All @@ -23,7 +23,7 @@
"license": "Apache-2.0",
"dependencies": {
"apidom": "file:../apidom",
"apidom-ns-openapi3": "file:../apidom-ns-openapi3",
"apidom-ns-openapi3-1": "file:../apidom-ns-openapi3-1",
"json-ast": "=2.1.7",
"ramda": "=0.27.0",
"ramda-adjunct": "=2.26.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as apiDOM from 'apidom';
import openapi3 from 'apidom-ns-openapi3';
import openapi3_1 from 'apidom-ns-openapi3-1';
import * as jsonAst from 'json-ast';
import specification from './specification';
import { visit } from './visitor';
Expand All @@ -8,7 +8,7 @@ const parse = (
source: string,
{ sourceMap = false, verbose = true, junker = true, specObj = specification } = {},
) => {
const namespace = apiDOM.createNamespace(openapi3);
const namespace = apiDOM.createNamespace(openapi3_1);
const parseResultElement = new namespace.elements.ParseResult();
const documentVisitor = specObj.visitors.document.$visitor();
let ast = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import OpenapiVisitor from './visitors/OpenapiVisitor';
import InfoVisitor from './visitors/info';
import InfoTitleVisitor from './visitors/info/TitleVisitor';
import InfoDescriptionVisitor from './visitors/info/DescriptionVisitor';
import InfoSummaryVisitor from './visitors/info/SummaryVisitor';
import InfoTermsOfServiceVisitor from './visitors/info/TermsOfServiceVisitor';
import InfoVersionVisitor from './visitors/info/VersionVisitor';
import ContactVisitor from './visitors/info/contact';
Expand All @@ -14,6 +15,7 @@ import ContactUrlVisitor from './visitors/info/contact/UrlVisitor';
import ContactEmailVisitor from './visitors/info/contact/EmailVisitor';
import LicenseVisitor from './visitors/info/license';
import LicenseNameVisitor from './visitors/info/license/NameVisitor';
import LicenseIdentifierVisitor from './visitors/info/license/IdentifierVisitor';
import LicenseUrlVisitor from './visitors/info/license/UrlVisitor';
import ComponentsVisitor from './visitors/components';
import SchemasVisitor from './visitors/components/SchemasVisitor';
Expand Down Expand Up @@ -43,6 +45,7 @@ const specification = {
$visitor: InfoVisitor,
title: InfoTitleVisitor,
description: InfoDescriptionVisitor,
summary: InfoSummaryVisitor,
termsOfService: InfoTermsOfServiceVisitor,
version: InfoVersionVisitor,
contact: {
Expand All @@ -54,6 +57,7 @@ const specification = {
license: {
$visitor: LicenseVisitor,
name: LicenseNameVisitor,
identifier: LicenseIdentifierVisitor,
url: LicenseUrlVisitor,
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import stampit from 'stampit';
import SpecificationVisitor from '../SpecificationVisitor';
import { BREAK } from '../../visitor';

const SummaryVisitor = stampit(SpecificationVisitor, {
methods: {
property(propertyNode) {
const keyElement = new this.namespace.elements.String(propertyNode.key.value);
const valueElement = new this.namespace.elements.String(propertyNode.value.value);
const { MemberElement } = this.namespace.elements.Element.prototype;

this.element = new MemberElement(
this.maybeAddSourceMap(propertyNode.key, keyElement),
this.maybeAddSourceMap(propertyNode.value, valueElement),
);

return BREAK;
},
},
});

export default SummaryVisitor;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const InfoVisitor = stampit(SpecificationVisitor, {
const supportedProps = [
'title',
'description',
'summary',
'termsOfService',
'version',
'contact',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import stampit from 'stampit';
import SpecificationVisitor from '../../SpecificationVisitor';
import { BREAK } from '../../../visitor';

const IdentifierVisitor = stampit(SpecificationVisitor, {
methods: {
property(propertyNode) {
const keyElement = new this.namespace.elements.String(propertyNode.key.value);
const valueElement = new this.namespace.elements.String(propertyNode.value.value);
const { MemberElement } = this.namespace.elements.Element.prototype;

this.element = new MemberElement(
this.maybeAddSourceMap(propertyNode.key, keyElement),
this.maybeAddSourceMap(propertyNode.value, valueElement),
);

return BREAK;
},
},
});

export default IdentifierVisitor;
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const LicenseVisitor = stampit(SpecificationVisitor, {
const commentVisitor = this.retrieveVisitorInstance(['document', 'comment']);

objectNode.properties.forEach((propertyNode) => {
if (['name', 'url'].includes(propertyNode.key.value)) {
if (['name', 'identifier', 'url'].includes(propertyNode.key.value)) {
licenseElement.content.push(
this.mapPropertyNodeToMemberElement(
['document', 'openApi', 'info', 'license', propertyNode.key.value],
Expand Down
35 changes: 35 additions & 0 deletions apidom/packages/apidom-parser-adapter-openapi3-1/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"env": {
"mocha": true
},
"globals": {
"document": true
},
"plugins": [
"mocha"
],
"rules": {
"no-void": 0,
"func-names": 0,
"prefer-arrow-callback": 0,
"no-array-constructor": 0,
"prefer-rest-params": 0,
"no-new-wrappers": 0,
"mocha/no-skipped-tests": 2,
"mocha/handle-done-callback": 2,
"mocha/valid-suite-description": 2,
"mocha/no-mocha-arrows": 2,
"mocha/no-hooks-for-single-case": 2,
"mocha/no-sibling-hooks": 2,
"mocha/no-top-level-hooks": 2,
"mocha/no-identical-title": 2,
"mocha/no-nested-tests": 2,
"mocha/no-exclusive-tests": 2
},
"overrides": [{
"files": ["mocha-bootstrap.js"],
"parserOptions": {
"sourceType": "script"
}
}]
}
Loading

0 comments on commit 9d48576

Please sign in to comment.