-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(openapi-3.1-adapter): add support for browser build fragments
Refs #35
- Loading branch information
Showing
24 changed files
with
52,635 additions
and
98 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/es | ||
/lib | ||
/types | ||
/tree-sitter-json.wasm |
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
68 changes: 0 additions & 68 deletions
68
apidom/packages/apidom-parser-adapter-openapi3-1/config/webpack/node.config.js
This file was deleted.
Oops, something went wrong.
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
6 changes: 6 additions & 0 deletions
6
apidom/packages/apidom-parser-adapter-openapi3-1/src/adapter-browser.ts
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,6 @@ | ||
export { default as parse } from './parser/index-browser'; | ||
|
||
export const mediaTypes = ['application/vnd.oai.openapi', 'application/vnd.oai.openapi+json']; | ||
|
||
export const detect = (source: string): boolean => | ||
!!source.match(/(["']?)openapi\1\s*:\s*(["']?)3\.\d+\.\d+\2/g); |
2 changes: 1 addition & 1 deletion
2
...-parser-adapter-openapi3-1/src/adapter.ts → ...er-adapter-openapi3-1/src/adapter-node.ts
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
15 changes: 15 additions & 0 deletions
15
apidom/packages/apidom-parser-adapter-openapi3-1/src/parser/index-browser-patch.ts
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,15 @@ | ||
import { tail } from 'ramda'; | ||
import { isString } from 'ramda-adjunct'; | ||
// @ts-ignore | ||
import treeSitterWasm from 'web-tree-sitter/tree-sitter.wasm'; | ||
|
||
// patch fetch() to let emscripten load the WASM file | ||
const realFetch = window.fetch; | ||
window.fetch = (...args) => { | ||
// @ts-ignore | ||
if (isString(args[0]) && args[0].endsWith('/tree-sitter.wasm')) { | ||
// @ts-ignore | ||
return realFetch.apply(window, [treeSitterWasm, tail(args)]); | ||
} | ||
return realFetch.apply(window, args); | ||
}; |
27 changes: 27 additions & 0 deletions
27
apidom/packages/apidom-parser-adapter-openapi3-1/src/parser/index-browser.ts
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,27 @@ | ||
import './index-browser-patch'; | ||
|
||
import Parser from 'web-tree-sitter'; | ||
import * as apiDOM from 'apidom'; | ||
|
||
import parse from '.'; | ||
// @ts-ignore | ||
import treeSitterJson from '../../tree-sitter-json.wasm'; | ||
|
||
const parserP = (async () => { | ||
await Parser.init(); | ||
const JsonLanguage = await Parser.Language.load(treeSitterJson); | ||
const parser = new Parser(); | ||
parser.setLanguage(JsonLanguage); | ||
return parser; | ||
})(); | ||
|
||
const parseBrowser = async ( | ||
source: string, | ||
options: Record<string, unknown> = {}, | ||
): Promise<apiDOM.ParseResultElement> => { | ||
const parser = await parserP; | ||
// @ts-ignore | ||
return parse(source, { ...options, parser }); | ||
}; | ||
|
||
export default parseBrowser; |
19 changes: 19 additions & 0 deletions
19
apidom/packages/apidom-parser-adapter-openapi3-1/src/parser/index-node.ts
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,19 @@ | ||
import Parser from 'tree-sitter'; | ||
// @ts-ignore | ||
import JSONLanguage from 'tree-sitter-json'; | ||
import * as apiDOM from 'apidom'; | ||
|
||
import parse from '.'; | ||
|
||
const parseNode = async ( | ||
source: string, | ||
options: Record<string, unknown> = {}, | ||
): Promise<apiDOM.ParseResultElement> => { | ||
const parser = new Parser(); | ||
parser.setLanguage(JSONLanguage); | ||
|
||
// @ts-ignore | ||
return parse(source, { ...options, parser }); | ||
}; | ||
|
||
export default parseNode; |
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.