@intrig/plugin-react 0.0.15-30 → 0.0.15-31

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.cjs CHANGED
@@ -2897,38 +2897,10 @@ async function downloadHookTemplate({ source, data: { paths, operationId, respon
2897
2897
  `;
2898
2898
  }
2899
2899
 
2900
- async function typeTemplate(descriptor) {
2901
- const { data: { schema, name: typeName }, source } = descriptor;
2902
- const { imports, zodSchema, tsType } = openApiSchemaToZod(schema);
2903
- const ts = pluginSdk.typescript(path__namespace.resolve('src', source, 'components', 'schemas', `${typeName}.ts`));
2904
- const simpleType = (await pluginSdk.jsonLiteral('')`${JSON.stringify(schema)}`).content;
2905
- const transport = schema.type === 'string' && schema.format === 'binary' ? 'binary' : 'json';
2906
- var _JSON_stringify;
2907
- return ts`
2908
- import { z } from 'zod'
2909
-
2910
- ${[
2911
- ...imports
2912
- ].join('\n')}
2913
-
2914
- //--- Zod Schemas ---//
2915
-
2916
- export const ${typeName}Schema = ${zodSchema}
2917
-
2918
- //--- Typescript Type ---//
2919
-
2920
- export type ${typeName} = ${tsType}
2921
-
2922
- //--- JSON Schema ---//
2923
-
2924
- export const ${typeName}_jsonschema = ${(_JSON_stringify = JSON.stringify(schema)) != null ? _JSON_stringify : "{}"}
2925
-
2926
- //--- Simple Type ---//
2927
- /*[${simpleType}]*/
2928
-
2929
- // Transport hint for clients ("binary" => use arraybuffer/blob)
2930
- export const ${typeName}_transport = '${transport}' as const;
2931
- `;
2900
+ // Helper to escape string values for use in generated code
2901
+ function escapeStringValue(value) {
2902
+ return value.replace(/\\/g, '\\\\') // Escape backslashes first
2903
+ .replace(/'/g, "\\'"); // Escape single quotes
2932
2904
  }
2933
2905
  function isRef(schema) {
2934
2906
  return '$ref' in (schema != null ? schema : {});
@@ -2983,8 +2955,8 @@ function handleStringSchema(schema) {
2983
2955
  const imports = new Set();
2984
2956
  let binaryish = false;
2985
2957
  if (schema.enum) {
2986
- const enumValues = schema.enum.map((value)=>`'${value}'`).join(' | ');
2987
- const zodEnum = `z.enum([${schema.enum.map((value)=>`'${value}'`).join(', ')}])`;
2958
+ const enumValues = schema.enum.map((value)=>`'${escapeStringValue(String(value))}'`).join(' | ');
2959
+ const zodEnum = `z.enum([${schema.enum.map((value)=>`'${escapeStringValue(String(value))}'`).join(', ')}])`;
2988
2960
  return {
2989
2961
  tsType: enumValues,
2990
2962
  zodSchema: zodEnum,
@@ -3006,7 +2978,7 @@ function handleStringSchema(schema) {
3006
2978
  } else if (schema.format === 'time') {
3007
2979
  zodSchema = 'z.string()';
3008
2980
  if (schema.pattern) {
3009
- zodSchema += `.regex(new RegExp('${schema.pattern}'))`;
2981
+ zodSchema += `.regex(new RegExp('${escapeStringValue(schema.pattern)}'))`;
3010
2982
  }
3011
2983
  } else if (schema.format === 'date-time' && !schema.pattern) {
3012
2984
  tsType = 'Date';
@@ -3021,11 +2993,29 @@ function handleStringSchema(schema) {
3021
2993
  } else if (schema.format === 'binary') {
3022
2994
  tsType = 'BinaryData';
3023
2995
  zodSchema = 'BinaryDataSchema';
2996
+ // Apply file size constraints using refinements
2997
+ if (schema.minLength !== undefined) {
2998
+ zodSchema += `.refine((blob) => blob.size >= ${schema.minLength}, { message: 'File size must be at least ${schema.minLength} bytes' })`;
2999
+ }
3000
+ if (schema.maxLength !== undefined) {
3001
+ zodSchema += `.refine((blob) => blob.size <= ${schema.maxLength}, { message: 'File size must not exceed ${schema.maxLength} bytes' })`;
3002
+ }
3024
3003
  imports.add(`import { BinaryData, BinaryDataSchema } from '@intrig/react/type-utils'`);
3025
3004
  binaryish = true;
3026
3005
  } else if (schema.format === 'byte') {
3027
3006
  tsType = 'Uint8Array';
3028
3007
  zodSchema = 'z.string().transform((val) => base64ToUint8Array(val))';
3008
+ // Note: For byte (base64), length constraints apply to the decoded data
3009
+ // We can't easily validate before transform, so we validate after
3010
+ if (schema.minLength !== undefined || schema.maxLength !== undefined) {
3011
+ zodSchema = `(${zodSchema})`;
3012
+ if (schema.minLength !== undefined) {
3013
+ zodSchema += `.refine((arr) => arr.length >= ${schema.minLength}, { message: 'Data size must be at least ${schema.minLength} bytes' })`;
3014
+ }
3015
+ if (schema.maxLength !== undefined) {
3016
+ zodSchema += `.refine((arr) => arr.length <= ${schema.maxLength}, { message: 'Data size must not exceed ${schema.maxLength} bytes' })`;
3017
+ }
3018
+ }
3029
3019
  imports.add(`import { base64ToUint8Array } from '@intrig/react/type-utils'`);
3030
3020
  binaryish = true;
3031
3021
  } else if (schema.format === 'email') {
@@ -3043,7 +3033,7 @@ function handleStringSchema(schema) {
3043
3033
  } else {
3044
3034
  if (schema.minLength !== undefined) zodSchema += `.min(${schema.minLength})`;
3045
3035
  if (schema.maxLength !== undefined) zodSchema += `.max(${schema.maxLength})`;
3046
- if (schema.pattern !== undefined) zodSchema += `.regex(new RegExp('${schema.pattern}'))`;
3036
+ if (schema.pattern !== undefined) zodSchema += `.regex(new RegExp('${escapeStringValue(schema.pattern)}'))`;
3047
3037
  }
3048
3038
  return {
3049
3039
  tsType,
@@ -3054,8 +3044,11 @@ function handleStringSchema(schema) {
3054
3044
  }
3055
3045
  function handleNumberSchema(schema) {
3056
3046
  let zodSchema = 'z.number()';
3057
- if (schema.minimum !== undefined) zodSchema += `.min(${schema.minimum})`;
3058
- if (schema.maximum !== undefined) zodSchema += `.max(${schema.maximum})`;
3047
+ // Handle exclusive bounds (OpenAPI 3.1 style - exclusiveMinimum/Maximum are numbers)
3048
+ if (schema.exclusiveMinimum !== undefined) zodSchema += `.gt(${schema.exclusiveMinimum})`;
3049
+ else if (schema.minimum !== undefined) zodSchema += `.min(${schema.minimum})`;
3050
+ if (schema.exclusiveMaximum !== undefined) zodSchema += `.lt(${schema.exclusiveMaximum})`;
3051
+ else if (schema.maximum !== undefined) zodSchema += `.max(${schema.maximum})`;
3059
3052
  return {
3060
3053
  tsType: 'number',
3061
3054
  zodSchema,
@@ -3064,8 +3057,11 @@ function handleNumberSchema(schema) {
3064
3057
  }
3065
3058
  function handleIntegerSchema(schema) {
3066
3059
  let zodSchema = 'z.number().int()';
3067
- if (schema.minimum !== undefined) zodSchema += `.min(${schema.minimum})`;
3068
- if (schema.maximum !== undefined) zodSchema += `.max(${schema.maximum})`;
3060
+ // Handle exclusive bounds (OpenAPI 3.1 style - exclusiveMinimum/Maximum are numbers)
3061
+ if (schema.exclusiveMinimum !== undefined) zodSchema += `.gt(${schema.exclusiveMinimum})`;
3062
+ else if (schema.minimum !== undefined) zodSchema += `.min(${schema.minimum})`;
3063
+ if (schema.exclusiveMaximum !== undefined) zodSchema += `.lt(${schema.exclusiveMaximum})`;
3064
+ else if (schema.maximum !== undefined) zodSchema += `.max(${schema.maximum})`;
3069
3065
  return {
3070
3066
  tsType: 'number',
3071
3067
  zodSchema,
@@ -3085,9 +3081,11 @@ function handleArraySchema(schema, imports) {
3085
3081
  throw new Error('Array schema must have an items property');
3086
3082
  }
3087
3083
  const { tsType, zodSchema: itemZodSchema, imports: itemImports, binaryish } = openApiSchemaToZod(schema.items, imports);
3088
- let zodSchema = binaryish ? `z.array(${itemZodSchema})` : `(z.preprocess((raw) => (Array.isArray(raw) ? raw : [raw]), z.array(${itemZodSchema})) as z.ZodType<${tsType}[], z.ZodTypeDef, ${tsType}[]>)`;
3089
- if (schema.minItems !== undefined) zodSchema += `.min(${schema.minItems})`;
3090
- if (schema.maxItems !== undefined) zodSchema += `.max(${schema.maxItems})`;
3084
+ // Build the array schema with constraints
3085
+ let arraySchema = `z.array(${itemZodSchema})`;
3086
+ if (schema.minItems !== undefined) arraySchema += `.min(${schema.minItems})`;
3087
+ if (schema.maxItems !== undefined) arraySchema += `.max(${schema.maxItems})`;
3088
+ const zodSchema = binaryish ? arraySchema : `(z.preprocess((raw) => (Array.isArray(raw) ? raw : [raw]), ${arraySchema}) as z.ZodType<(${tsType})[], z.ZodTypeDef, (${tsType})[]>)`;
3091
3089
  return {
3092
3090
  tsType: `(${tsType})[]`,
3093
3091
  zodSchema,
@@ -3158,21 +3156,26 @@ function handleComplexSchema(schema, imports) {
3158
3156
  const options = schema.allOf.map((subSchema)=>openApiSchemaToZod(subSchema));
3159
3157
  const zodSchemas = options.map((option)=>option.zodSchema);
3160
3158
  const tsTypes = options.map((option)=>option.tsType);
3161
- if (zodSchemas.length === 1) return {
3162
- tsType: tsTypes.join(' & '),
3163
- zodSchema: zodSchemas[0],
3164
- imports: new Set([
3165
- ...imports,
3166
- ...options.flatMap((option)=>Array.from(option.imports))
3167
- ])
3168
- };
3159
+ const allImports = new Set([
3160
+ ...imports,
3161
+ ...options.flatMap((option)=>Array.from(option.imports))
3162
+ ]);
3163
+ if (zodSchemas.length === 1) {
3164
+ return {
3165
+ tsType: tsTypes[0],
3166
+ zodSchema: zodSchemas[0],
3167
+ imports: allImports
3168
+ };
3169
+ }
3170
+ // Use .and() chaining instead of z.intersection() which only takes 2 arguments
3171
+ const combinedZodSchema = zodSchemas.reduce((acc, schema, index)=>{
3172
+ if (index === 0) return schema;
3173
+ return `${acc}.and(${schema})`;
3174
+ });
3169
3175
  return {
3170
3176
  tsType: tsTypes.join(' & '),
3171
- zodSchema: `z.intersection(${zodSchemas.join(', ')})`,
3172
- imports: new Set([
3173
- ...imports,
3174
- ...options.flatMap((option)=>Array.from(option.imports))
3175
- ])
3177
+ zodSchema: combinedZodSchema,
3178
+ imports: allImports
3176
3179
  };
3177
3180
  }
3178
3181
  return {
@@ -3182,6 +3185,40 @@ function handleComplexSchema(schema, imports) {
3182
3185
  };
3183
3186
  }
3184
3187
 
3188
+ async function typeTemplate(descriptor) {
3189
+ const { data: { schema, name: typeName }, source } = descriptor;
3190
+ const { imports, zodSchema, tsType } = openApiSchemaToZod(schema);
3191
+ const ts = pluginSdk.typescript(path__namespace.resolve('src', source, 'components', 'schemas', `${typeName}.ts`));
3192
+ const simpleType = (await pluginSdk.jsonLiteral('')`${JSON.stringify(schema)}`).content;
3193
+ const transport = schema.type === 'string' && schema.format === 'binary' ? 'binary' : 'json';
3194
+ var _JSON_stringify;
3195
+ return ts`
3196
+ import { z } from 'zod'
3197
+
3198
+ ${[
3199
+ ...imports
3200
+ ].join('\n')}
3201
+
3202
+ //--- Zod Schemas ---//
3203
+
3204
+ export const ${typeName}Schema = ${zodSchema}
3205
+
3206
+ //--- Typescript Type ---//
3207
+
3208
+ export type ${typeName} = ${tsType}
3209
+
3210
+ //--- JSON Schema ---//
3211
+
3212
+ export const ${typeName}_jsonschema = ${(_JSON_stringify = JSON.stringify(schema)) != null ? _JSON_stringify : "{}"}
3213
+
3214
+ //--- Simple Type ---//
3215
+ /*[${simpleType}]*/
3216
+
3217
+ // Transport hint for clients ("binary" => use arraybuffer/blob)
3218
+ export const ${typeName}_transport = '${transport}' as const;
3219
+ `;
3220
+ }
3221
+
3185
3222
  async function generateCode(ctx) {
3186
3223
  // Root/project files
3187
3224
  await ctx.dump(packageJsonTemplate(ctx));
package/dist/index.js CHANGED
@@ -2873,38 +2873,10 @@ async function downloadHookTemplate({ source, data: { paths, operationId, respon
2873
2873
  `;
2874
2874
  }
2875
2875
 
2876
- async function typeTemplate(descriptor) {
2877
- const { data: { schema, name: typeName }, source } = descriptor;
2878
- const { imports, zodSchema, tsType } = openApiSchemaToZod(schema);
2879
- const ts = typescript(path.resolve('src', source, 'components', 'schemas', `${typeName}.ts`));
2880
- const simpleType = (await jsonLiteral('')`${JSON.stringify(schema)}`).content;
2881
- const transport = schema.type === 'string' && schema.format === 'binary' ? 'binary' : 'json';
2882
- var _JSON_stringify;
2883
- return ts`
2884
- import { z } from 'zod'
2885
-
2886
- ${[
2887
- ...imports
2888
- ].join('\n')}
2889
-
2890
- //--- Zod Schemas ---//
2891
-
2892
- export const ${typeName}Schema = ${zodSchema}
2893
-
2894
- //--- Typescript Type ---//
2895
-
2896
- export type ${typeName} = ${tsType}
2897
-
2898
- //--- JSON Schema ---//
2899
-
2900
- export const ${typeName}_jsonschema = ${(_JSON_stringify = JSON.stringify(schema)) != null ? _JSON_stringify : "{}"}
2901
-
2902
- //--- Simple Type ---//
2903
- /*[${simpleType}]*/
2904
-
2905
- // Transport hint for clients ("binary" => use arraybuffer/blob)
2906
- export const ${typeName}_transport = '${transport}' as const;
2907
- `;
2876
+ // Helper to escape string values for use in generated code
2877
+ function escapeStringValue(value) {
2878
+ return value.replace(/\\/g, '\\\\') // Escape backslashes first
2879
+ .replace(/'/g, "\\'"); // Escape single quotes
2908
2880
  }
2909
2881
  function isRef(schema) {
2910
2882
  return '$ref' in (schema != null ? schema : {});
@@ -2959,8 +2931,8 @@ function handleStringSchema(schema) {
2959
2931
  const imports = new Set();
2960
2932
  let binaryish = false;
2961
2933
  if (schema.enum) {
2962
- const enumValues = schema.enum.map((value)=>`'${value}'`).join(' | ');
2963
- const zodEnum = `z.enum([${schema.enum.map((value)=>`'${value}'`).join(', ')}])`;
2934
+ const enumValues = schema.enum.map((value)=>`'${escapeStringValue(String(value))}'`).join(' | ');
2935
+ const zodEnum = `z.enum([${schema.enum.map((value)=>`'${escapeStringValue(String(value))}'`).join(', ')}])`;
2964
2936
  return {
2965
2937
  tsType: enumValues,
2966
2938
  zodSchema: zodEnum,
@@ -2982,7 +2954,7 @@ function handleStringSchema(schema) {
2982
2954
  } else if (schema.format === 'time') {
2983
2955
  zodSchema = 'z.string()';
2984
2956
  if (schema.pattern) {
2985
- zodSchema += `.regex(new RegExp('${schema.pattern}'))`;
2957
+ zodSchema += `.regex(new RegExp('${escapeStringValue(schema.pattern)}'))`;
2986
2958
  }
2987
2959
  } else if (schema.format === 'date-time' && !schema.pattern) {
2988
2960
  tsType = 'Date';
@@ -2997,11 +2969,29 @@ function handleStringSchema(schema) {
2997
2969
  } else if (schema.format === 'binary') {
2998
2970
  tsType = 'BinaryData';
2999
2971
  zodSchema = 'BinaryDataSchema';
2972
+ // Apply file size constraints using refinements
2973
+ if (schema.minLength !== undefined) {
2974
+ zodSchema += `.refine((blob) => blob.size >= ${schema.minLength}, { message: 'File size must be at least ${schema.minLength} bytes' })`;
2975
+ }
2976
+ if (schema.maxLength !== undefined) {
2977
+ zodSchema += `.refine((blob) => blob.size <= ${schema.maxLength}, { message: 'File size must not exceed ${schema.maxLength} bytes' })`;
2978
+ }
3000
2979
  imports.add(`import { BinaryData, BinaryDataSchema } from '@intrig/react/type-utils'`);
3001
2980
  binaryish = true;
3002
2981
  } else if (schema.format === 'byte') {
3003
2982
  tsType = 'Uint8Array';
3004
2983
  zodSchema = 'z.string().transform((val) => base64ToUint8Array(val))';
2984
+ // Note: For byte (base64), length constraints apply to the decoded data
2985
+ // We can't easily validate before transform, so we validate after
2986
+ if (schema.minLength !== undefined || schema.maxLength !== undefined) {
2987
+ zodSchema = `(${zodSchema})`;
2988
+ if (schema.minLength !== undefined) {
2989
+ zodSchema += `.refine((arr) => arr.length >= ${schema.minLength}, { message: 'Data size must be at least ${schema.minLength} bytes' })`;
2990
+ }
2991
+ if (schema.maxLength !== undefined) {
2992
+ zodSchema += `.refine((arr) => arr.length <= ${schema.maxLength}, { message: 'Data size must not exceed ${schema.maxLength} bytes' })`;
2993
+ }
2994
+ }
3005
2995
  imports.add(`import { base64ToUint8Array } from '@intrig/react/type-utils'`);
3006
2996
  binaryish = true;
3007
2997
  } else if (schema.format === 'email') {
@@ -3019,7 +3009,7 @@ function handleStringSchema(schema) {
3019
3009
  } else {
3020
3010
  if (schema.minLength !== undefined) zodSchema += `.min(${schema.minLength})`;
3021
3011
  if (schema.maxLength !== undefined) zodSchema += `.max(${schema.maxLength})`;
3022
- if (schema.pattern !== undefined) zodSchema += `.regex(new RegExp('${schema.pattern}'))`;
3012
+ if (schema.pattern !== undefined) zodSchema += `.regex(new RegExp('${escapeStringValue(schema.pattern)}'))`;
3023
3013
  }
3024
3014
  return {
3025
3015
  tsType,
@@ -3030,8 +3020,11 @@ function handleStringSchema(schema) {
3030
3020
  }
3031
3021
  function handleNumberSchema(schema) {
3032
3022
  let zodSchema = 'z.number()';
3033
- if (schema.minimum !== undefined) zodSchema += `.min(${schema.minimum})`;
3034
- if (schema.maximum !== undefined) zodSchema += `.max(${schema.maximum})`;
3023
+ // Handle exclusive bounds (OpenAPI 3.1 style - exclusiveMinimum/Maximum are numbers)
3024
+ if (schema.exclusiveMinimum !== undefined) zodSchema += `.gt(${schema.exclusiveMinimum})`;
3025
+ else if (schema.minimum !== undefined) zodSchema += `.min(${schema.minimum})`;
3026
+ if (schema.exclusiveMaximum !== undefined) zodSchema += `.lt(${schema.exclusiveMaximum})`;
3027
+ else if (schema.maximum !== undefined) zodSchema += `.max(${schema.maximum})`;
3035
3028
  return {
3036
3029
  tsType: 'number',
3037
3030
  zodSchema,
@@ -3040,8 +3033,11 @@ function handleNumberSchema(schema) {
3040
3033
  }
3041
3034
  function handleIntegerSchema(schema) {
3042
3035
  let zodSchema = 'z.number().int()';
3043
- if (schema.minimum !== undefined) zodSchema += `.min(${schema.minimum})`;
3044
- if (schema.maximum !== undefined) zodSchema += `.max(${schema.maximum})`;
3036
+ // Handle exclusive bounds (OpenAPI 3.1 style - exclusiveMinimum/Maximum are numbers)
3037
+ if (schema.exclusiveMinimum !== undefined) zodSchema += `.gt(${schema.exclusiveMinimum})`;
3038
+ else if (schema.minimum !== undefined) zodSchema += `.min(${schema.minimum})`;
3039
+ if (schema.exclusiveMaximum !== undefined) zodSchema += `.lt(${schema.exclusiveMaximum})`;
3040
+ else if (schema.maximum !== undefined) zodSchema += `.max(${schema.maximum})`;
3045
3041
  return {
3046
3042
  tsType: 'number',
3047
3043
  zodSchema,
@@ -3061,9 +3057,11 @@ function handleArraySchema(schema, imports) {
3061
3057
  throw new Error('Array schema must have an items property');
3062
3058
  }
3063
3059
  const { tsType, zodSchema: itemZodSchema, imports: itemImports, binaryish } = openApiSchemaToZod(schema.items, imports);
3064
- let zodSchema = binaryish ? `z.array(${itemZodSchema})` : `(z.preprocess((raw) => (Array.isArray(raw) ? raw : [raw]), z.array(${itemZodSchema})) as z.ZodType<${tsType}[], z.ZodTypeDef, ${tsType}[]>)`;
3065
- if (schema.minItems !== undefined) zodSchema += `.min(${schema.minItems})`;
3066
- if (schema.maxItems !== undefined) zodSchema += `.max(${schema.maxItems})`;
3060
+ // Build the array schema with constraints
3061
+ let arraySchema = `z.array(${itemZodSchema})`;
3062
+ if (schema.minItems !== undefined) arraySchema += `.min(${schema.minItems})`;
3063
+ if (schema.maxItems !== undefined) arraySchema += `.max(${schema.maxItems})`;
3064
+ const zodSchema = binaryish ? arraySchema : `(z.preprocess((raw) => (Array.isArray(raw) ? raw : [raw]), ${arraySchema}) as z.ZodType<(${tsType})[], z.ZodTypeDef, (${tsType})[]>)`;
3067
3065
  return {
3068
3066
  tsType: `(${tsType})[]`,
3069
3067
  zodSchema,
@@ -3134,21 +3132,26 @@ function handleComplexSchema(schema, imports) {
3134
3132
  const options = schema.allOf.map((subSchema)=>openApiSchemaToZod(subSchema));
3135
3133
  const zodSchemas = options.map((option)=>option.zodSchema);
3136
3134
  const tsTypes = options.map((option)=>option.tsType);
3137
- if (zodSchemas.length === 1) return {
3138
- tsType: tsTypes.join(' & '),
3139
- zodSchema: zodSchemas[0],
3140
- imports: new Set([
3141
- ...imports,
3142
- ...options.flatMap((option)=>Array.from(option.imports))
3143
- ])
3144
- };
3135
+ const allImports = new Set([
3136
+ ...imports,
3137
+ ...options.flatMap((option)=>Array.from(option.imports))
3138
+ ]);
3139
+ if (zodSchemas.length === 1) {
3140
+ return {
3141
+ tsType: tsTypes[0],
3142
+ zodSchema: zodSchemas[0],
3143
+ imports: allImports
3144
+ };
3145
+ }
3146
+ // Use .and() chaining instead of z.intersection() which only takes 2 arguments
3147
+ const combinedZodSchema = zodSchemas.reduce((acc, schema, index)=>{
3148
+ if (index === 0) return schema;
3149
+ return `${acc}.and(${schema})`;
3150
+ });
3145
3151
  return {
3146
3152
  tsType: tsTypes.join(' & '),
3147
- zodSchema: `z.intersection(${zodSchemas.join(', ')})`,
3148
- imports: new Set([
3149
- ...imports,
3150
- ...options.flatMap((option)=>Array.from(option.imports))
3151
- ])
3153
+ zodSchema: combinedZodSchema,
3154
+ imports: allImports
3152
3155
  };
3153
3156
  }
3154
3157
  return {
@@ -3158,6 +3161,40 @@ function handleComplexSchema(schema, imports) {
3158
3161
  };
3159
3162
  }
3160
3163
 
3164
+ async function typeTemplate(descriptor) {
3165
+ const { data: { schema, name: typeName }, source } = descriptor;
3166
+ const { imports, zodSchema, tsType } = openApiSchemaToZod(schema);
3167
+ const ts = typescript(path.resolve('src', source, 'components', 'schemas', `${typeName}.ts`));
3168
+ const simpleType = (await jsonLiteral('')`${JSON.stringify(schema)}`).content;
3169
+ const transport = schema.type === 'string' && schema.format === 'binary' ? 'binary' : 'json';
3170
+ var _JSON_stringify;
3171
+ return ts`
3172
+ import { z } from 'zod'
3173
+
3174
+ ${[
3175
+ ...imports
3176
+ ].join('\n')}
3177
+
3178
+ //--- Zod Schemas ---//
3179
+
3180
+ export const ${typeName}Schema = ${zodSchema}
3181
+
3182
+ //--- Typescript Type ---//
3183
+
3184
+ export type ${typeName} = ${tsType}
3185
+
3186
+ //--- JSON Schema ---//
3187
+
3188
+ export const ${typeName}_jsonschema = ${(_JSON_stringify = JSON.stringify(schema)) != null ? _JSON_stringify : "{}"}
3189
+
3190
+ //--- Simple Type ---//
3191
+ /*[${simpleType}]*/
3192
+
3193
+ // Transport hint for clients ("binary" => use arraybuffer/blob)
3194
+ export const ${typeName}_transport = '${transport}' as const;
3195
+ `;
3196
+ }
3197
+
3161
3198
  async function generateCode(ctx) {
3162
3199
  // Root/project files
3163
3200
  await ctx.dump(packageJsonTemplate(ctx));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intrig/plugin-react",
3
- "version": "0.0.15-30",
3
+ "version": "0.0.15-31",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -15,7 +15,7 @@
15
15
  }
16
16
  },
17
17
  "dependencies": {
18
- "@intrig/plugin-sdk": "^0.0.15-30",
18
+ "@intrig/plugin-sdk": "^0.0.15-31",
19
19
  "@swc/helpers": "~0.5.11",
20
20
  "fs-extra": "^11.2.0"
21
21
  },