Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add JSDoc annotations '@private' (#70) #72

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
62 changes: 0 additions & 62 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,11 @@
<dd></dd>
</dl>

## Members

<dl>
<dt><a href="#validate">validate</a> ⇒ <code>Array.&lt;Object&gt;</code></dt>
<dd></dd>
</dl>

## Functions

<dl>
<dt><a href="#bundle">bundle(files, [options])</a> ⇒ <code><a href="#Document">Document</a></code></dt>
<dd></dd>
<dt><a href="#isExternalReference">isExternalReference(ref)</a> ⇒ <code>boolean</code></dt>
<dd><p>Checks if <code>ref</code> is an external reference.</p></dd>
<dt><a href="#resolveExternalRefs">resolveExternalRefs(parsedJSON, $refs)</a> ⇒ <code>ExternalComponents</code></dt>
<dd></dd>
<dt><a href="#parse">parse(JSONSchema)</a></dt>
<dd><p>Resolves external references and updates $refs.</p></dd>
</dl>

<a name="Document"></a>
Expand Down Expand Up @@ -65,17 +52,6 @@ console.log(document.string()); // get JSON string

### document.string() ⇒ <code>string</code>
**Kind**: instance method of [<code>Document</code>](#Document)
<a name="validate"></a>

## validate ⇒ <code>Array.&lt;Object&gt;</code>
**Kind**: global variable

| Param | Type |
| --- | --- |
| asyncapiDocuments | <code>Object</code> |
| options | <code>Object</code> |
| options.referenceIntoComponents | <code>boolean</code> |

<a name="bundle"></a>

## bundle(files, [options]) ⇒ [<code>Document</code>](#Document)
Expand Down Expand Up @@ -104,41 +80,3 @@ async function main() {

main().catch(e => console.error(e));
```
<a name="bundle..resolvedJsons"></a>

### bundle~resolvedJsons
<p>Bundle all external references for each file.</p>

**Kind**: inner constant of [<code>bundle</code>](#bundle)
<a name="isExternalReference"></a>

## isExternalReference(ref) ⇒ <code>boolean</code>
<p>Checks if <code>ref</code> is an external reference.</p>

**Kind**: global function

| Param | Type |
| --- | --- |
| ref | <code>string</code> |

<a name="resolveExternalRefs"></a>

## resolveExternalRefs(parsedJSON, $refs) ⇒ <code>ExternalComponents</code>
**Kind**: global function

| Param | Type |
| --- | --- |
| parsedJSON | <code>Array.&lt;Object&gt;</code> |
| $refs | <code>$RefParser</code> |

<a name="parse"></a>

## parse(JSONSchema)
<p>Resolves external references and updates $refs.</p>

**Kind**: global function

| Param | Type |
| --- | --- |
| JSONSchema | <code>Array.&lt;Object&gt;</code> |

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default async function bundle(files: string[], options: any = {}) {

/**
* Bundle all external references for each file.
* @private
*/
const resolvedJsons = await resolve(parsedJsons, {
referenceIntoComponents: options.referenceIntoComponents,
Expand Down
10 changes: 10 additions & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { merge } from 'lodash';
import type { $Refs } from '@apidevtools/json-schema-ref-parser';
import type { AsyncAPIObject, ComponentsObject, MessageObject } from './spec-types';

/**
* @class
* @private
*/
class ExternalComponents {
ref;
resolvedJSON;
Expand All @@ -23,6 +27,9 @@ class ExternalComponents {
}
}

/**
* @private
*/
function crawlChannelPropertiesForRefs(JSONSchema: AsyncAPIObject) {
// eslint-disable-next-line
return JSONPath({ json: JSONSchema, path: `$.channels.*.*.message['$ref']` });
Expand All @@ -32,6 +39,7 @@ function crawlChannelPropertiesForRefs(JSONSchema: AsyncAPIObject) {
* Checks if `ref` is an external reference.
* @param {string} ref
* @returns {boolean}
* @private
*/
function isExternalReference(ref: string) {
return !ref.startsWith('#');
Expand All @@ -42,6 +50,7 @@ function isExternalReference(ref: string) {
* @param {Object[]} parsedJSON
* @param {$RefParser} $refs
* @returns {ExternalComponents}
* @private
*/
async function resolveExternalRefs(parsedJSON: AsyncAPIObject, $refs: $Refs) {
const componentObj: ComponentsObject = { messages: {} };
Expand Down Expand Up @@ -71,6 +80,7 @@ async function resolveExternalRefs(parsedJSON: AsyncAPIObject, $refs: $Refs) {
/**
* Resolves external references and updates $refs.
* @param {Object[]} JSONSchema
* @private
*/
export async function parse(JSONSchema: AsyncAPIObject) {
const $ref: any = await $RefParser.resolve(JSONSchema);
Expand Down
7 changes: 7 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { ParserError } from './errors';

import type { AsyncAPIObject } from './spec-types';

/**
* @private
*/
export const toJS = (asyncapiYAMLorJSON: string | object) => {
if (!asyncapiYAMLorJSON) {
throw new ParserError({
Expand Down Expand Up @@ -38,6 +41,9 @@ export const toJS = (asyncapiYAMLorJSON: string | object) => {
return yaml.load(asyncapiYAMLorJSON);
};

/**
* @private
*/
export const validate = async (
parsedJSONs: AsyncAPIObject[],
parser: { parse(asyncapi: string | any): Promise<any> }
Expand All @@ -53,6 +59,7 @@ export const validate = async (
* @param {Object} options
* @param {boolean} options.referenceIntoComponents
* @returns {Array<Object>}
* @private
*/
export const resolve = async (
asyncapiDocuments: AsyncAPIObject[],
Expand Down