@furystack/rest 8.0.41 → 8.1.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/CHANGELOG.md +77 -0
- package/README.md +37 -1
- package/esm/api-endpoint-schema.d.ts +47 -2
- package/esm/api-endpoint-schema.d.ts.map +1 -1
- package/esm/index.d.ts +4 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +4 -1
- package/esm/index.js.map +1 -1
- package/esm/openapi-document.d.ts +303 -0
- package/esm/openapi-document.d.ts.map +1 -0
- package/esm/openapi-document.js +2 -0
- package/esm/openapi-document.js.map +1 -0
- package/esm/openapi-resolve-refs.d.ts +20 -0
- package/esm/openapi-resolve-refs.d.ts.map +1 -0
- package/esm/openapi-resolve-refs.js +68 -0
- package/esm/openapi-resolve-refs.js.map +1 -0
- package/esm/openapi-resolve-refs.spec.d.ts +2 -0
- package/esm/openapi-resolve-refs.spec.d.ts.map +1 -0
- package/esm/openapi-resolve-refs.spec.js +294 -0
- package/esm/openapi-resolve-refs.spec.js.map +1 -0
- package/esm/openapi-to-rest-api.d.ts +197 -0
- package/esm/openapi-to-rest-api.d.ts.map +1 -0
- package/esm/openapi-to-rest-api.js +2 -0
- package/esm/openapi-to-rest-api.js.map +1 -0
- package/esm/openapi-to-rest-api.spec.d.ts +2 -0
- package/esm/openapi-to-rest-api.spec.d.ts.map +1 -0
- package/esm/openapi-to-rest-api.spec.js +665 -0
- package/esm/openapi-to-rest-api.spec.js.map +1 -0
- package/esm/openapi-to-schema.d.ts +24 -0
- package/esm/openapi-to-schema.d.ts.map +1 -0
- package/esm/openapi-to-schema.js +145 -0
- package/esm/openapi-to-schema.js.map +1 -0
- package/esm/openapi-to-schema.spec.d.ts +2 -0
- package/esm/openapi-to-schema.spec.d.ts.map +1 -0
- package/esm/openapi-to-schema.spec.js +610 -0
- package/esm/openapi-to-schema.spec.js.map +1 -0
- package/esm/rest-api.d.ts +21 -4
- package/esm/rest-api.d.ts.map +1 -1
- package/esm/swagger-document.d.ts +2 -195
- package/esm/swagger-document.d.ts.map +1 -1
- package/esm/swagger-document.js +2 -1
- package/esm/swagger-document.js.map +1 -1
- package/package.json +4 -4
- package/src/api-endpoint-schema.ts +56 -3
- package/src/index.ts +4 -1
- package/src/openapi-document.ts +328 -0
- package/src/openapi-resolve-refs.spec.ts +324 -0
- package/src/openapi-resolve-refs.ts +71 -0
- package/src/openapi-to-rest-api.spec.ts +823 -0
- package/src/openapi-to-rest-api.ts +263 -0
- package/src/openapi-to-schema.spec.ts +707 -0
- package/src/openapi-to-schema.ts +163 -0
- package/src/rest-api.ts +26 -5
- package/src/swagger-document.ts +2 -220
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,82 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [8.1.0] - 2026-03-07
|
|
4
|
+
|
|
5
|
+
### ⬆️ Dependencies
|
|
6
|
+
|
|
7
|
+
- Updated `@types/node` from `^25.3.1` to `^25.3.5`
|
|
8
|
+
|
|
9
|
+
### 🗑️ Deprecated
|
|
10
|
+
|
|
11
|
+
- `SwaggerDocument` type - Use `OpenApiDocument` instead
|
|
12
|
+
- `/swagger.json` endpoint in `WithSchemaAction` - Use `/openapi.json` instead. The `/swagger.json` endpoint remains available during the transition period and responds with `Deprecation` and `Link` headers pointing to `/openapi.json`.
|
|
13
|
+
|
|
14
|
+
### ✨ Features
|
|
15
|
+
|
|
16
|
+
### Bidirectional OpenAPI 3.1 Support
|
|
17
|
+
|
|
18
|
+
The package can now both **consume** and **produce** OpenAPI 3.1 documents with strong typing.
|
|
19
|
+
|
|
20
|
+
### Consume: OpenAPI to FuryStack
|
|
21
|
+
|
|
22
|
+
Import an OpenAPI JSON document and derive a strongly-typed `RestApi` from it:
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import type { OpenApiDocument, OpenApiToRestApi } from '@furystack/rest'
|
|
26
|
+
import { createClient } from '@furystack/rest-client-fetch'
|
|
27
|
+
|
|
28
|
+
const apiDoc = {
|
|
29
|
+
/* downloaded OpenAPI JSON */
|
|
30
|
+
} as const satisfies OpenApiDocument
|
|
31
|
+
type MyApi = OpenApiToRestApi<typeof apiDoc>
|
|
32
|
+
|
|
33
|
+
const client = createClient<MyApi>({ endpointUrl: 'https://api.example.com' })
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- Added `OpenApiToRestApi<T>` - Extracts a strongly-typed `RestApi` from an `as const` OpenAPI document, including path parameters, query parameters, request bodies, and response types
|
|
37
|
+
- Added `JsonSchemaToType<S>` - Maps JSON Schema types to TypeScript types, supporting primitives, arrays, objects with required/optional properties, `enum`, `const`, `nullable` (`type: ['string', 'null']`), and composition (`allOf`, `oneOf`, `anyOf`)
|
|
38
|
+
- Added `ConvertOpenApiPath<P>` - Converts OpenAPI `{param}` path format to FuryStack `:param` format at the type level
|
|
39
|
+
- Added `resolveOpenApiRefs()` - Resolves all internal `$ref` pointers in an OpenAPI document, inlining the referenced schemas, parameters, responses, and request bodies. Handles circular references safely.
|
|
40
|
+
- Added `openApiToSchema()` - Converts an OpenAPI document to a FuryStack `ApiEndpointSchema` at runtime, preserving metadata (tags, deprecated, summary, description, servers, security schemes, contact, license)
|
|
41
|
+
- Added `convertOpenApiPathToFuryStack()` - Runtime path format conversion from OpenAPI `{param}` to FuryStack `:param`
|
|
42
|
+
|
|
43
|
+
### Type-level `$ref` Resolution
|
|
44
|
+
|
|
45
|
+
`OpenApiToRestApi` resolves `$ref` pointers within the type system, so schemas that use `$ref` to `components/schemas`, `components/parameters`, `components/responses`, and `components/requestBodies` are resolved automatically.
|
|
46
|
+
|
|
47
|
+
### OpenAPI Document Types
|
|
48
|
+
|
|
49
|
+
- Renamed `SwaggerDocument` to `OpenApiDocument` with all associated types (`InfoObject`, `PathItem`, `Operation`, `ParameterObject`, `ResponseObject`, etc.) - these model the full OpenAPI 3.1 specification
|
|
50
|
+
|
|
51
|
+
### Metadata Support
|
|
52
|
+
|
|
53
|
+
- Extended `RestApi` endpoint shape with optional metadata: `tags`, `deprecated`, `summary`, `description`
|
|
54
|
+
- Added `ApiDocumentMetadata` type for document-level metadata (servers, tags, contact, license, externalDocs, securitySchemes)
|
|
55
|
+
- Added metadata fields to `ApiEndpointDefinition` and `ApiEndpointSchema`
|
|
56
|
+
|
|
57
|
+
### ♻️ Refactoring
|
|
58
|
+
|
|
59
|
+
- Replaced `swagger-document.ts` with `openapi-document.ts` (the old file now re-exports from the new one for backward compatibility)
|
|
60
|
+
- Changed `WithSchemaAction` to expose `/openapi.json` instead of `/swagger.json`
|
|
61
|
+
|
|
62
|
+
### 🧪 Tests
|
|
63
|
+
|
|
64
|
+
- Type-level tests for `OpenApiToRestApi`, `JsonSchemaToType`, and `ConvertOpenApiPath` covering primitives, objects, arrays, enums, const, nullable, allOf/oneOf/anyOf, `$ref` resolution, path/query/body extraction, and metadata
|
|
65
|
+
- Unit tests for `openApiToSchema()` covering all HTTP methods, path conversion, response schema extraction, authentication detection, and document/operation metadata
|
|
66
|
+
- Unit tests for `resolveOpenApiRefs()` covering schema/parameter/response/requestBody resolution, circular ref handling, external refs, and unresolvable refs
|
|
67
|
+
- Round-trip tests importing external JSON fixtures to verify the consume-produce pipeline
|
|
68
|
+
|
|
69
|
+
### 📚 Documentation
|
|
70
|
+
|
|
71
|
+
- Added JSDoc with OpenAPI 3.1 spec links to all 26 exported OpenAPI types
|
|
72
|
+
- Added JSDoc to `RestApi`, `ApiDocumentMetadata`, and all new exported functions and types
|
|
73
|
+
|
|
74
|
+
## [8.0.42] - 2026-03-06
|
|
75
|
+
|
|
76
|
+
### ⬆️ Dependencies
|
|
77
|
+
|
|
78
|
+
- Updated internal FuryStack dependencies
|
|
79
|
+
|
|
3
80
|
## [8.0.41] - 2026-03-03
|
|
4
81
|
|
|
5
82
|
### ⬆️ Dependencies
|
package/README.md
CHANGED
|
@@ -129,9 +129,45 @@ export type MyApiWithSchema = WithSchemaAction<MyApi>
|
|
|
129
129
|
|
|
130
130
|
// This adds:
|
|
131
131
|
// GET /schema - Returns the API schema
|
|
132
|
-
// GET /
|
|
132
|
+
// GET /openapi.json - Returns OpenAPI 3.1 documentation
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
+
## Consuming OpenAPI Documents
|
|
136
|
+
|
|
137
|
+
You can derive a type-safe `RestApi` from an existing OpenAPI 3.1 document, enabling FuryStack clients to talk to any OpenAPI-described service.
|
|
138
|
+
|
|
139
|
+
### Type-level extraction
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import type { OpenApiDocument, OpenApiToRestApi } from '@furystack/rest'
|
|
143
|
+
import { createClient } from '@furystack/rest-client-fetch'
|
|
144
|
+
|
|
145
|
+
const apiDoc = {
|
|
146
|
+
/* OpenAPI 3.1 JSON */
|
|
147
|
+
} as const satisfies OpenApiDocument
|
|
148
|
+
|
|
149
|
+
type PetStoreApi = OpenApiToRestApi<typeof apiDoc>
|
|
150
|
+
|
|
151
|
+
const client = createClient<PetStoreApi>({ endpointUrl: 'https://petstore.example.com' })
|
|
152
|
+
const { result } = await client({ method: 'GET', action: '/pets' })
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Supports `$ref` resolution, `allOf`/`oneOf`/`anyOf` composition, nullable types, `const`, enums, and metadata extraction (`tags`, `deprecated`, `summary`, `description`).
|
|
156
|
+
|
|
157
|
+
### Runtime conversion
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
import { resolveOpenApiRefs, openApiToSchema } from '@furystack/rest'
|
|
161
|
+
|
|
162
|
+
// 1. Resolve $ref pointers (required if the document uses $ref)
|
|
163
|
+
const resolved = resolveOpenApiRefs(myOpenApiDoc)
|
|
164
|
+
|
|
165
|
+
// 2. Convert to FuryStack's ApiEndpointSchema
|
|
166
|
+
const schema = openApiToSchema(resolved)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Security scheme names from the original document are preserved through the conversion, so they survive a round-trip back through `generateOpenApiDocument`.
|
|
170
|
+
|
|
135
171
|
## Utilities
|
|
136
172
|
|
|
137
173
|
### Query String Serialization
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { Method } from './methods.js';
|
|
2
|
+
import type { ContactObject, ExternalDocumentationObject, LicenseObject, SecuritySchemeObject, ServerObject, TagObject } from './openapi-document.js';
|
|
2
3
|
import type { RestApi } from './rest-api.js';
|
|
3
4
|
/**
|
|
4
|
-
* The JSON
|
|
5
|
+
* The JSON Schema type used for API endpoint definitions.
|
|
6
|
+
*
|
|
7
|
+
* This is intentionally `unknown` because the exact schema shape depends on
|
|
8
|
+
* the generator used (e.g. `ts-json-schema-generator` produces Draft 7-style
|
|
9
|
+
* objects with `definitions`, while consumed OpenAPI documents use 3.1-style
|
|
10
|
+
* objects). Narrowing to `object | boolean` would break runtime usages where
|
|
11
|
+
* the schema is `null` or omitted.
|
|
5
12
|
*/
|
|
6
13
|
export type Schema = unknown;
|
|
7
14
|
/**
|
|
@@ -25,9 +32,46 @@ export type ApiEndpointDefinition = {
|
|
|
25
32
|
schemaName: string;
|
|
26
33
|
/**
|
|
27
34
|
* Indicates whether the endpoint requires authentication.
|
|
28
|
-
* To include the flag, wrap your endpoint with an
|
|
35
|
+
* To include the flag, wrap your endpoint with an Authenticate() call during the implementation.
|
|
29
36
|
*/
|
|
30
37
|
isAuthenticated: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Tags for API documentation grouping.
|
|
40
|
+
*/
|
|
41
|
+
tags?: string[];
|
|
42
|
+
/**
|
|
43
|
+
* Marks the endpoint as deprecated.
|
|
44
|
+
*/
|
|
45
|
+
deprecated?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* A short summary of the endpoint.
|
|
48
|
+
*/
|
|
49
|
+
summary?: string;
|
|
50
|
+
/**
|
|
51
|
+
* A longer description of the endpoint.
|
|
52
|
+
*/
|
|
53
|
+
description?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The OpenAPI security scheme names required for this endpoint.
|
|
56
|
+
* When present, used by `generateOpenApiDocument` to emit accurate per-operation `security`.
|
|
57
|
+
* When absent, falls back to the `isAuthenticated` boolean behavior.
|
|
58
|
+
*/
|
|
59
|
+
securitySchemes?: string[];
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Document-level metadata preserved from/to OpenAPI documents.
|
|
63
|
+
* Carries info fields (contact, license, servers, tags, etc.) through the
|
|
64
|
+
* `openApiToSchema()` -> `generateOpenApiDocument()` round-trip.
|
|
65
|
+
*/
|
|
66
|
+
export type ApiDocumentMetadata = {
|
|
67
|
+
summary?: string;
|
|
68
|
+
termsOfService?: string;
|
|
69
|
+
contact?: ContactObject;
|
|
70
|
+
license?: LicenseObject;
|
|
71
|
+
servers?: ServerObject[];
|
|
72
|
+
tags?: TagObject[];
|
|
73
|
+
externalDocs?: ExternalDocumentationObject;
|
|
74
|
+
securitySchemes?: Record<string, SecuritySchemeObject>;
|
|
31
75
|
};
|
|
32
76
|
/**
|
|
33
77
|
* Represents the schema for an API, organized by HTTP method and then by path.
|
|
@@ -51,6 +95,7 @@ export type ApiEndpointSchema<TApi extends RestApi = RestApi> = {
|
|
|
51
95
|
name: string;
|
|
52
96
|
description: string;
|
|
53
97
|
version: string;
|
|
98
|
+
metadata?: ApiDocumentMetadata;
|
|
54
99
|
endpoints: {
|
|
55
100
|
[TMethod in Method]?: TMethod extends keyof TApi ? TApi[TMethod] extends Record<string, unknown> ? {
|
|
56
101
|
[TPath in keyof TApi[TMethod] & string]: ApiEndpointDefinition;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-endpoint-schema.d.ts","sourceRoot":"","sources":["../src/api-endpoint-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C
|
|
1
|
+
{"version":3,"file":"api-endpoint-schema.d.ts","sourceRoot":"","sources":["../src/api-endpoint-schema.ts"],"names":[],"mappings":"A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IAAI,SAAS,OAAO,GAAG,OAAO,IAAI;IAC9D,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,mBAAmB,CAAA;IAC9B,SAAS,EAAE;SACR,OAAO,IAAI,MAAM,CAAC,CAAC,EAAE,OAAO,SAAS,MAAM,IAAI,GAC5C,IAAI,CAAC,OAAO,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3C;aAAG,KAAK,IAAI,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,MAAM,GAAG,qBAAqB;SAAE,GAClE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,GACvC,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC;KAC1C,CAAA;CACF,CAAA"}
|
package/esm/index.d.ts
CHANGED
|
@@ -2,8 +2,11 @@ export * from './api-endpoint-schema.js';
|
|
|
2
2
|
export * from './deserialize-query-string.js';
|
|
3
3
|
export * from './endpoint-models/index.js';
|
|
4
4
|
export * from './methods.js';
|
|
5
|
+
export * from './openapi-document.js';
|
|
6
|
+
export * from './openapi-resolve-refs.js';
|
|
7
|
+
export * from './openapi-to-rest-api.js';
|
|
8
|
+
export * from './openapi-to-schema.js';
|
|
5
9
|
export * from './request-error.js';
|
|
6
10
|
export * from './rest-api.js';
|
|
7
11
|
export * from './serialize-to-query-string.js';
|
|
8
|
-
export * from './swagger-document.js';
|
|
9
12
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,cAAc,CAAA;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,2BAA2B,CAAA;AACzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,gCAAgC,CAAA"}
|
package/esm/index.js
CHANGED
|
@@ -2,8 +2,11 @@ export * from './api-endpoint-schema.js';
|
|
|
2
2
|
export * from './deserialize-query-string.js';
|
|
3
3
|
export * from './endpoint-models/index.js';
|
|
4
4
|
export * from './methods.js';
|
|
5
|
+
export * from './openapi-document.js';
|
|
6
|
+
export * from './openapi-resolve-refs.js';
|
|
7
|
+
export * from './openapi-to-rest-api.js';
|
|
8
|
+
export * from './openapi-to-schema.js';
|
|
5
9
|
export * from './request-error.js';
|
|
6
10
|
export * from './rest-api.js';
|
|
7
11
|
export * from './serialize-to-query-string.js';
|
|
8
|
-
export * from './swagger-document.js';
|
|
9
12
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,cAAc,CAAA;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,2BAA2B,CAAA;AACzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,gCAAgC,CAAA"}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an OpenAPI 3.1 document.
|
|
3
|
+
* @see https://spec.openapis.org/oas/v3.1.0#openapi-object
|
|
4
|
+
*/
|
|
5
|
+
export type OpenApiDocument = {
|
|
6
|
+
openapi: string;
|
|
7
|
+
info: InfoObject;
|
|
8
|
+
jsonSchemaDialect?: string;
|
|
9
|
+
externalDocs?: ExternalDocumentationObject;
|
|
10
|
+
servers?: ServerObject[];
|
|
11
|
+
tags?: TagObject[];
|
|
12
|
+
security?: SecurityRequirementObject[];
|
|
13
|
+
paths?: Record<string, PathItem>;
|
|
14
|
+
webhooks?: Record<string, PathItem>;
|
|
15
|
+
components?: ComponentsObject;
|
|
16
|
+
[key: `x-${string}`]: unknown;
|
|
17
|
+
};
|
|
18
|
+
/** @deprecated Use OpenApiDocument instead */
|
|
19
|
+
export type SwaggerDocument = OpenApiDocument;
|
|
20
|
+
/**
|
|
21
|
+
* Metadata about the API.
|
|
22
|
+
* @see https://spec.openapis.org/oas/v3.1.0#info-object
|
|
23
|
+
*/
|
|
24
|
+
export type InfoObject = {
|
|
25
|
+
title: string;
|
|
26
|
+
version: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
summary?: string;
|
|
29
|
+
termsOfService?: string;
|
|
30
|
+
contact?: ContactObject;
|
|
31
|
+
license?: LicenseObject;
|
|
32
|
+
[key: `x-${string}`]: unknown;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Contact information for the API.
|
|
36
|
+
* @see https://spec.openapis.org/oas/v3.1.0#contact-object
|
|
37
|
+
*/
|
|
38
|
+
export type ContactObject = {
|
|
39
|
+
name?: string;
|
|
40
|
+
url?: string;
|
|
41
|
+
email?: string;
|
|
42
|
+
[key: `x-${string}`]: unknown;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* License information for the API.
|
|
46
|
+
* @see https://spec.openapis.org/oas/v3.1.0#license-object
|
|
47
|
+
*/
|
|
48
|
+
export type LicenseObject = {
|
|
49
|
+
name: string;
|
|
50
|
+
identifier?: string;
|
|
51
|
+
url?: string;
|
|
52
|
+
[key: `x-${string}`]: unknown;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* A reference to external documentation.
|
|
56
|
+
* @see https://spec.openapis.org/oas/v3.1.0#external-documentation-object
|
|
57
|
+
*/
|
|
58
|
+
export type ExternalDocumentationObject = {
|
|
59
|
+
url: string;
|
|
60
|
+
description?: string;
|
|
61
|
+
[key: `x-${string}`]: unknown;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* An object representing a server.
|
|
65
|
+
* @see https://spec.openapis.org/oas/v3.1.0#server-object
|
|
66
|
+
*/
|
|
67
|
+
export type ServerObject = {
|
|
68
|
+
url: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
variables?: Record<string, ServerVariableObject>;
|
|
71
|
+
[key: `x-${string}`]: unknown;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* An object representing a server variable for server URL template substitution.
|
|
75
|
+
* @see https://spec.openapis.org/oas/v3.1.0#server-variable-object
|
|
76
|
+
*/
|
|
77
|
+
export type ServerVariableObject = {
|
|
78
|
+
default: string;
|
|
79
|
+
description?: string;
|
|
80
|
+
enum?: string[];
|
|
81
|
+
[key: `x-${string}`]: unknown;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Adds metadata to a single tag used by operations.
|
|
85
|
+
* @see https://spec.openapis.org/oas/v3.1.0#tag-object
|
|
86
|
+
*/
|
|
87
|
+
export type TagObject = {
|
|
88
|
+
name: string;
|
|
89
|
+
description?: string;
|
|
90
|
+
externalDocs?: ExternalDocumentationObject;
|
|
91
|
+
[key: `x-${string}`]: unknown;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Lists the required security schemes to execute an operation.
|
|
95
|
+
* Each entry maps a security scheme name to a list of required scopes.
|
|
96
|
+
* @see https://spec.openapis.org/oas/v3.1.0#security-requirement-object
|
|
97
|
+
*/
|
|
98
|
+
export type SecurityRequirementObject = Record<string, string[]>;
|
|
99
|
+
/**
|
|
100
|
+
* Holds a set of reusable objects for the OpenAPI document.
|
|
101
|
+
* @see https://spec.openapis.org/oas/v3.1.0#components-object
|
|
102
|
+
*/
|
|
103
|
+
export type ComponentsObject = {
|
|
104
|
+
schemas?: Record<string, object | boolean>;
|
|
105
|
+
responses?: Record<string, ResponseObject | ReferenceObject>;
|
|
106
|
+
parameters?: Record<string, ParameterObject | ReferenceObject>;
|
|
107
|
+
examples?: Record<string, ExampleObject | ReferenceObject>;
|
|
108
|
+
requestBodies?: Record<string, RequestBodyObject | ReferenceObject>;
|
|
109
|
+
headers?: Record<string, HeaderObject | ReferenceObject>;
|
|
110
|
+
securitySchemes?: Record<string, SecuritySchemeObject | ReferenceObject>;
|
|
111
|
+
links?: Record<string, LinkObject | ReferenceObject>;
|
|
112
|
+
callbacks?: Record<string, CallbackObject | ReferenceObject>;
|
|
113
|
+
pathItems?: Record<string, PathItem | ReferenceObject>;
|
|
114
|
+
[key: `x-${string}`]: unknown;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* A JSON Reference object pointing to another location in the document or an external resource.
|
|
118
|
+
* @see https://spec.openapis.org/oas/v3.1.0#reference-object
|
|
119
|
+
*/
|
|
120
|
+
export type ReferenceObject = {
|
|
121
|
+
$ref: string;
|
|
122
|
+
description?: string;
|
|
123
|
+
summary?: string;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Describes the operations available on a single path.
|
|
127
|
+
* @see https://spec.openapis.org/oas/v3.1.0#path-item-object
|
|
128
|
+
*/
|
|
129
|
+
export type PathItem = {
|
|
130
|
+
summary?: string;
|
|
131
|
+
description?: string;
|
|
132
|
+
get?: Operation;
|
|
133
|
+
put?: Operation;
|
|
134
|
+
post?: Operation;
|
|
135
|
+
delete?: Operation;
|
|
136
|
+
options?: Operation;
|
|
137
|
+
head?: Operation;
|
|
138
|
+
patch?: Operation;
|
|
139
|
+
trace?: Operation;
|
|
140
|
+
servers?: ServerObject[];
|
|
141
|
+
parameters?: Array<ParameterObject | ReferenceObject>;
|
|
142
|
+
[key: `x-${string}`]: unknown;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Describes a single API operation on a path.
|
|
146
|
+
* @see https://spec.openapis.org/oas/v3.1.0#operation-object
|
|
147
|
+
*/
|
|
148
|
+
export type Operation = {
|
|
149
|
+
tags?: string[];
|
|
150
|
+
summary?: string;
|
|
151
|
+
description?: string;
|
|
152
|
+
externalDocs?: ExternalDocumentationObject;
|
|
153
|
+
operationId?: string;
|
|
154
|
+
parameters?: Array<ParameterObject | ReferenceObject>;
|
|
155
|
+
requestBody?: RequestBodyObject | ReferenceObject;
|
|
156
|
+
responses: ResponsesObject;
|
|
157
|
+
callbacks?: Record<string, CallbackObject | ReferenceObject>;
|
|
158
|
+
deprecated?: boolean;
|
|
159
|
+
security?: SecurityRequirementObject[];
|
|
160
|
+
servers?: ServerObject[];
|
|
161
|
+
[key: `x-${string}`]: unknown;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Describes a single operation parameter (path, query, header, or cookie).
|
|
165
|
+
* @see https://spec.openapis.org/oas/v3.1.0#parameter-object
|
|
166
|
+
*/
|
|
167
|
+
export type ParameterObject = {
|
|
168
|
+
name: string;
|
|
169
|
+
in: 'query' | 'header' | 'path' | 'cookie';
|
|
170
|
+
description?: string;
|
|
171
|
+
required?: boolean;
|
|
172
|
+
deprecated?: boolean;
|
|
173
|
+
allowEmptyValue?: boolean;
|
|
174
|
+
style?: string;
|
|
175
|
+
explode?: boolean;
|
|
176
|
+
allowReserved?: boolean;
|
|
177
|
+
schema?: object | boolean;
|
|
178
|
+
example?: unknown;
|
|
179
|
+
examples?: Record<string, ExampleObject | ReferenceObject>;
|
|
180
|
+
content?: Record<string, MediaTypeObject>;
|
|
181
|
+
[key: `x-${string}`]: unknown;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Describes the request body of an operation.
|
|
185
|
+
* @see https://spec.openapis.org/oas/v3.1.0#request-body-object
|
|
186
|
+
*/
|
|
187
|
+
export type RequestBodyObject = {
|
|
188
|
+
description?: string;
|
|
189
|
+
content: Record<string, MediaTypeObject>;
|
|
190
|
+
required?: boolean;
|
|
191
|
+
[key: `x-${string}`]: unknown;
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* Describes the content of a request body or response for a specific media type.
|
|
195
|
+
* @see https://spec.openapis.org/oas/v3.1.0#media-type-object
|
|
196
|
+
*/
|
|
197
|
+
export type MediaTypeObject = {
|
|
198
|
+
schema?: object | boolean;
|
|
199
|
+
example?: unknown;
|
|
200
|
+
examples?: Record<string, ExampleObject | ReferenceObject>;
|
|
201
|
+
encoding?: Record<string, EncodingObject>;
|
|
202
|
+
[key: `x-${string}`]: unknown;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Describes the encoding properties for a specific property in a request body.
|
|
206
|
+
* @see https://spec.openapis.org/oas/v3.1.0#encoding-object
|
|
207
|
+
*/
|
|
208
|
+
export type EncodingObject = {
|
|
209
|
+
contentType?: string;
|
|
210
|
+
headers?: Record<string, HeaderObject | ReferenceObject>;
|
|
211
|
+
style?: string;
|
|
212
|
+
explode?: boolean;
|
|
213
|
+
allowReserved?: boolean;
|
|
214
|
+
[key: `x-${string}`]: unknown;
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* A map of HTTP status codes to response objects describing the operation responses.
|
|
218
|
+
* @see https://spec.openapis.org/oas/v3.1.0#responses-object
|
|
219
|
+
*/
|
|
220
|
+
export type ResponsesObject = Record<string, ResponseObject | ReferenceObject>;
|
|
221
|
+
/**
|
|
222
|
+
* Describes a single response from an API operation.
|
|
223
|
+
* @see https://spec.openapis.org/oas/v3.1.0#response-object
|
|
224
|
+
*/
|
|
225
|
+
export type ResponseObject = {
|
|
226
|
+
description: string;
|
|
227
|
+
headers?: Record<string, HeaderObject | ReferenceObject>;
|
|
228
|
+
content?: Record<string, MediaTypeObject>;
|
|
229
|
+
links?: Record<string, LinkObject | ReferenceObject>;
|
|
230
|
+
[key: `x-${string}`]: unknown;
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Describes a header parameter, equivalent to a ParameterObject without `name` and `in`.
|
|
234
|
+
* @see https://spec.openapis.org/oas/v3.1.0#header-object
|
|
235
|
+
*/
|
|
236
|
+
export type HeaderObject = Omit<ParameterObject, 'name' | 'in'>;
|
|
237
|
+
/**
|
|
238
|
+
* An object holding a reusable example value.
|
|
239
|
+
* @see https://spec.openapis.org/oas/v3.1.0#example-object
|
|
240
|
+
*/
|
|
241
|
+
export type ExampleObject = {
|
|
242
|
+
summary?: string;
|
|
243
|
+
description?: string;
|
|
244
|
+
value?: unknown;
|
|
245
|
+
externalValue?: string;
|
|
246
|
+
[key: `x-${string}`]: unknown;
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Represents a possible design-time link for a response.
|
|
250
|
+
* @see https://spec.openapis.org/oas/v3.1.0#link-object
|
|
251
|
+
*/
|
|
252
|
+
export type LinkObject = {
|
|
253
|
+
operationRef?: string;
|
|
254
|
+
operationId?: string;
|
|
255
|
+
parameters?: Record<string, unknown>;
|
|
256
|
+
requestBody?: unknown;
|
|
257
|
+
description?: string;
|
|
258
|
+
server?: ServerObject;
|
|
259
|
+
[key: `x-${string}`]: unknown;
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* A map of callback objects keyed by expression.
|
|
263
|
+
* @see https://spec.openapis.org/oas/v3.1.0#callback-object
|
|
264
|
+
*/
|
|
265
|
+
export type CallbackObject = Record<string, PathItem>;
|
|
266
|
+
/**
|
|
267
|
+
* Defines a security scheme for the API (apiKey, http, oauth2, openIdConnect, or mutualTLS).
|
|
268
|
+
* @see https://spec.openapis.org/oas/v3.1.0#security-scheme-object
|
|
269
|
+
*/
|
|
270
|
+
export type SecuritySchemeObject = {
|
|
271
|
+
type: 'apiKey' | 'http' | 'mutualTLS' | 'oauth2' | 'openIdConnect';
|
|
272
|
+
description?: string;
|
|
273
|
+
name?: string;
|
|
274
|
+
in?: 'query' | 'header' | 'cookie';
|
|
275
|
+
scheme?: string;
|
|
276
|
+
bearerFormat?: string;
|
|
277
|
+
flows?: OAuthFlowsObject;
|
|
278
|
+
openIdConnectUrl?: string;
|
|
279
|
+
[key: `x-${string}`]: unknown;
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Allows configuration of the supported OAuth flows.
|
|
283
|
+
* @see https://spec.openapis.org/oas/v3.1.0#oauth-flows-object
|
|
284
|
+
*/
|
|
285
|
+
export type OAuthFlowsObject = {
|
|
286
|
+
implicit?: OAuthFlowObject;
|
|
287
|
+
password?: OAuthFlowObject;
|
|
288
|
+
clientCredentials?: OAuthFlowObject;
|
|
289
|
+
authorizationCode?: OAuthFlowObject;
|
|
290
|
+
[key: `x-${string}`]: unknown;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Configuration details for a specific OAuth flow type.
|
|
294
|
+
* @see https://spec.openapis.org/oas/v3.1.0#oauth-flow-object
|
|
295
|
+
*/
|
|
296
|
+
export type OAuthFlowObject = {
|
|
297
|
+
authorizationUrl?: string;
|
|
298
|
+
tokenUrl?: string;
|
|
299
|
+
refreshUrl?: string;
|
|
300
|
+
scopes: Record<string, string>;
|
|
301
|
+
[key: `x-${string}`]: unknown;
|
|
302
|
+
};
|
|
303
|
+
//# sourceMappingURL=openapi-document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-document.d.ts","sourceRoot":"","sources":["../src/openapi-document.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAA;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"version":3,"file":"openapi-document.js","sourceRoot":"","sources":["../src/openapi-document.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { OpenApiDocument } from './openapi-document.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves all internal `$ref` pointers in an OpenAPI document, inlining the referenced objects.
|
|
4
|
+
*
|
|
5
|
+
* Only internal references (`#/...`) are supported. External file references are left as-is.
|
|
6
|
+
* Circular references are broken by substituting an empty object `{}`.
|
|
7
|
+
*
|
|
8
|
+
* @param doc - The OpenAPI document with `$ref` pointers
|
|
9
|
+
* @returns A new OpenAPI document with all internal `$ref` pointers resolved
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { resolveOpenApiRefs } from '@furystack/rest'
|
|
14
|
+
*
|
|
15
|
+
* const resolved = resolveOpenApiRefs(myOpenApiDoc)
|
|
16
|
+
* // All $ref pointers have been replaced with the actual schemas
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const resolveOpenApiRefs: (doc: OpenApiDocument) => OpenApiDocument;
|
|
20
|
+
//# sourceMappingURL=openapi-resolve-refs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-resolve-refs.d.ts","sourceRoot":"","sources":["../src/openapi-resolve-refs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAmD5D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,eAAe,KAAG,eAEzD,CAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves an internal JSON Pointer (e.g. `#/components/schemas/User`) against a document tree.
|
|
3
|
+
*/
|
|
4
|
+
const resolvePointer = (root, pointer) => {
|
|
5
|
+
const segments = pointer
|
|
6
|
+
.replace(/^#\//, '')
|
|
7
|
+
.split('/')
|
|
8
|
+
.map((s) => s.replace(/~1/g, '/').replace(/~0/g, '~'));
|
|
9
|
+
let current = root;
|
|
10
|
+
for (const segment of segments) {
|
|
11
|
+
if (current === null || current === undefined || typeof current !== 'object')
|
|
12
|
+
return undefined;
|
|
13
|
+
current = current[segment];
|
|
14
|
+
}
|
|
15
|
+
return current;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Deep-walks a value and replaces all `{ $ref: "#/..." }` objects with the resolved target.
|
|
19
|
+
* Tracks visited `$ref` strings to prevent infinite loops from circular references.
|
|
20
|
+
*/
|
|
21
|
+
const resolveNode = (node, root, visited) => {
|
|
22
|
+
if (node === null || node === undefined || typeof node !== 'object')
|
|
23
|
+
return node;
|
|
24
|
+
if (Array.isArray(node)) {
|
|
25
|
+
return node.map((item) => resolveNode(item, root, visited));
|
|
26
|
+
}
|
|
27
|
+
const obj = node;
|
|
28
|
+
if (typeof obj.$ref === 'string') {
|
|
29
|
+
const ref = obj.$ref;
|
|
30
|
+
if (!ref.startsWith('#/'))
|
|
31
|
+
return node;
|
|
32
|
+
if (visited.has(ref))
|
|
33
|
+
return {};
|
|
34
|
+
visited.add(ref);
|
|
35
|
+
const resolved = resolvePointer(root, ref);
|
|
36
|
+
if (resolved === undefined)
|
|
37
|
+
return node;
|
|
38
|
+
const result = resolveNode(resolved, root, new Set(visited));
|
|
39
|
+
visited.delete(ref);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
const result = {};
|
|
43
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
44
|
+
result[key] = resolveNode(value, root, visited);
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Resolves all internal `$ref` pointers in an OpenAPI document, inlining the referenced objects.
|
|
50
|
+
*
|
|
51
|
+
* Only internal references (`#/...`) are supported. External file references are left as-is.
|
|
52
|
+
* Circular references are broken by substituting an empty object `{}`.
|
|
53
|
+
*
|
|
54
|
+
* @param doc - The OpenAPI document with `$ref` pointers
|
|
55
|
+
* @returns A new OpenAPI document with all internal `$ref` pointers resolved
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { resolveOpenApiRefs } from '@furystack/rest'
|
|
60
|
+
*
|
|
61
|
+
* const resolved = resolveOpenApiRefs(myOpenApiDoc)
|
|
62
|
+
* // All $ref pointers have been replaced with the actual schemas
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export const resolveOpenApiRefs = (doc) => {
|
|
66
|
+
return resolveNode(structuredClone(doc), doc, new Set());
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=openapi-resolve-refs.js.map
|