@ir-kit/openapi-loader 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +32 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ahmed Rowaihi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# `@ir-kit/openapi-loader`
|
|
2
|
+
|
|
3
|
+
Load an OpenAPI 3.x spec from a file path, URL, or pre-parsed object. Bundles `$ref`s via `@hey-api/json-schema-ref-parser` and runs optional hey-api-aware normalization.
|
|
4
|
+
|
|
5
|
+
Part of [ir-kit](https://github.com/ir-kit/ir-kit). For multi-format input (OpenAPI + AsyncAPI + TypeSpec under one API), reach for [`@ir-kit/spec-loader`](../../shared/spec-loader) instead.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @ir-kit/openapi-loader
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { loadOpenAPI } from "@ir-kit/openapi-loader";
|
|
17
|
+
|
|
18
|
+
const spec = await loadOpenAPI({
|
|
19
|
+
input: "./petstore.yaml", // path, URL, or pre-parsed object
|
|
20
|
+
normalize: true, // optional hey-api normalization
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## API
|
|
25
|
+
|
|
26
|
+
| Export | Description |
|
|
27
|
+
| ------------------------------------ | ------------------------------------------------------------ |
|
|
28
|
+
| `loadOpenAPI(opts)` | Bundle `$ref`s, optionally normalize, return the spec |
|
|
29
|
+
| `resolveOpenAPIInput(input, cwd?)` | Resolve a string input to an absolute path / URL passthrough |
|
|
30
|
+
| `OpenAPIInput`, `LoadOpenAPIOptions` | Public types |
|
|
31
|
+
|
|
32
|
+
`normalize: true` applies the safe preset (`SAFE_NORMALIZE` from `@ir-kit/openapi`). Pass a `NormalizeOptions` object to customize.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type NormalizeOptions } from "@ir-kit/openapi";
|
|
2
|
+
export type OpenAPIInput = string | Record<string, unknown>;
|
|
3
|
+
export interface LoadOpenAPIOptions {
|
|
4
|
+
input: OpenAPIInput;
|
|
5
|
+
cwd?: string;
|
|
6
|
+
/** Apply hey-api-aware normalization after bundling. `true` enables
|
|
7
|
+
* the safe preset; pass an object for custom rules. */
|
|
8
|
+
normalize?: boolean | NormalizeOptions;
|
|
9
|
+
}
|
|
10
|
+
export declare function loadOpenAPI(opts: LoadOpenAPIOptions): Promise<Record<string, unknown>>;
|
|
11
|
+
export declare function resolveOpenAPIInput(input: OpenAPIInput, cwd?: string): OpenAPIInput;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,YAAY,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;4DACwD;IACxD,SAAS,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC;CACxC;AAED,wBAAsB,WAAW,CAC/B,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAalC;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,YAAY,EACnB,GAAG,GAAE,MAAsB,GAC1B,YAAY,CASd"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isAbsolute, resolve } from "node:path";
|
|
2
|
+
import { $RefParser } from "@hey-api/json-schema-ref-parser";
|
|
3
|
+
import { normalizeSpec, SAFE_NORMALIZE, } from "@ir-kit/openapi";
|
|
4
|
+
export async function loadOpenAPI(opts) {
|
|
5
|
+
const bundled = (await new $RefParser().bundle({
|
|
6
|
+
pathOrUrlOrSchema: resolveOpenAPIInput(opts.input, opts.cwd),
|
|
7
|
+
}));
|
|
8
|
+
if (opts.normalize) {
|
|
9
|
+
normalizeSpec(bundled, opts.normalize === true ? SAFE_NORMALIZE : opts.normalize);
|
|
10
|
+
}
|
|
11
|
+
return bundled;
|
|
12
|
+
}
|
|
13
|
+
export function resolveOpenAPIInput(input, cwd = process.cwd()) {
|
|
14
|
+
if (typeof input !== "string")
|
|
15
|
+
return input;
|
|
16
|
+
const trimmed = input.trim();
|
|
17
|
+
if (trimmed === "") {
|
|
18
|
+
throw new Error("OpenAPI spec input is empty or only whitespace.");
|
|
19
|
+
}
|
|
20
|
+
if (/^https?:\/\//i.test(trimmed))
|
|
21
|
+
return trimmed;
|
|
22
|
+
if (isAbsolute(trimmed))
|
|
23
|
+
return trimmed;
|
|
24
|
+
return resolve(cwd, trimmed);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAEL,aAAa,EACb,cAAc,GACf,MAAM,iBAAiB,CAAC;AAYzB,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAwB;IAExB,MAAM,OAAO,GAAG,CAAC,MAAM,IAAI,UAAU,EAAE,CAAC,MAAM,CAAC;QAC7C,iBAAiB,EAAE,mBAAmB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC;KAC7D,CAAC,CAA4B,CAAC;IAE/B,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,aAAa,CACX,OAAO,EACP,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAC1D,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,KAAmB,EACnB,MAAc,OAAO,CAAC,GAAG,EAAE;IAE3B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,IAAI,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IAClD,IAAI,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IACxC,OAAO,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC/B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ir-kit/openapi-loader",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Load an OpenAPI 3.x spec from a file path, URL, or pre-parsed object. Bundles `$ref`s via `@hey-api/json-schema-ref-parser` and runs optional hey-api-aware normalization.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"openapi",
|
|
7
|
+
"loader",
|
|
8
|
+
"ref-parser",
|
|
9
|
+
"spec",
|
|
10
|
+
"ir-kit"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/ir-kit/ir-kit/tree/main/packages/openapi/loader",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/ir-kit/ir-kit/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Ahmed Rowaihi",
|
|
19
|
+
"email": "ahmedrowaihi@gmail.com"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/ir-kit/ir-kit.git",
|
|
24
|
+
"directory": "packages/openapi/loader"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"README.md",
|
|
40
|
+
"LICENSE.md"
|
|
41
|
+
],
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public",
|
|
44
|
+
"provenance": true
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@hey-api/json-schema-ref-parser": "^1.4.1",
|
|
48
|
+
"@ir-kit/openapi": "0.3.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^22",
|
|
52
|
+
"vitest": "^4.0.0",
|
|
53
|
+
"@ir-kit/tsconfig": "0.0.0"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=20.19.0"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsc -p tsconfig.build.json",
|
|
60
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"test": "vitest run --passWithNoTests"
|
|
63
|
+
}
|
|
64
|
+
}
|