-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49afdba
commit 12a0a01
Showing
12 changed files
with
166 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
import { applyTraitsV2, applyTraitsV3 } from './apply-traits'; | ||
import { parseSchemasV2 } from './parse-schema'; | ||
|
||
import type { Parser } from '../parser'; | ||
import type { ParseOptions } from "../parse"; | ||
import type { DetailedAsyncAPI } from "../types"; | ||
|
||
export async function customOperations(detailed: DetailedAsyncAPI, options: ParseOptions): Promise<void> { | ||
export async function customOperations(parser: Parser, detailed: DetailedAsyncAPI, options: ParseOptions): Promise<void> { | ||
switch (detailed.semver.major) { | ||
case 2: return operationsV2(detailed, options); | ||
case 3: return operationsV3(detailed, options); | ||
case 2: return operationsV2(parser, detailed, options); | ||
case 3: return operationsV3(parser, detailed, options); | ||
} | ||
} | ||
|
||
async function operationsV2(detailed: DetailedAsyncAPI, options: ParseOptions): Promise<void> { | ||
async function operationsV2(parser: Parser, detailed: DetailedAsyncAPI, options: ParseOptions): Promise<void> { | ||
if (options.applyTraits) { | ||
applyTraitsV2(detailed.parsed); | ||
} | ||
if (options.parseSchemas) { | ||
await parseSchemasV2(detailed); | ||
await parseSchemasV2(parser, detailed); | ||
} | ||
} | ||
|
||
async function operationsV3(detailed: DetailedAsyncAPI, options: ParseOptions): Promise<void> { | ||
async function operationsV3(parser: Parser, detailed: DetailedAsyncAPI, options: ParseOptions): Promise<void> { | ||
if (options.applyTraits) { | ||
applyTraitsV3(detailed.parsed); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
export * from './models'; | ||
|
||
export { lint, validate } from './lint'; | ||
export { parse } from './parse'; | ||
export { Parser } from './parser'; | ||
export { stringify, unstringify } from './stringify'; | ||
|
||
export { registerSchemaParser } from './schema-parser'; | ||
export { AsyncAPISchemaParser } from './schema-parser/asyncapi-schema-parser'; | ||
|
||
export type { AsyncAPISemver, Diagnostic, SchemaValidateResult } from './types'; | ||
export type { LintOptions, ValidateOptions, ValidateOutput } from './lint'; | ||
export type { ParseInput, ParseOptions, ParseOutput } from './parse'; | ||
export type { StringifyOptions } from './stringify'; | ||
export type { ParseOptions } from './parse'; | ||
export type { AsyncAPISemver, ParserInput, ParserOutput, Diagnostic, SchemaValidateResult } from './types'; | ||
|
||
export type { ValidateSchemaInput, ParseSchemaInput, SchemaParser } from './schema-parser' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Spectral } from "@stoplight/spectral-core"; | ||
import { asyncapi as aasRuleset } from "@stoplight/spectral-rulesets"; | ||
|
||
import { parse } from "./parse"; | ||
import { lint, validate } from "./lint"; | ||
import { registerSchemaParser } from './schema-parser'; | ||
|
||
import type { IConstructorOpts } from "@stoplight/spectral-core"; | ||
import type { ParseInput, ParseOptions } from "./parse"; | ||
import type { LintOptions, ValidateOptions } from "./lint"; | ||
import type { SchemaParser } from './schema-parser'; | ||
|
||
export interface ParserOptions { | ||
spectral?: Spectral | IConstructorOpts; | ||
} | ||
|
||
export class Parser { | ||
public readonly parserRegistry = new Map<string, SchemaParser>(); | ||
public readonly spectral: Spectral; | ||
|
||
constructor(options?: ParserOptions) { | ||
const { spectral } = options || {}; | ||
if (spectral instanceof Spectral) { | ||
this.spectral = spectral; | ||
} else { | ||
this.spectral = new Spectral(spectral); | ||
} | ||
|
||
// TODO: fix type | ||
this.spectral.setRuleset(aasRuleset as any); | ||
} | ||
|
||
parse(asyncapi: ParseInput, options?: ParseOptions) { | ||
return parse(this, asyncapi, options); | ||
} | ||
|
||
lint(asyncapi: ParseInput, options?: LintOptions) { | ||
return lint(this, asyncapi, options); | ||
} | ||
|
||
validate(asyncapi: ParseInput, options?: ValidateOptions) { | ||
return validate(this, asyncapi, options); | ||
} | ||
|
||
registerSchemaParser(parser: SchemaParser) { | ||
return registerSchemaParser(this, parser); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.