@orpc/openapi 0.0.0-next.df486d6 → 0.0.0-next.e0f01a5
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/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.mjs +21 -17
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ import { OpenAPIV3_1 } from 'openapi-types';
|
|
|
3
3
|
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
4
4
|
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
5
5
|
import { AnyRouter } from '@orpc/server';
|
|
6
|
+
import { Promisable } from '@orpc/shared';
|
|
6
7
|
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
7
8
|
export { JSONSchema, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
|
8
9
|
import { HTTPPath, HTTPMethod } from '@orpc/client';
|
|
@@ -34,15 +35,15 @@ interface SchemaConvertOptions {
|
|
|
34
35
|
strategy: 'input' | 'output';
|
|
35
36
|
}
|
|
36
37
|
interface SchemaConverter {
|
|
37
|
-
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema]
|
|
38
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
38
39
|
}
|
|
39
40
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
40
|
-
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): boolean
|
|
41
|
+
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
41
42
|
}
|
|
42
43
|
declare class CompositeSchemaConverter implements SchemaConverter {
|
|
43
44
|
private readonly converters;
|
|
44
45
|
constructor(converters: ConditionalSchemaConverter[]);
|
|
45
|
-
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema]
|
|
46
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { OpenAPIV3_1 } from 'openapi-types';
|
|
|
3
3
|
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
4
4
|
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
5
5
|
import { AnyRouter } from '@orpc/server';
|
|
6
|
+
import { Promisable } from '@orpc/shared';
|
|
6
7
|
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
7
8
|
export { JSONSchema, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
|
8
9
|
import { HTTPPath, HTTPMethod } from '@orpc/client';
|
|
@@ -34,15 +35,15 @@ interface SchemaConvertOptions {
|
|
|
34
35
|
strategy: 'input' | 'output';
|
|
35
36
|
}
|
|
36
37
|
interface SchemaConverter {
|
|
37
|
-
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema]
|
|
38
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
38
39
|
}
|
|
39
40
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
40
|
-
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): boolean
|
|
41
|
+
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
41
42
|
}
|
|
42
43
|
declare class CompositeSchemaConverter implements SchemaConverter {
|
|
43
44
|
private readonly converters;
|
|
44
45
|
constructor(converters: ConditionalSchemaConverter[]);
|
|
45
|
-
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema]
|
|
46
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
|
package/dist/index.mjs
CHANGED
|
@@ -287,9 +287,9 @@ class CompositeSchemaConverter {
|
|
|
287
287
|
constructor(converters) {
|
|
288
288
|
this.converters = converters;
|
|
289
289
|
}
|
|
290
|
-
convert(schema, options) {
|
|
290
|
+
async convert(schema, options) {
|
|
291
291
|
for (const converter of this.converters) {
|
|
292
|
-
if (converter.condition(schema, options)) {
|
|
292
|
+
if (await converter.condition(schema, options)) {
|
|
293
293
|
return converter.convert(schema, options);
|
|
294
294
|
}
|
|
295
295
|
}
|
|
@@ -309,8 +309,12 @@ class OpenAPIGenerator {
|
|
|
309
309
|
async generate(router, base) {
|
|
310
310
|
const doc = clone(base);
|
|
311
311
|
doc.openapi = "3.1.1";
|
|
312
|
-
const
|
|
312
|
+
const contracts = [];
|
|
313
313
|
await resolveContractProcedures({ path: [], router }, ({ contract, path }) => {
|
|
314
|
+
contracts.push({ contract, path });
|
|
315
|
+
});
|
|
316
|
+
const errors = [];
|
|
317
|
+
for (const { contract, path } of contracts) {
|
|
314
318
|
const operationId = path.join(".");
|
|
315
319
|
try {
|
|
316
320
|
const def = contract["~orpc"];
|
|
@@ -323,9 +327,9 @@ class OpenAPIGenerator {
|
|
|
323
327
|
deprecated: def.route.deprecated,
|
|
324
328
|
tags: def.route.tags?.map((tag) => tag)
|
|
325
329
|
};
|
|
326
|
-
this.#request(operationObjectRef, def);
|
|
327
|
-
this.#successResponse(operationObjectRef, def);
|
|
328
|
-
this.#errorResponse(operationObjectRef, def);
|
|
330
|
+
await this.#request(operationObjectRef, def);
|
|
331
|
+
await this.#successResponse(operationObjectRef, def);
|
|
332
|
+
await this.#errorResponse(operationObjectRef, def);
|
|
329
333
|
doc.paths ??= {};
|
|
330
334
|
doc.paths[httpPath] ??= {};
|
|
331
335
|
doc.paths[httpPath][method] = applyCustomOpenAPIOperation(operationObjectRef, contract);
|
|
@@ -338,7 +342,7 @@ class OpenAPIGenerator {
|
|
|
338
342
|
${e.message}`
|
|
339
343
|
);
|
|
340
344
|
}
|
|
341
|
-
}
|
|
345
|
+
}
|
|
342
346
|
if (errors.length) {
|
|
343
347
|
throw new OpenAPIGeneratorError(
|
|
344
348
|
`Some error occurred during OpenAPI generation:
|
|
@@ -348,22 +352,22 @@ ${errors.join("\n\n")}`
|
|
|
348
352
|
}
|
|
349
353
|
return this.serializer.serialize(doc)[0];
|
|
350
354
|
}
|
|
351
|
-
#request(ref, def) {
|
|
355
|
+
async #request(ref, def) {
|
|
352
356
|
const method = fallbackContractConfig("defaultMethod", def.route.method);
|
|
353
357
|
const details = getEventIteratorSchemaDetails(def.inputSchema);
|
|
354
358
|
if (details) {
|
|
355
359
|
ref.requestBody = {
|
|
356
360
|
required: true,
|
|
357
361
|
content: toOpenAPIEventIteratorContent(
|
|
358
|
-
this.converter.convert(details.yields, { strategy: "input" }),
|
|
359
|
-
this.converter.convert(details.returns, { strategy: "input" })
|
|
362
|
+
await this.converter.convert(details.yields, { strategy: "input" }),
|
|
363
|
+
await this.converter.convert(details.returns, { strategy: "input" })
|
|
360
364
|
)
|
|
361
365
|
};
|
|
362
366
|
return;
|
|
363
367
|
}
|
|
364
368
|
const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
|
|
365
369
|
const inputStructure = fallbackContractConfig("defaultInputStructure", def.route.inputStructure);
|
|
366
|
-
let [required, schema] = this.converter.convert(def.inputSchema, { strategy: "input" });
|
|
370
|
+
let [required, schema] = await this.converter.convert(def.inputSchema, { strategy: "input" });
|
|
367
371
|
if (isAnySchema(schema) && !dynamicParams?.length) {
|
|
368
372
|
return;
|
|
369
373
|
}
|
|
@@ -429,7 +433,7 @@ ${errors.join("\n\n")}`
|
|
|
429
433
|
};
|
|
430
434
|
}
|
|
431
435
|
}
|
|
432
|
-
#successResponse(ref, def) {
|
|
436
|
+
async #successResponse(ref, def) {
|
|
433
437
|
const outputSchema = def.outputSchema;
|
|
434
438
|
const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
|
|
435
439
|
const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
|
|
@@ -440,13 +444,13 @@ ${errors.join("\n\n")}`
|
|
|
440
444
|
ref.responses[status] = {
|
|
441
445
|
description,
|
|
442
446
|
content: toOpenAPIEventIteratorContent(
|
|
443
|
-
this.converter.convert(eventIteratorSchemaDetails.yields, { strategy: "output" }),
|
|
444
|
-
this.converter.convert(eventIteratorSchemaDetails.returns, { strategy: "output" })
|
|
447
|
+
await this.converter.convert(eventIteratorSchemaDetails.yields, { strategy: "output" }),
|
|
448
|
+
await this.converter.convert(eventIteratorSchemaDetails.returns, { strategy: "output" })
|
|
445
449
|
)
|
|
446
450
|
};
|
|
447
451
|
return;
|
|
448
452
|
}
|
|
449
|
-
const [required, json] = this.converter.convert(outputSchema, { strategy: "output" });
|
|
453
|
+
const [required, json] = await this.converter.convert(outputSchema, { strategy: "output" });
|
|
450
454
|
ref.responses ??= {};
|
|
451
455
|
ref.responses[status] = {
|
|
452
456
|
description
|
|
@@ -479,7 +483,7 @@ ${errors.join("\n\n")}`
|
|
|
479
483
|
);
|
|
480
484
|
}
|
|
481
485
|
}
|
|
482
|
-
#errorResponse(ref, def) {
|
|
486
|
+
async #errorResponse(ref, def) {
|
|
483
487
|
const errorMap = def.errorMap;
|
|
484
488
|
const errors = {};
|
|
485
489
|
for (const code in errorMap) {
|
|
@@ -489,7 +493,7 @@ ${errors.join("\n\n")}`
|
|
|
489
493
|
}
|
|
490
494
|
const status = fallbackORPCErrorStatus(code, config.status);
|
|
491
495
|
const message = fallbackORPCErrorMessage(code, config.message);
|
|
492
|
-
const [dataRequired, dataSchema] = this.converter.convert(config.data, { strategy: "output" });
|
|
496
|
+
const [dataRequired, dataSchema] = await this.converter.convert(config.data, { strategy: "output" });
|
|
493
497
|
errors[status] ??= [];
|
|
494
498
|
errors[status].push({
|
|
495
499
|
type: "object",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.e0f01a5",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"json-schema-typed": "^8.0.1",
|
|
43
43
|
"openapi-types": "^12.1.3",
|
|
44
44
|
"rou3": "^0.5.1",
|
|
45
|
-
"@orpc/client": "0.0.0-next.
|
|
46
|
-
"@orpc/
|
|
47
|
-
"@orpc/
|
|
48
|
-
"@orpc/
|
|
49
|
-
"@orpc/
|
|
50
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
45
|
+
"@orpc/client": "0.0.0-next.e0f01a5",
|
|
46
|
+
"@orpc/openapi-client": "0.0.0-next.e0f01a5",
|
|
47
|
+
"@orpc/shared": "0.0.0-next.e0f01a5",
|
|
48
|
+
"@orpc/contract": "0.0.0-next.e0f01a5",
|
|
49
|
+
"@orpc/server": "0.0.0-next.e0f01a5",
|
|
50
|
+
"@orpc/standard-server": "0.0.0-next.e0f01a5"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"zod": "^3.24.2"
|