Skip to content

Commit

Permalink
chore(parser-adapter-openapi-json-3-1): use API Extractor for TypeScr…
Browse files Browse the repository at this point in the history
…ipt rollup (#4524)

Refs #4382
  • Loading branch information
glowcloud authored Nov 21, 2024
1 parent f86b3fd commit 2bd39d8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "../../../../api-extractor.json",
"mainEntryPointFilePath": "../../types/adapter.d.ts"
}

This file was deleted.

8 changes: 4 additions & 4 deletions packages/apidom-parser-adapter-openapi-json-3-1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"unpkg": "./dist/apidom-parser-apdater-openapi-json-3-1.browser.min.js",
"main": "./src/adapter.cjs",
"exports": {
"types": "./types/dist.d.ts",
"types": "./types/apidom-parser-adapter-openapi-json-3-1.d.ts",
"import": "./src/adapter.mjs",
"require": "./src/adapter.cjs"
},
"types": "./types/dist.d.ts",
"types": "./types/apidom-parser-adapter-openapi-json-3-1.d.ts",
"scripts": {
"build": "npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser",
"build:es": "cross-env BABEL_ENV=es babel src --out-dir src --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'",
Expand All @@ -25,7 +25,7 @@
"lint:fix": "eslint ./ --fix",
"clean": "rimraf --glob 'src/**/*.mjs' 'src/**/*.cjs' 'test/**/*.mjs' ./dist ./types",
"typescript:check-types": "tsc --noEmit && tsc -p ./test/tsconfig.json --noEmit",
"typescript:declaration": "tsc -p tsconfig.declaration.json && rollup -c config/rollup/types.dist.js",
"typescript:declaration": "tsc -p tsconfig.declaration.json && api-extractor run -l -c ./config/api-extractor/api-extractor.json",
"test": "npm run build:es && cross-env BABEL_ENV=es babel test --out-dir test --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward' && cross-env NODE_ENV=test mocha",
"perf": "cross-env BABEL_ENV=es babel ./test/perf/index.ts --out-file ./test/perf/index.mjs --root-mode 'upward' && cross-env NODE_ENV=test node ./test/perf/index.mjs",
"perf:lexical-analysis": "cross-env BABEL_ENV=es babel ./test/perf/lexical-analysis.ts --out-file ./test/perf/lexical-analysis.mjs --root-mode 'upward' && cross-env NODE_ENV=test node ./test/perf/lexical-analysis.mjs",
Expand Down Expand Up @@ -54,7 +54,7 @@
"src/**/*.mjs",
"src/**/*.cjs",
"dist/",
"types/dist.d.ts",
"types/apidom-parser-adapter-openapi-json-3-1.d.ts",
"LICENSES",
"NOTICE",
"README.md",
Expand Down
12 changes: 12 additions & 0 deletions packages/apidom-parser-adapter-openapi-json-3-1/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ import openApiNamespace, { OpenApi3_1Element } from '@swagger-api/apidom-ns-open

export { default as mediaTypes } from './media-types.ts';

/**
* @public
*/
export const detectionRegExp = /"openapi"\s*:\s*"(?<version_json>3\.1\.(?:[1-9]\d*|0))"/;

/**
* @public
*/
export const detect = async (source: string): Promise<boolean> =>
detectionRegExp.test(source) && (await detectJSON(source));

/**
* @public
*/
export const parse = async (
source: string,
options: Record<string, unknown> = {},
Expand All @@ -29,4 +38,7 @@ export const parse = async (
return parseResultElement;
};

/**
* @public
*/
export const namespace = createNamespace(openApiNamespace);
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { mediaTypes, OpenAPIMediaTypes } from '@swagger-api/apidom-ns-openapi-3-1';

/**
* @public
*/
const jsonMediaTypes = new OpenAPIMediaTypes(
...mediaTypes.filterByFormat('generic'),
...mediaTypes.filterByFormat('json'),
Expand Down

0 comments on commit 2bd39d8

Please sign in to comment.