@orpc/openapi 0.18.0 → 0.20.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.
@@ -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>;
@@ -1,3 +1,12 @@
1
1
  /** unnoq */
2
- export * from './generator';
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,5 @@
1
+ export declare class JSONSerializer {
2
+ serialize(payload: unknown): unknown;
3
+ }
4
+ export type PublicJSONSerializer = Pick<JSONSerializer, keyof JSONSerializer>;
5
+ //# sourceMappingURL=json-serializer.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,8 @@
1
+ export declare class OpenAPIPathParser {
2
+ parseDynamicParams(path: string): {
3
+ name: string;
4
+ raw: string;
5
+ }[];
6
+ }
7
+ export type PublicOpenAPIPathParser = Pick<OpenAPIPathParser, keyof OpenAPIPathParser>;
8
+ //# sourceMappingURL=openapi-path-parser.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { OpenApiBuilder } from 'openapi3-ts/oas31';
2
+ export type * as OpenAPI from 'openapi3-ts/oas31';
3
+ //# sourceMappingURL=openapi.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
@@ -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.18.0",
4
+ "version": "0.20.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/shared": "0.18.0",
47
- "@orpc/contract": "0.18.0",
48
- "@orpc/server": "0.18.0"
46
+ "@orpc/contract": "0.20.0",
47
+ "@orpc/shared": "0.20.0",
48
+ "@orpc/server": "0.20.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@readme/openapi-parser": "^2.6.0",