@kubb/adapter-oas 5.0.0-beta.75 → 5.0.0-beta.9

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/README.md ADDED
@@ -0,0 +1,98 @@
1
+ <div align="center">
2
+ <h1>@kubb/adapter-oas</h1>
3
+ <a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
4
+ <img width="180" src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/logo.png" alt="Kubb logo">
5
+ </a>
6
+
7
+ [![npm version][npm-version-src]][npm-version-href]
8
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
9
+ [![Coverage][coverage-src]][coverage-href]
10
+ [![License][license-src]][license-href]
11
+ [![Sponsors][sponsors-src]][sponsors-href]
12
+
13
+ <h4>
14
+ <a href="https://kubb.dev/" target="_blank">Documentation</a>
15
+ <span> · </span>
16
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
17
+ <span> · </span>
18
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
19
+ </h4>
20
+ </div>
21
+
22
+ OpenAPI and Swagger adapter for Kubb. Parses and validates Swagger 2.0, OpenAPI 3.0, and OpenAPI 3.1 specifications and transforms them into a `@kubb/ast` `RootNode` for downstream code generation plugins.
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ bun add @kubb/adapter-oas
28
+ # or
29
+ pnpm add @kubb/adapter-oas
30
+ # or
31
+ npm install @kubb/adapter-oas
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ Use `adapterOas` inside your `kubb.config.ts`:
37
+
38
+ ```typescript
39
+ import { defineConfig } from 'kubb'
40
+ import { adapterOas } from '@kubb/adapter-oas'
41
+
42
+ export default defineConfig({
43
+ input: {
44
+ path: './openapi.yaml',
45
+ },
46
+ output: {
47
+ path: './src/gen',
48
+ },
49
+ adapters: [adapterOas()],
50
+ })
51
+ ```
52
+
53
+ ## Features
54
+
55
+ - Supports Swagger 2.0, OpenAPI 3.0, and OpenAPI 3.1
56
+ - Validates and dereferences `$ref` pointers
57
+ - Merges multi-document specs
58
+ - Outputs a `@kubb/ast` `RootNode` that every Kubb plugin reads from
59
+ - Re-exports typed helpers for operations, schemas, parameters, and responses
60
+
61
+ ## API
62
+
63
+ ### `adapterOas(options?)`
64
+
65
+ Creates the OAS adapter instance. Pass it in the `adapters` array of `defineConfig`.
66
+
67
+ ### `mergeDocuments(documents)`
68
+
69
+ Merges multiple OpenAPI documents into a single document before parsing.
70
+
71
+ ### Types
72
+
73
+ All OpenAPI types (`Document`, `Operation`, `SchemaObject`, `HttpMethod`, etc.) are re-exported from this package.
74
+
75
+ ## Supporting Kubb
76
+
77
+ Kubb is an open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
78
+
79
+ - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
80
+
81
+ <p align="center">
82
+ <a href="https://github.com/sponsors/stijnvanhulle">
83
+ <img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
84
+ </a>
85
+ </p>
86
+
87
+ <!-- Badges -->
88
+
89
+ [npm-version-src]: https://img.shields.io/npm/v/@kubb/adapter-oas?flat&colorA=18181B&colorB=f58517
90
+ [npm-version-href]: https://npmjs.com/package/@kubb/adapter-oas
91
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/adapter-oas?flat&colorA=18181B&colorB=f58517
92
+ [npm-downloads-href]: https://npmjs.com/package/@kubb/adapter-oas
93
+ [license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
94
+ [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
95
+ [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
96
+ [coverage-href]: https://www.npmjs.com/package/@kubb/adapter-oas
97
+ [sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
98
+ [sponsors-href]: https://github.com/sponsors/stijnvanhulle/
package/dist/index.cjs CHANGED
@@ -47,7 +47,7 @@ let oas_utils = require("oas/utils");
47
47
  */
48
48
  const DEFAULT_PARSER_OPTIONS = {
49
49
  dateType: "string",
50
- integerType: "number",
50
+ integerType: "bigint",
51
51
  unknownType: "any",
52
52
  emptySchemaType: "any",
53
53
  enumSuffix: "enum"
@@ -686,11 +686,10 @@ async function parseDocument(pathOrApi, { canBundle = true, enablePaths = true }
686
686
  * ```
687
687
  */
688
688
  async function mergeDocuments(pathOrApi) {
689
- const documents = [];
690
- for (const p of pathOrApi) documents.push(await parseDocument(p, {
689
+ const documents = await Promise.all(pathOrApi.map((p) => parseDocument(p, {
691
690
  enablePaths: false,
692
691
  canBundle: false
693
- }));
692
+ })));
694
693
  if (documents.length === 0) throw new Error("No OAS documents provided for merging.");
695
694
  const seed = {
696
695
  openapi: MERGE_OPENAPI_VERSION,
@@ -746,6 +745,7 @@ async function validateDocument(document, { throwOnError = false } = {}) {
746
745
  }
747
746
  //#endregion
748
747
  //#region src/refs.ts
748
+ const _refCache = /* @__PURE__ */ new WeakMap();
749
749
  /**
750
750
  * Resolves a local JSON pointer reference from a document.
751
751
  *
@@ -763,8 +763,15 @@ function resolveRef(document, $ref) {
763
763
  if ($ref === "") return null;
764
764
  if ($ref.startsWith("#")) $ref = globalThis.decodeURIComponent($ref.substring(1));
765
765
  else return null;
766
+ let docCache = _refCache.get(document);
767
+ if (!docCache) {
768
+ docCache = /* @__PURE__ */ new Map();
769
+ _refCache.set(document, docCache);
770
+ }
771
+ if (docCache.has($ref)) return docCache.get($ref);
766
772
  const current = $ref.split("/").filter(Boolean).reduce((obj, key) => obj?.[key], document);
767
773
  if (!current) throw new Error(`Could not find a definition for ${origRef}.`);
774
+ docCache.set($ref, current);
768
775
  return current;
769
776
  }
770
777
  /**
@@ -1946,6 +1953,9 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
1946
1953
  get inputNode() {
1947
1954
  return inputNode;
1948
1955
  },
1956
+ async validate(input, options) {
1957
+ await validateDocument(await parseDocument(input), options);
1958
+ },
1949
1959
  getImports(node, resolve) {
1950
1960
  return _kubb_core.ast.collectImports({
1951
1961
  node,
@@ -2006,8 +2016,5 @@ exports.HttpMethods = HttpMethods;
2006
2016
  exports.adapterOas = adapterOas;
2007
2017
  exports.adapterOasName = adapterOasName;
2008
2018
  exports.mergeDocuments = mergeDocuments;
2009
- exports.parseDocument = parseDocument;
2010
- exports.parseFromConfig = parseFromConfig;
2011
- exports.validateDocument = validateDocument;
2012
2019
 
2013
2020
  //# sourceMappingURL=index.cjs.map