@swagger-api/apidom-parser-adapter-openapi-json-3-1 0.68.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +363 -0
- package/LICENSES/Apache-2.0.txt +202 -0
- package/LICENSES/MIT.txt +9 -0
- package/NOTICE +57 -0
- package/README.md +86 -0
- package/cjs/adapter.cjs +35 -0
- package/cjs/media-types.cjs +8 -0
- package/dist/7c7ca323880d9fa6e48d1d1b2e78e140.wasm +0 -0
- package/dist/apidom-parser-adapter-openapi-json-3-1.browser.js +47654 -0
- package/dist/apidom-parser-adapter-openapi-json-3-1.browser.min.js +1 -0
- package/dist/fba0b3cc0d7ee926ea482deee298a5fe.wasm +0 -0
- package/es/adapter.js +23 -0
- package/es/media-types.js +3 -0
- package/package.json +64 -0
- package/types/dist.d.ts +12 -0
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @swagger-api/apidom-parser-adapter-openapi-json-3-1
|
|
2
|
+
|
|
3
|
+
`@swagger-api/apidom-parser-adapter-openapi-json-3-1` is a parser adapter for the [OpenApi 3.1.0 specification](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md) in [JSON format](https://www.json.org/json-en.html).
|
|
4
|
+
Under the hood this adapter uses [apidom-parser-adapter-json](https://github.com/swagger-api/apidom/tree/main/packages/apidom-parser-adapter-json)
|
|
5
|
+
to parse a source string into generic ApiDOM in [base ApiDOM namespace](https://github.com/swagger-api/apidom/tree/main/packages/apidom#base-namespace)
|
|
6
|
+
which is then refracted with [OpenApi 3.1.0 Refractors](https://github.com/swagger-api/apidom/tree/main/packages/apidom-ns-openapi-3-1#refractors).
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
After [prerequisites](https://github.com/swagger-api/apidom/blob/main/README.md#prerequisites) for installing this package are satisfied, you can install it
|
|
11
|
+
via [npm CLI](https://docs.npmjs.com/cli) by running the following command:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
$ npm install @swagger-api/apidom-parser-adapter-openapi-json-3-1
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Parser adapter API
|
|
18
|
+
|
|
19
|
+
This parser adapter is fully compatible with parser adapter interface required by [@swagger-api/apidom-parser](https://github.com/swagger-api/apidom/tree/main/packages/apidom-parser#mounting-parser-adapters)
|
|
20
|
+
and implements all required properties.
|
|
21
|
+
|
|
22
|
+
### mediaTypes
|
|
23
|
+
|
|
24
|
+
Defines list of media types that this parser adapter recognizes.
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
[
|
|
28
|
+
'application/vnd.oai.openapi;version=3.1.0',
|
|
29
|
+
'application/vnd.oai.openapi+json;version=3.1.0',
|
|
30
|
+
]
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### detect
|
|
34
|
+
|
|
35
|
+
[Detection](https://github.com/swagger-api/apidom/blob/main/packages/apidom-parser-adapter-openapi-json-3-1/src/adapter.ts#L13) is based on a regular expression matching required OpenApi 3.1.0 specification symbols in JSON format.
|
|
36
|
+
|
|
37
|
+
### namespace
|
|
38
|
+
|
|
39
|
+
This adapter exposes an instance of [OpenApi 3.1.0 ApiDOM namespace](https://github.com/swagger-api/apidom/tree/main/packages/apidom-ns-openapi-3-1#openapi-310-namespace).
|
|
40
|
+
|
|
41
|
+
### parse
|
|
42
|
+
|
|
43
|
+
`parse` function consumes various options as a second argument. Here is a list of these options:
|
|
44
|
+
|
|
45
|
+
Option | Type | Default | Description
|
|
46
|
+
--- | --- | --- | ---
|
|
47
|
+
<a name="specObj"></a>`specObj` | `Object` | [Specification Object](https://github.com/swagger-api/apidom/blob/main/packages/apidom-ns-openapi-3-1/src/refractor/specification.ts) | This specification object drives the JSON AST transformation to OpenAPI 3.1.0 ApiDOM namespace.
|
|
48
|
+
<a name="sourceMap"></a>`sourceMap` | `Boolean` | `false` | Indicate whether to generate source maps.
|
|
49
|
+
<a name="refractorOpts"></a>`refractorOpts` | `Object` | `{}` | Refractor options are [passed to refractors](https://github.com/swagger-api/apidom/tree/main/packages/apidom-ns-openapi-3-1#refractor-plugins) during refracting phase.
|
|
50
|
+
|
|
51
|
+
All unrecognized arbitrary options will be ignored.
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
This parser adapter can be used directly or indirectly via [@swagger-api/apidom-parser](https://github.com/swagger-api/apidom/tree/main/packages/apidom-parser).
|
|
56
|
+
|
|
57
|
+
### Direct usage
|
|
58
|
+
|
|
59
|
+
During direct usage you don't need to provide `mediaType` as the `parse` function is already pre-bound
|
|
60
|
+
with [supported media types](#mediatypes).
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import { parse, detect } from '@swagger-api/apidom-parser-adapter-openapi-json-3-1';
|
|
64
|
+
|
|
65
|
+
// detecting
|
|
66
|
+
await detect('{"openapi": "3.1.0"}'); // => true
|
|
67
|
+
await detect('test'); // => false
|
|
68
|
+
|
|
69
|
+
// parsing
|
|
70
|
+
const parseResult = await parse('{"openapi": "3.1.0"}', { sourceMap: true });
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Indirect usage
|
|
74
|
+
|
|
75
|
+
You can omit the `mediaType` option here, but please read [Word on detect vs mediaTypes](https://github.com/swagger-api/apidom/tree/main/packages/apidom-parser#word-on-detect-vs-mediatypes) before you do so.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
import ApiDOMParser from '@swagger-api/apidom-parser';
|
|
79
|
+
import * as openApiJsonAdapter from '@swagger-api/apidom-parser-adapter-openapi-json-3-1';
|
|
80
|
+
|
|
81
|
+
const parser = ApiDOMParser();
|
|
82
|
+
|
|
83
|
+
parser.use(openApiJsonAdapter);
|
|
84
|
+
|
|
85
|
+
const parseResult = await parser.parse('{"openapi": "3.1.0"}', { mediaType: openApiJsonAdapter.mediaTypes.latest('json') });
|
|
86
|
+
```
|
package/cjs/adapter.cjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.parse = exports.namespace = exports.mediaTypes = exports.detectionRegExp = exports.detect = void 0;
|
|
6
|
+
var _ramda = require("ramda");
|
|
7
|
+
var _ramdaAdjunct = require("ramda-adjunct");
|
|
8
|
+
var _apidomCore = require("@swagger-api/apidom-core");
|
|
9
|
+
var _apidomParserAdapterJson = require("@swagger-api/apidom-parser-adapter-json");
|
|
10
|
+
var _apidomNsOpenapi = _interopRequireWildcard(require("@swagger-api/apidom-ns-openapi-3-1"));
|
|
11
|
+
var _mediaTypes = _interopRequireDefault(require("./media-types.cjs"));
|
|
12
|
+
exports.mediaTypes = _mediaTypes.default;
|
|
13
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
+
const detectionRegExp = /"openapi"\s*:\s*"(?<version_json>3\.1\.(?:[1-9]\d*|0))"/;
|
|
16
|
+
exports.detectionRegExp = detectionRegExp;
|
|
17
|
+
const detect = async source => detectionRegExp.test(source) && (await (0, _apidomParserAdapterJson.detect)(source));
|
|
18
|
+
exports.detect = detect;
|
|
19
|
+
const parse = async (source, options = {}) => {
|
|
20
|
+
const refractorOpts = (0, _ramda.propOr)({}, 'refractorOpts', options);
|
|
21
|
+
const parserOpts = (0, _ramda.omit)(['refractorOpts'], options);
|
|
22
|
+
const parseResultElement = await (0, _apidomParserAdapterJson.parse)(source, parserOpts);
|
|
23
|
+
const {
|
|
24
|
+
result
|
|
25
|
+
} = parseResultElement;
|
|
26
|
+
if ((0, _ramdaAdjunct.isNotUndefined)(result)) {
|
|
27
|
+
const openApiElement = _apidomNsOpenapi.OpenApi3_1Element.refract(result, refractorOpts);
|
|
28
|
+
openApiElement.classes.push('result');
|
|
29
|
+
parseResultElement.replaceResult(openApiElement);
|
|
30
|
+
}
|
|
31
|
+
return parseResultElement;
|
|
32
|
+
};
|
|
33
|
+
exports.parse = parse;
|
|
34
|
+
const namespace = (0, _apidomCore.createNamespace)(_apidomNsOpenapi.default);
|
|
35
|
+
exports.namespace = namespace;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-1");
|
|
6
|
+
const jsonMediaTypes = new _apidomNsOpenapi.OpenAPIMediaTypes(..._apidomNsOpenapi.mediaTypes.filterByFormat('generic'), ..._apidomNsOpenapi.mediaTypes.filterByFormat('json'));
|
|
7
|
+
var _default = jsonMediaTypes;
|
|
8
|
+
exports.default = _default;
|
|
Binary file
|