-
Notifications
You must be signed in to change notification settings - Fork 22
feat(apidom-reference): parser for unit tests #5056
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
318a74f
feat(apidom-reference): parser for unit tests
lukaszzazulak e24e130
feat(apidom-reference): parser for unit tests
lukaszzazulak 5c94c1e
feat(apidom-reference): parser for unit tests
lukaszzazulak cc36d46
Merge branch 'main' into feat/async-api3-reference-parser
lukaszzazulak 2146c70
feat(apidom-reference): parser for unit tests
lukaszzazulak fdc6a0e
feat(apidom-reference): parser for unit tests
lukaszzazulak f080e1b
feat(apidom-reference): parser for unit tests
lukaszzazulak 9c829a3
Merge branch 'main' into feat/async-api3-reference-parser
lukaszzazulak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
60 changes: 60 additions & 0 deletions
60
packages/apidom-reference/src/parse/parsers/asyncapi-json-3/index.ts
This file contains hidden or 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,60 @@ | ||
| import { pick } from 'ramda'; | ||
| import { ParseResultElement } from '@swagger-api/apidom-core'; | ||
| import { | ||
| parse, | ||
| mediaTypes as AsyncAPI3MediaTypes, | ||
| detect, | ||
| } from '@swagger-api/apidom-parser-adapter-asyncapi-json-3'; | ||
|
|
||
| import ParserError from '../../../errors/ParserError.ts'; | ||
| import Parser, { ParserOptions } from '../Parser.ts'; | ||
| import File from '../../../File.ts'; | ||
|
|
||
| export type { default as Parser, ParserOptions } from '../Parser.ts'; | ||
| export type { default as File, FileOptions } from '../../../File.ts'; | ||
|
|
||
| /** | ||
| * @public | ||
| */ | ||
| export interface AsyncAPIJSON3ParserOptions extends Omit<ParserOptions, 'name'> {} | ||
|
|
||
| /** | ||
| * @public | ||
| */ | ||
| class AsyncAPIJSON3Parser extends Parser { | ||
| public syntacticAnalysis?: 'direct' | 'indirect'; | ||
|
|
||
| public refractorOpts!: object; | ||
|
|
||
| constructor(options?: AsyncAPIJSON3ParserOptions) { | ||
| const { fileExtensions = [], mediaTypes = AsyncAPI3MediaTypes, ...rest } = options ?? {}; | ||
|
|
||
| super({ ...rest, name: 'asyncapi-json-3', fileExtensions, mediaTypes }); | ||
| } | ||
|
|
||
| async canParse(file: File): Promise<boolean> { | ||
| const hasSupportedFileExtension = | ||
| this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension); | ||
| const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType); | ||
|
|
||
| if (!hasSupportedFileExtension) return false; | ||
| if (hasSupportedMediaType) return true; | ||
| if (!hasSupportedMediaType) { | ||
| return detect(file.toString()); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| async parse(file: File): Promise<ParseResultElement> { | ||
| const source = file.toString(); | ||
|
|
||
| try { | ||
| const parserOpts = pick(['sourceMap', 'syntacticAnalysis', 'refractorOpts'], this); | ||
| return await parse(source, parserOpts); | ||
| } catch (error: unknown) { | ||
| throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default AsyncAPIJSON3Parser; |
57 changes: 57 additions & 0 deletions
57
packages/apidom-reference/src/parse/parsers/asyncapi-yaml-3/index.ts
This file contains hidden or 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,57 @@ | ||
| import { pick } from 'ramda'; | ||
| import { ParseResultElement } from '@swagger-api/apidom-core'; | ||
| import { | ||
| parse, | ||
| mediaTypes as AsyncAPI3MediaTypes, | ||
| detect, | ||
| } from '@swagger-api/apidom-parser-adapter-asyncapi-yaml-3'; | ||
|
|
||
| import ParserError from '../../../errors/ParserError.ts'; | ||
| import Parser, { ParserOptions } from '../Parser.ts'; | ||
| import File from '../../../File.ts'; | ||
|
|
||
| export type { default as Parser, ParserOptions } from '../Parser.ts'; | ||
| export type { default as File, FileOptions } from '../../../File.ts'; | ||
|
|
||
| /** | ||
| * @public | ||
| */ | ||
| export interface AsyncAPIYAML3ParserOptions extends Omit<ParserOptions, 'name'> {} | ||
|
|
||
| /** | ||
| * @public | ||
| */ | ||
| class AsyncAPIYAML3Parser extends Parser { | ||
| public refractorOpts!: object; | ||
|
|
||
| constructor(options?: AsyncAPIYAML3ParserOptions) { | ||
| const { fileExtensions = [], mediaTypes = AsyncAPI3MediaTypes, ...rest } = options ?? {}; | ||
|
|
||
| super({ ...rest, name: 'asyncapi-yaml-3', fileExtensions, mediaTypes }); | ||
| } | ||
|
|
||
| async canParse(file: File): Promise<boolean> { | ||
| const hasSupportedFileExtension = | ||
| this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension); | ||
| const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType); | ||
|
|
||
| if (!hasSupportedFileExtension) return false; | ||
| if (hasSupportedMediaType) return true; | ||
| if (!hasSupportedMediaType) { | ||
| return detect(file.toString()); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| async parse(file: File): Promise<ParseResultElement> { | ||
| const source = file.toString(); | ||
| try { | ||
| const parserOpts = pick(['sourceMap', 'refractorOpts'], this); | ||
| return await parse(source, parserOpts); | ||
| } catch (error: unknown) { | ||
| throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default AsyncAPIYAML3Parser; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.