@orpc/openapi 0.15.0 → 0.16.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/index.js CHANGED
@@ -3943,10 +3943,15 @@ var NON_LOGIC_KEYWORDS = [
3943
3943
  var UNSUPPORTED_JSON_SCHEMA = { not: {} };
3944
3944
  var UNDEFINED_JSON_SCHEMA = { const: "undefined" };
3945
3945
  function zodToJsonSchema(schema, options) {
3946
+ if (schema["~standard"].vendor !== "zod") {
3947
+ console.warn(`Generate JSON schema not support ${schema["~standard"].vendor} yet`);
3948
+ return {};
3949
+ }
3950
+ const schema__ = schema;
3946
3951
  if (!options?.isHandledCustomJSONSchema) {
3947
- const customJSONSchema = getCustomJSONSchema(schema._def, options);
3952
+ const customJSONSchema = getCustomJSONSchema(schema__._def, options);
3948
3953
  if (customJSONSchema) {
3949
- const json = zodToJsonSchema(schema, {
3954
+ const json = zodToJsonSchema(schema__, {
3950
3955
  ...options,
3951
3956
  isHandledCustomJSONSchema: true
3952
3957
  });
@@ -3957,13 +3962,13 @@ function zodToJsonSchema(schema, options) {
3957
3962
  }
3958
3963
  }
3959
3964
  const childOptions = { ...options, isHandledCustomJSONSchema: false };
3960
- const customType = getCustomZodType(schema._def);
3965
+ const customType = getCustomZodType(schema__._def);
3961
3966
  switch (customType) {
3962
3967
  case "Blob": {
3963
3968
  return { type: "string", contentMediaType: "*/*" };
3964
3969
  }
3965
3970
  case "File": {
3966
- const mimeType = getCustomZodFileMimeType(schema._def) ?? "*/*";
3971
+ const mimeType = getCustomZodFileMimeType(schema__._def) ?? "*/*";
3967
3972
  return { type: "string", contentMediaType: mimeType };
3968
3973
  }
3969
3974
  case "Invalid Date": {
@@ -3980,10 +3985,10 @@ function zodToJsonSchema(schema, options) {
3980
3985
  }
3981
3986
  }
3982
3987
  const _expectedCustomType = customType;
3983
- const typeName = schema._def.typeName;
3988
+ const typeName = schema__._def.typeName;
3984
3989
  switch (typeName) {
3985
3990
  case ZodFirstPartyTypeKind.ZodString: {
3986
- const schema_ = schema;
3991
+ const schema_ = schema__;
3987
3992
  const json = { type: "string" };
3988
3993
  for (const check of schema_._def.checks) {
3989
3994
  switch (check.kind) {
@@ -4065,7 +4070,7 @@ function zodToJsonSchema(schema, options) {
4065
4070
  return json;
4066
4071
  }
4067
4072
  case ZodFirstPartyTypeKind.ZodNumber: {
4068
- const schema_ = schema;
4073
+ const schema_ = schema__;
4069
4074
  const json = { type: "number" };
4070
4075
  for (const check of schema_._def.checks) {
4071
4076
  switch (check.kind) {
@@ -4110,23 +4115,23 @@ function zodToJsonSchema(schema, options) {
4110
4115
  return UNDEFINED_JSON_SCHEMA;
4111
4116
  }
4112
4117
  case ZodFirstPartyTypeKind.ZodLiteral: {
4113
- const schema_ = schema;
4118
+ const schema_ = schema__;
4114
4119
  return { const: schema_._def.value };
4115
4120
  }
4116
4121
  case ZodFirstPartyTypeKind.ZodEnum: {
4117
- const schema_ = schema;
4122
+ const schema_ = schema__;
4118
4123
  return {
4119
4124
  enum: schema_._def.values
4120
4125
  };
4121
4126
  }
4122
4127
  case ZodFirstPartyTypeKind.ZodNativeEnum: {
4123
- const schema_ = schema;
4128
+ const schema_ = schema__;
4124
4129
  return {
4125
4130
  enum: Object.values(schema_._def.values)
4126
4131
  };
4127
4132
  }
4128
4133
  case ZodFirstPartyTypeKind.ZodArray: {
4129
- const schema_ = schema;
4134
+ const schema_ = schema__;
4130
4135
  const def = schema_._def;
4131
4136
  const json = { type: "array" };
4132
4137
  if (def.exactLength) {
@@ -4142,7 +4147,7 @@ function zodToJsonSchema(schema, options) {
4142
4147
  return json;
4143
4148
  }
4144
4149
  case ZodFirstPartyTypeKind.ZodTuple: {
4145
- const schema_ = schema;
4150
+ const schema_ = schema__;
4146
4151
  const prefixItems = [];
4147
4152
  const json = { type: "array" };
4148
4153
  for (const item of schema_._def.items) {
@@ -4160,7 +4165,7 @@ function zodToJsonSchema(schema, options) {
4160
4165
  return json;
4161
4166
  }
4162
4167
  case ZodFirstPartyTypeKind.ZodObject: {
4163
- const schema_ = schema;
4168
+ const schema_ = schema__;
4164
4169
  const json = { type: "object" };
4165
4170
  const properties = {};
4166
4171
  const required = [];
@@ -4196,7 +4201,7 @@ function zodToJsonSchema(schema, options) {
4196
4201
  return json;
4197
4202
  }
4198
4203
  case ZodFirstPartyTypeKind.ZodRecord: {
4199
- const schema_ = schema;
4204
+ const schema_ = schema__;
4200
4205
  const json = { type: "object" };
4201
4206
  json.additionalProperties = zodToJsonSchema(
4202
4207
  schema_._def.valueType,
@@ -4205,14 +4210,14 @@ function zodToJsonSchema(schema, options) {
4205
4210
  return json;
4206
4211
  }
4207
4212
  case ZodFirstPartyTypeKind.ZodSet: {
4208
- const schema_ = schema;
4213
+ const schema_ = schema__;
4209
4214
  return {
4210
4215
  type: "array",
4211
4216
  items: zodToJsonSchema(schema_._def.valueType, childOptions)
4212
4217
  };
4213
4218
  }
4214
4219
  case ZodFirstPartyTypeKind.ZodMap: {
4215
- const schema_ = schema;
4220
+ const schema_ = schema__;
4216
4221
  return {
4217
4222
  type: "array",
4218
4223
  items: {
@@ -4228,7 +4233,7 @@ function zodToJsonSchema(schema, options) {
4228
4233
  }
4229
4234
  case ZodFirstPartyTypeKind.ZodUnion:
4230
4235
  case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
4231
- const schema_ = schema;
4236
+ const schema_ = schema__;
4232
4237
  const anyOf = [];
4233
4238
  for (const s of schema_._def.options) {
4234
4239
  anyOf.push(zodToJsonSchema(s, childOptions));
@@ -4236,7 +4241,7 @@ function zodToJsonSchema(schema, options) {
4236
4241
  return { anyOf };
4237
4242
  }
4238
4243
  case ZodFirstPartyTypeKind.ZodIntersection: {
4239
- const schema_ = schema;
4244
+ const schema_ = schema__;
4240
4245
  const allOf = [];
4241
4246
  for (const s of [schema_._def.left, schema_._def.right]) {
4242
4247
  allOf.push(zodToJsonSchema(s, childOptions));
@@ -4244,7 +4249,7 @@ function zodToJsonSchema(schema, options) {
4244
4249
  return { allOf };
4245
4250
  }
4246
4251
  case ZodFirstPartyTypeKind.ZodLazy: {
4247
- const schema_ = schema;
4252
+ const schema_ = schema__;
4248
4253
  const maxLazyDepth = childOptions?.maxLazyDepth ?? 5;
4249
4254
  const lazyDepth = childOptions?.lazyDepth ?? 0;
4250
4255
  if (lazyDepth > maxLazyDepth) {
@@ -4261,44 +4266,44 @@ function zodToJsonSchema(schema, options) {
4261
4266
  return {};
4262
4267
  }
4263
4268
  case ZodFirstPartyTypeKind.ZodOptional: {
4264
- const schema_ = schema;
4269
+ const schema_ = schema__;
4265
4270
  const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
4266
4271
  return {
4267
4272
  anyOf: [UNDEFINED_JSON_SCHEMA, inner]
4268
4273
  };
4269
4274
  }
4270
4275
  case ZodFirstPartyTypeKind.ZodReadonly: {
4271
- const schema_ = schema;
4276
+ const schema_ = schema__;
4272
4277
  return zodToJsonSchema(schema_._def.innerType, childOptions);
4273
4278
  }
4274
4279
  case ZodFirstPartyTypeKind.ZodDefault: {
4275
- const schema_ = schema;
4280
+ const schema_ = schema__;
4276
4281
  return zodToJsonSchema(schema_._def.innerType, childOptions);
4277
4282
  }
4278
4283
  case ZodFirstPartyTypeKind.ZodEffects: {
4279
- const schema_ = schema;
4284
+ const schema_ = schema__;
4280
4285
  if (schema_._def.effect.type === "transform" && childOptions?.mode === "output") {
4281
4286
  return {};
4282
4287
  }
4283
4288
  return zodToJsonSchema(schema_._def.schema, childOptions);
4284
4289
  }
4285
4290
  case ZodFirstPartyTypeKind.ZodCatch: {
4286
- const schema_ = schema;
4291
+ const schema_ = schema__;
4287
4292
  return zodToJsonSchema(schema_._def.innerType, childOptions);
4288
4293
  }
4289
4294
  case ZodFirstPartyTypeKind.ZodBranded: {
4290
- const schema_ = schema;
4295
+ const schema_ = schema__;
4291
4296
  return zodToJsonSchema(schema_._def.type, childOptions);
4292
4297
  }
4293
4298
  case ZodFirstPartyTypeKind.ZodPipeline: {
4294
- const schema_ = schema;
4299
+ const schema_ = schema__;
4295
4300
  return zodToJsonSchema(
4296
4301
  childOptions?.mode === "output" ? schema_._def.out : schema_._def.in,
4297
4302
  childOptions
4298
4303
  );
4299
4304
  }
4300
4305
  case ZodFirstPartyTypeKind.ZodNullable: {
4301
- const schema_ = schema;
4306
+ const schema_ = schema__;
4302
4307
  const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
4303
4308
  return {
4304
4309
  anyOf: [{ type: "null" }, inner]
@@ -4507,7 +4512,9 @@ async function generateOpenAPI(opts, options) {
4507
4512
  };
4508
4513
  }
4509
4514
  return {
4510
- required: Boolean(internal.InputSchema?.isOptional()),
4515
+ required: Boolean(
4516
+ internal.InputSchema && "isOptional" in internal.InputSchema && typeof internal.InputSchema.isOptional === "function" ? internal.InputSchema.isOptional() : false
4517
+ ),
4511
4518
  content
4512
4519
  };
4513
4520
  })();
@@ -1,5 +1,5 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
1
2
  import { type JSONSchema } from 'json-schema-typed/draft-2020-12';
2
- import { type ZodTypeAny } from 'zod';
3
3
  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")[];
4
4
  export declare const UNSUPPORTED_JSON_SCHEMA: {
5
5
  not: {};
@@ -35,7 +35,7 @@ export interface ZodToJsonSchemaOptions {
35
35
  */
36
36
  isHandledCustomJSONSchema?: boolean;
37
37
  }
38
- export declare function zodToJsonSchema(schema: ZodTypeAny, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema, boolean>;
38
+ export declare function zodToJsonSchema(schema: StandardSchemaV1, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema, boolean>;
39
39
  export declare function extractJSONSchema(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): {
40
40
  schema: JSONSchema | undefined;
41
41
  matches: JSONSchema[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/openapi",
3
3
  "type": "module",
4
- "version": "0.15.0",
4
+ "version": "0.16.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -34,14 +34,15 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
+ "@standard-schema/spec": "1.0.0-beta.4",
37
38
  "escape-string-regexp": "^5.0.0",
38
39
  "json-schema-typed": "^8.0.1",
39
40
  "openapi3-ts": "^4.4.0",
40
- "@orpc/server": "0.15.0",
41
- "@orpc/contract": "0.15.0",
42
- "@orpc/shared": "0.15.0",
43
- "@orpc/transformer": "0.15.0",
44
- "@orpc/zod": "0.15.0"
41
+ "@orpc/contract": "0.16.0",
42
+ "@orpc/transformer": "0.16.0",
43
+ "@orpc/server": "0.16.0",
44
+ "@orpc/shared": "0.16.0",
45
+ "@orpc/zod": "0.16.0"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@readme/openapi-parser": "^2.6.0",