@orpc/openapi 0.18.0 → 0.19.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/dist/chunk-KNYXLM77.js +107 -0
- package/dist/fetch.js +574 -14
- package/dist/index.js +255 -4501
- package/dist/src/fetch/openapi-handler.d.ts +2 -0
- package/dist/src/fetch/openapi-payload-codec.d.ts +3 -1
- package/dist/src/index.d.ts +10 -1
- package/dist/src/json-serializer.d.ts +5 -0
- package/dist/src/openapi-content-builder.d.ts +10 -0
- package/dist/src/openapi-generator.d.ts +51 -0
- package/dist/src/openapi-parameters-builder.d.ts +9 -0
- package/dist/src/openapi-path-parser.d.ts +8 -0
- package/dist/src/openapi.d.ts +3 -0
- package/dist/src/schema-converter.d.ts +16 -0
- package/dist/src/schema-utils.d.ts +11 -0
- package/dist/src/schema.d.ts +12 -0
- package/dist/src/utils.d.ts +1 -0
- package/package.json +4 -4
- package/dist/chunk-UPDKQRQG.js +0 -665
- package/dist/src/generator.d.ts +0 -26
- package/dist/src/zod-to-json-schema.d.ts +0 -43
|
@@ -2,11 +2,13 @@ import type { ConditionalFetchHandler, FetchOptions } from '@orpc/server/fetch';
|
|
|
2
2
|
import type { PublicInputBuilderSimple } from './input-builder-simple';
|
|
3
3
|
import { type Context, type Router, type WithSignal } from '@orpc/server';
|
|
4
4
|
import { type Hooks } from '@orpc/shared';
|
|
5
|
+
import { type PublicJSONSerializer } from '../json-serializer';
|
|
5
6
|
import { type PublicInputBuilderFull } from './input-builder-full';
|
|
6
7
|
import { type PublicOpenAPIPayloadCodec } from './openapi-payload-codec';
|
|
7
8
|
import { type Hono, type PublicOpenAPIProcedureMatcher } from './openapi-procedure-matcher';
|
|
8
9
|
import { type SchemaCoercer } from './schema-coercer';
|
|
9
10
|
export type OpenAPIHandlerOptions<T extends Context> = Hooks<Request, Response, T, WithSignal> & {
|
|
11
|
+
jsonSerializer?: PublicJSONSerializer;
|
|
10
12
|
procedureMatcher?: PublicOpenAPIProcedureMatcher;
|
|
11
13
|
payloadCodec?: PublicOpenAPIPayloadCodec;
|
|
12
14
|
inputBuilderSimple?: PublicInputBuilderSimple;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import type { PublicJSONSerializer } from '../json-serializer';
|
|
1
2
|
export declare class OpenAPIPayloadCodec {
|
|
3
|
+
private readonly jsonSerializer;
|
|
4
|
+
constructor(jsonSerializer: PublicJSONSerializer);
|
|
2
5
|
encode(payload: unknown, accept?: string): {
|
|
3
6
|
body: FormData | Blob | string | undefined;
|
|
4
7
|
headers?: Headers;
|
|
@@ -6,7 +9,6 @@ export declare class OpenAPIPayloadCodec {
|
|
|
6
9
|
private encodeAsJSON;
|
|
7
10
|
private encodeAsFormData;
|
|
8
11
|
private encodeAsURLSearchParams;
|
|
9
|
-
serialize(payload: unknown): unknown;
|
|
10
12
|
decode(re: Request | Response | Headers | URLSearchParams | FormData): Promise<unknown>;
|
|
11
13
|
}
|
|
12
14
|
export type PublicOpenAPIPayloadCodec = Pick<OpenAPIPayloadCodec, keyof OpenAPIPayloadCodec>;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
/** unnoq */
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './json-serializer';
|
|
3
|
+
export * from './openapi';
|
|
4
|
+
export * from './openapi-content-builder';
|
|
5
|
+
export * from './openapi-generator';
|
|
6
|
+
export * from './openapi-parameters-builder';
|
|
7
|
+
export * from './openapi-path-parser';
|
|
8
|
+
export * from './schema';
|
|
9
|
+
export * from './schema-converter';
|
|
10
|
+
export * from './schema-utils';
|
|
11
|
+
export * from './utils';
|
|
3
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { OpenAPI } from './openapi';
|
|
2
|
+
import type { JSONSchema } from './schema';
|
|
3
|
+
import type { PublicSchemaUtils } from './schema-utils';
|
|
4
|
+
export declare class OpenAPIContentBuilder {
|
|
5
|
+
private readonly schemaUtils;
|
|
6
|
+
constructor(schemaUtils: PublicSchemaUtils);
|
|
7
|
+
build(jsonSchema: JSONSchema.JSONSchema, options?: Partial<OpenAPI.MediaTypeObject>): OpenAPI.ContentObject;
|
|
8
|
+
}
|
|
9
|
+
export type PublicOpenAPIContentBuilder = Pick<OpenAPIContentBuilder, keyof OpenAPIContentBuilder>;
|
|
10
|
+
//# sourceMappingURL=openapi-content-builder.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ContractRouter } from '@orpc/contract';
|
|
2
|
+
import type { ANY_ROUTER } from '@orpc/server';
|
|
3
|
+
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
4
|
+
import type { SchemaConverter } from './schema-converter';
|
|
5
|
+
import { type PublicJSONSerializer } from './json-serializer';
|
|
6
|
+
import { type OpenAPI } from './openapi';
|
|
7
|
+
import { type PublicOpenAPIContentBuilder } from './openapi-content-builder';
|
|
8
|
+
import { type PublicOpenAPIParametersBuilder } from './openapi-parameters-builder';
|
|
9
|
+
import { type PublicSchemaUtils } from './schema-utils';
|
|
10
|
+
export interface OpenAPIGeneratorOptions {
|
|
11
|
+
contentBuilder?: PublicOpenAPIContentBuilder;
|
|
12
|
+
parametersBuilder?: PublicOpenAPIParametersBuilder;
|
|
13
|
+
schemaConverters?: SchemaConverter[];
|
|
14
|
+
schemaUtils?: PublicSchemaUtils;
|
|
15
|
+
jsonSerializer?: PublicJSONSerializer;
|
|
16
|
+
pathParser?: PublicOpenAPIPathParser;
|
|
17
|
+
/**
|
|
18
|
+
* Throw error when you missing define tag definition on OpenAPI root tags
|
|
19
|
+
*
|
|
20
|
+
* Example: if procedure has tags ['foo', 'bar'], and OpenAPI root tags is ['foo'], then error will be thrown
|
|
21
|
+
* Because OpenAPI root tags is missing 'bar' tag
|
|
22
|
+
*
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
considerMissingTagDefinitionAsError?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Weather ignore procedures that has no path defined.
|
|
28
|
+
*
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
ignoreUndefinedPathProcedures?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Throw error when you have error in OpenAPI generator
|
|
34
|
+
*
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
throwOnError?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare class OpenAPIGenerator {
|
|
40
|
+
private readonly options?;
|
|
41
|
+
private readonly contentBuilder;
|
|
42
|
+
private readonly parametersBuilder;
|
|
43
|
+
private readonly schemaConverter;
|
|
44
|
+
private readonly schemaUtils;
|
|
45
|
+
private readonly jsonSerializer;
|
|
46
|
+
private readonly pathParser;
|
|
47
|
+
constructor(options?: OpenAPIGeneratorOptions | undefined);
|
|
48
|
+
generate(router: ContractRouter | ANY_ROUTER, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
|
|
49
|
+
private handleError;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=openapi-generator.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OpenAPI } from './openapi';
|
|
2
|
+
import type { JSONSchema } from './schema';
|
|
3
|
+
export declare class OpenAPIParametersBuilder {
|
|
4
|
+
build(paramIn: OpenAPI.ParameterObject['in'], jsonSchema: JSONSchema.JSONSchema & {
|
|
5
|
+
type: 'object';
|
|
6
|
+
} & object, options?: Pick<OpenAPI.ParameterObject, 'example' | 'style' | 'required'>): OpenAPI.ParameterObject[];
|
|
7
|
+
}
|
|
8
|
+
export type PublicOpenAPIParametersBuilder = Pick<OpenAPIParametersBuilder, keyof OpenAPIParametersBuilder>;
|
|
9
|
+
//# sourceMappingURL=openapi-parameters-builder.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Schema } from '@orpc/contract';
|
|
2
|
+
import type { JSONSchema } from './schema';
|
|
3
|
+
export interface SchemaConvertOptions {
|
|
4
|
+
strategy: 'input' | 'output';
|
|
5
|
+
}
|
|
6
|
+
export interface SchemaConverter {
|
|
7
|
+
condition: (schema: Schema, options: SchemaConvertOptions) => boolean;
|
|
8
|
+
convert: (schema: Schema, options: SchemaConvertOptions) => JSONSchema.JSONSchema;
|
|
9
|
+
}
|
|
10
|
+
export declare class CompositeSchemaConverter implements SchemaConverter {
|
|
11
|
+
private readonly converters;
|
|
12
|
+
constructor(converters: SchemaConverter[]);
|
|
13
|
+
condition(): boolean;
|
|
14
|
+
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=schema-converter.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type FileSchema, type JSONSchema, type ObjectSchema } from './schema';
|
|
2
|
+
export declare class SchemaUtils {
|
|
3
|
+
isFileSchema(schema: JSONSchema.JSONSchema): schema is FileSchema;
|
|
4
|
+
isObjectSchema(schema: JSONSchema.JSONSchema): schema is ObjectSchema;
|
|
5
|
+
isAnySchema(schema: JSONSchema.JSONSchema): boolean;
|
|
6
|
+
isUndefinableSchema(schema: JSONSchema.JSONSchema): boolean;
|
|
7
|
+
separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
|
|
8
|
+
filterSchemaBranches(schema: JSONSchema.JSONSchema, check: (schema: JSONSchema.JSONSchema) => boolean, matches?: JSONSchema.JSONSchema[]): [matches: JSONSchema.JSONSchema[], rest: JSONSchema.JSONSchema | undefined];
|
|
9
|
+
}
|
|
10
|
+
export type PublicSchemaUtils = Pick<SchemaUtils, keyof SchemaUtils>;
|
|
11
|
+
//# sourceMappingURL=schema-utils.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as JSONSchema from 'json-schema-typed/draft-2020-12';
|
|
2
|
+
export { Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
|
3
|
+
export { JSONSchema };
|
|
4
|
+
export type ObjectSchema = JSONSchema.JSONSchema & {
|
|
5
|
+
type: 'object';
|
|
6
|
+
} & object;
|
|
7
|
+
export type FileSchema = JSONSchema.JSONSchema & {
|
|
8
|
+
type: 'string';
|
|
9
|
+
contentMediaType: string;
|
|
10
|
+
} & object;
|
|
11
|
+
export declare const NON_LOGIC_KEYWORDS: ("$anchor" | "$comment" | "$defs" | "$dynamicAnchor" | "$dynamicRef" | "$id" | "$schema" | "$vocabulary" | "contentEncoding" | "contentMediaType" | "default" | "definitions" | "deprecated" | "description" | "examples" | "format" | "readOnly" | "title" | "writeOnly")[];
|
|
12
|
+
//# sourceMappingURL=schema.d.ts.map
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -13,5 +13,6 @@ export interface EachContractLeafResultItem {
|
|
|
13
13
|
path: string[];
|
|
14
14
|
}
|
|
15
15
|
export declare function forEachContractProcedure(options: EachLeafOptions, callback: (options: EachLeafCallbackOptions) => void, result?: EachContractLeafResultItem[], isCurrentRouterContract?: boolean): EachContractLeafResultItem[];
|
|
16
|
+
export declare function forEachAllContractProcedure(router: ContractRouter | ANY_ROUTER, callback: (options: EachLeafCallbackOptions) => void): Promise<void>;
|
|
16
17
|
export declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
|
17
18
|
//# sourceMappingURL=utils.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.19.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"json-schema-typed": "^8.0.1",
|
|
44
44
|
"openapi3-ts": "^4.4.0",
|
|
45
45
|
"wildcard-match": "^5.1.3",
|
|
46
|
-
"@orpc/
|
|
47
|
-
"@orpc/
|
|
48
|
-
"@orpc/
|
|
46
|
+
"@orpc/contract": "0.19.0",
|
|
47
|
+
"@orpc/server": "0.19.0",
|
|
48
|
+
"@orpc/shared": "0.19.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@readme/openapi-parser": "^2.6.0",
|