Skip to content

Commit 92181e6

Browse files
committed
feat(parser-adapter-asyncapi-yaml-3): add package for parser adapter asyncapi yaml 3
1 parent b068ae3 commit 92181e6

32 files changed

+1957
-0
lines changed

packages/apidom-ls/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "^1.0.0-rc.3",
107107
"@swagger-api/apidom-parser-adapter-asyncapi-json-2": "^1.0.0-rc.3",
108108
"@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "^1.0.0-rc.3",
109+
"@swagger-api/apidom-parser-adapter-asyncapi-yaml-3": "^1.0.0-beta.0",
109110
"@swagger-api/apidom-parser-adapter-json": "^1.0.0-rc.3",
110111
"@swagger-api/apidom-parser-adapter-openapi-json-2": "^1.0.0-rc.3",
111112
"@swagger-api/apidom-parser-adapter-openapi-json-3-0": "^1.0.0-rc.3",

packages/apidom-ls/src/services/validation/validation-service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ export class DefaultValidationService implements ValidationService {
450450

451451
let processedText;
452452
const nameSpace = await findNamespace(text, this.settings?.defaultContentLanguage);
453+
// TODO: Turned off validation, because we will implement it in the future.
454+
if (nameSpace.namespace === 'asyncapi' && nameSpace.version === '3.0.0') {
455+
return [];
456+
}
453457
let docNs: string = nameSpace.namespace;
454458
// no API document has been parsed
455459
if (result.annotations) {

packages/apidom-ls/src/utils/utils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as openapi31xAdapterJson from '@swagger-api/apidom-parser-adapter-opena
66
import * as openapi31xAdapterYaml from '@swagger-api/apidom-parser-adapter-openapi-yaml-3-1';
77
import * as asyncapi2AdapterJson from '@swagger-api/apidom-parser-adapter-asyncapi-json-2';
88
import * as asyncapi2AdapterYaml from '@swagger-api/apidom-parser-adapter-asyncapi-yaml-2';
9+
import * as asyncapi3AdapterYaml from '@swagger-api/apidom-parser-adapter-asyncapi-yaml-3';
910
import * as adsAdapterJson from '@swagger-api/apidom-parser-adapter-api-design-systems-json';
1011
import * as adsAdapterYaml from '@swagger-api/apidom-parser-adapter-api-design-systems-yaml';
1112
import * as adapterJson from '@swagger-api/apidom-parser-adapter-json';
@@ -836,6 +837,19 @@ export async function findNamespace(
836837
};
837838
}
838839

840+
if (await asyncapi3AdapterYaml.detect(text)) {
841+
const asyncapi3YamlMatch = text.match(asyncapi3AdapterYaml.detectionRegExp)!;
842+
const groups = asyncapi3YamlMatch.groups!;
843+
const version = groups.version_json ?? groups.version_yaml;
844+
845+
return {
846+
namespace: 'asyncapi',
847+
version,
848+
format: 'YAML',
849+
mediaType: asyncapi3AdapterYaml.mediaTypes.findBy(version, 'yaml'),
850+
};
851+
}
852+
839853
if (await openapi2AdapterJson.detect(text)) {
840854
const openapi2JsonMatch = text.match(openapi2AdapterJson.detectionRegExp)!;
841855
const groups = openapi2JsonMatch.groups!;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**/*.js
2+
/**/*.mjs
3+
/**/*.cjs
4+
/dist
5+
/types
6+
/config
7+
/.nyc_output
8+
/node_modules
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/src/**/*.mjs
2+
/src/**/*.cjs
3+
/test/**/*.mjs
4+
/dist
5+
/types
6+
/NOTICE
7+
/swagger-api-apidom-parser-adapter-asyncapi-yaml-3-*.tgz
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extensions": ["ts"],
3+
"loader": "ts-node/esm",
4+
"recursive": true,
5+
"spec": "test/**/*.ts",
6+
"file": ["test/mocha-bootstrap.ts"],
7+
"ignore": ["test/perf/**/*.ts"]
8+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
save-prefix="="
2+
save=false
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# @swagger-api/apidom-parser-adapter-asyncapi-yaml-3
2+
3+
`@swagger-api/apidom-parser-adapter-asyncapi-yaml-3` is a parser adapter for following AsyncAPI specification versions defined in [YAML format](https://yaml.org/spec/1.2/spec.html):
4+
5+
- [AsyncAPI 3.0.0 specification](https://github.com/asyncapi/spec/blob/v3.0.0/spec/asyncapi.md)
6+
7+
Under the hood this adapter uses [@swagger-api/apidom-parser-adapter-yaml-1-2](https://github.com/swagger-api/apidom/tree/main/packages/apidom-parser-adapter-yaml-1-2)
8+
to parse a source string into generic ApiDOM in [base ApiDOM namespace](https://github.com/swagger-api/apidom/tree/main/packages/apidom#base-namespace)
9+
10+
[//]: # (// TODO: The below link does not have content yet.)
11+
which is then refracted with [AsyncApi 3.x.y Refractors](https://github.com/swagger-api/apidom/tree/main/packages/apidom-ns-asyncapi-3#refractors).
12+
13+
## Installation
14+
15+
After [prerequisites](https://github.com/swagger-api/apidom/blob/main/README.md#prerequisites) for installing this package are satisfied, you can install it
16+
via [npm CLI](https://docs.npmjs.com/cli) by running the following command:
17+
18+
```sh
19+
$ npm install @swagger-api/@swagger-api/apidom-parser-adapter-asyncapi-yaml-3
20+
```
21+
22+
## Parser adapter API
23+
24+
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)
25+
and implements all required properties.
26+
27+
### mediaTypes
28+
29+
Defines list of media types that this parser adapter recognizes.
30+
31+
```js
32+
[
33+
'application/vnd.aai.asyncapi;version=3.0.0',
34+
'application/vnd.aai.asyncapi+yaml;version=3.0.0',
35+
]
36+
```
37+
38+
### detect
39+
40+
[Detection](https://github.com/swagger-api/apidom/blob/main/packages/apidom-parser-adapter-asyncapi-yaml-3/src/adapter.ts#L13) is based on a regular expression matching required AsyncApi 3.x.y specification symbols in YAML format.
41+
42+
### namespace
43+
44+
[//]: # (// TODO: Below link does not have content yet.)
45+
This adapter exposes an instance of [AsyncApi 3.x.y ApiDOM namespace](https://github.com/swagger-api/apidom/tree/main/packages/apidom-ns-asyncapi-3#asyncapi-2xy-namespace).
46+
47+
### parse
48+
49+
`parse` function consumes various options as a second argument. Here is a list of these options:
50+
51+
Option | Type | Default | Description
52+
--- | --- | --- | ---
53+
<a name="specObj"></a>`specObj` | `Object` | [Specification Object](https://github.com/swagger-api/apidom/blob/main/packages/apidom-ns-asyncapi-3/src/refractor/specification.ts) | This specification object drives the YAML AST transformation to AsyncAPI 3.x ApiDOM namespace.
54+
<a name="sourceMap"></a>`sourceMap` | `Boolean` | `false` | Indicate whether to generate source maps.
55+
<a name="refractorOpts"></a>`refractorOpts` | `Object` | `{}` | Refractor options are [passed to refractors](https://github.com/swagger-api/apidom/tree/main/packages/apidom-ns-asyncapi-3#refractor-plugins) during refracting phase.
56+
57+
All unrecognized arbitrary options will be ignored.
58+
59+
## Usage
60+
61+
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).
62+
63+
### Direct usage
64+
65+
During direct usage you don't need to provide `mediaType` as the `parse` function is already pre-bound
66+
with [supported media types](#mediatypes).
67+
68+
```js
69+
import { parse, detect } from '@swagger-api/apidom-parser-adapter-asyncapi-yaml-3';
70+
71+
// detecting
72+
await detect('asyncapi: 3.0.0'); // => true
73+
await detect('test'); // => false
74+
75+
// parsing
76+
const parseResult = await parse('asyncapi: 3.0.0', { sourceMap: true });
77+
```
78+
79+
### Indirect usage
80+
81+
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.
82+
83+
```js
84+
import ApiDOMParser from '@swagger-api/apidom-parser';
85+
import * as asyncApiYamlAdapter from '@swagger-api/apidom-parser-adapter-asyncapi-yaml-3';
86+
87+
const parser = new ApiDOMParser();
88+
89+
parser.use(asyncApiYamlAdapter);
90+
91+
const parseResult = await parser.parse('asyncapi: 3.0.0', { mediaType: asyncApiYamlAdapter.mediaTypes.latest('yaml') });
92+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
"extends": "../../../../api-extractor.json",
4+
"mainEntryPointFilePath": "../../types/adapter.d.ts"
5+
}

0 commit comments

Comments
 (0)