@hey-api/openapi-ts 0.59.1 → 0.60.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.d.cts CHANGED
@@ -24,6 +24,10 @@ type ArrayOfObjectsToObjectMap<T extends ReadonlyArray<Record<string, any>>, D e
24
24
  [K in T[number][D]]?: Extract<T[number], Record<D, K>>;
25
25
  };
26
26
 
27
+ type OmitUnderscoreKeys<T> = {
28
+ [K in keyof T as K extends `_${string}` ? never : K]: T[K];
29
+ };
30
+
27
31
  type PluginNames =
28
32
  | '@hey-api/schemas'
29
33
  | '@hey-api/sdk'
@@ -37,23 +41,39 @@ type PluginNames =
37
41
  | 'fastify'
38
42
  | 'zod';
39
43
 
44
+ type PluginTag = 'transformer' | 'validator';
45
+
46
+ interface PluginContext {
47
+ ensureDependency: (name: PluginNames | true) => void;
48
+ pluginByTag: (tag: PluginTag) => PluginNames | undefined;
49
+ }
50
+
40
51
  interface BaseConfig {
41
52
  // eslint-disable-next-line @typescript-eslint/ban-types
42
53
  name: PluginNames | (string & {});
43
54
  output?: string;
44
55
  }
45
56
 
46
- interface Dependencies {
57
+ interface Meta<Config extends BaseConfig> {
47
58
  /**
48
- * Required dependencies will be always processed, regardless of whether
49
- * a user defines them in their `plugins` config.
59
+ * Dependency plugins will be always processed, regardless of whether user
60
+ * explicitly defines them in their `plugins` config.
50
61
  */
51
62
  _dependencies?: ReadonlyArray<PluginNames>;
52
63
  /**
53
- * Optional dependencies are not processed unless a user explicitly defines
54
- * them in their `plugins` config.
64
+ * Allows overriding config before it's sent to the parser. An example is
65
+ * defining `validator` as `true` and the plugin figures out which plugin
66
+ * should be used for validation.
55
67
  */
56
- _optionalDependencies?: ReadonlyArray<PluginNames>;
68
+ _infer?: (
69
+ config: Config & Omit<Meta<Config>, '_infer'>,
70
+ context: PluginContext,
71
+ ) => void;
72
+ /**
73
+ * Optional tags can be used to help with deciding plugin order and inferring
74
+ * plugin configuration options.
75
+ */
76
+ _tags?: ReadonlyArray<PluginTag>;
57
77
  }
58
78
 
59
79
  /**
@@ -61,7 +81,7 @@ interface Dependencies {
61
81
  */
62
82
  declare namespace Plugin {
63
83
  export type Config<Config extends BaseConfig> = Config &
64
- Dependencies & {
84
+ Meta<Config> & {
65
85
  _handler: Plugin.Handler<Config>;
66
86
  _handlerLegacy: Plugin.LegacyHandler<Config>;
67
87
  };
@@ -78,10 +98,7 @@ declare namespace Plugin {
78
98
  plugin: Plugin.Instance<Config>;
79
99
  }) => void;
80
100
 
81
- export type Instance<Config extends BaseConfig> = Omit<
82
- Config,
83
- '_dependencies' | '_handler' | '_handlerLegacy' | '_optionalDependencies'
84
- > &
101
+ export type Instance<Config extends BaseConfig> = OmitUnderscoreKeys<Config> &
85
102
  Pick<Required<Config>, 'output'>;
86
103
 
87
104
  /**
@@ -3950,8 +3967,8 @@ interface IROperationObject {
3950
3967
  parameters?: IRParametersObject;
3951
3968
  path: keyof IRPathsObject;
3952
3969
  responses?: IRResponsesObject;
3970
+ security?: ReadonlyArray<SecuritySchemeObject>;
3953
3971
  // TODO: parser - add more properties
3954
- // security?: ReadonlyArray<SecurityRequirementObject>;
3955
3972
  // servers?: ReadonlyArray<ServerObject>;
3956
3973
  summary?: string;
3957
3974
  tags?: ReadonlyArray<string>;
@@ -4110,18 +4127,29 @@ interface Config$a extends Plugin.Name<'@hey-api/sdk'> {
4110
4127
  * Note that by enabling this option, your SDKs will **NOT**
4111
4128
  * support {@link https://developer.mozilla.org/docs/Glossary/Tree_shaking tree-shaking}.
4112
4129
  * For this reason, it is disabled by default.
4130
+ *
4113
4131
  * @default false
4114
4132
  */
4115
4133
  asClass?: boolean;
4116
4134
  /**
4135
+ * **This feature works only with the experimental parser**
4136
+ *
4137
+ * Should the generated functions contain auth mechanisms? You may want to
4138
+ * disable this option if you're handling auth yourself or defining it
4139
+ * globally on the client and want to reduce the size of generated code.
4140
+ *
4141
+ * @default true
4142
+ */
4143
+ auth?: boolean;
4144
+ /**
4145
+ * **This feature works only with the legacy parser**
4146
+ *
4117
4147
  * Filter endpoints to be included in the generated SDK. The provided
4118
4148
  * string should be a regular expression where matched results will be
4119
4149
  * included in the output. The input pattern this string will be tested
4120
4150
  * against is `{method} {path}`. For example, you can match
4121
4151
  * `POST /api/v1/foo` with `^POST /api/v1/foo$`.
4122
4152
  *
4123
- * This option does not work with the experimental parser.
4124
- *
4125
4153
  * @deprecated
4126
4154
  */
4127
4155
  filter?: string;
@@ -4138,17 +4166,21 @@ interface Config$a extends Plugin.Name<'@hey-api/sdk'> {
4138
4166
  // TODO: parser - rename operationId option to something like inferId?: boolean
4139
4167
  /**
4140
4168
  * Use operation ID to generate operation names?
4169
+ *
4141
4170
  * @default true
4142
4171
  */
4143
4172
  operationId?: boolean;
4144
4173
  /**
4145
4174
  * Name of the generated file.
4175
+ *
4146
4176
  * @default 'sdk'
4147
4177
  */
4148
4178
  output?: string;
4149
4179
  /**
4150
4180
  * Define shape of returned value from service calls
4181
+ *
4151
4182
  * @default 'body'
4183
+ *
4152
4184
  * @deprecated
4153
4185
  */
4154
4186
  response?: 'body' | 'response';
@@ -4157,9 +4189,38 @@ interface Config$a extends Plugin.Name<'@hey-api/sdk'> {
4157
4189
  * obtained from your OpenAPI specification tags.
4158
4190
  *
4159
4191
  * This option has no effect if `sdk.asClass` is `false`.
4192
+ *
4160
4193
  * @default '{{name}}Service'
4161
4194
  */
4162
4195
  serviceNameBuilder?: string;
4196
+ /**
4197
+ * Transform response data before returning. This is useful if you want to
4198
+ * convert for example ISO strings into Date objects. However, transformation
4199
+ * adds runtime overhead, so it's not recommended to use unless necessary.
4200
+ *
4201
+ * You can customize the selected transformer output through its plugin. You
4202
+ * can also set `transformer` to `true` to automatically choose the
4203
+ * transformer from your defined plugins.
4204
+ *
4205
+ * @default false
4206
+ */
4207
+ transformer?: '@hey-api/transformers' | boolean;
4208
+ /**
4209
+ * **This feature works only with the experimental parser**
4210
+ *
4211
+ * Validate response data against schema before returning. This is useful
4212
+ * if you want to ensure the response conforms to a desired shape. However,
4213
+ * validation adds runtime overhead, so it's not recommended to use unless
4214
+ * absolutely necessary.
4215
+ *
4216
+ * Ensure you have declared the selected library as a dependency to avoid
4217
+ * errors. You can customize the selected validator output through its
4218
+ * plugin. You can also set `validator` to `true` to automatically choose
4219
+ * the validator from your defined plugins.
4220
+ *
4221
+ * @default false
4222
+ */
4223
+ validator?: 'zod' | boolean;
4163
4224
  }
4164
4225
 
4165
4226
  interface Config$9 extends Plugin.Name<'@hey-api/transformers'> {
@@ -4213,15 +4274,16 @@ interface Config$8 extends Plugin.Name<'@hey-api/typescript'> {
4213
4274
  */
4214
4275
  identifierCase?: Exclude<StringCase, 'SCREAMING_SNAKE_CASE'>;
4215
4276
  /**
4216
- * Include only types matching regular expression.
4277
+ * **This feature works only with the legacy parser**
4217
4278
  *
4218
- * This option does not work with the experimental parser.
4279
+ * Include only types matching regular expression.
4219
4280
  *
4220
4281
  * @deprecated
4221
4282
  */
4222
4283
  include?: string;
4223
4284
  /**
4224
4285
  * Name of the generated file.
4286
+ *
4225
4287
  * @default 'types'
4226
4288
  */
4227
4289
  output?: string;
package/dist/index.d.ts CHANGED
@@ -24,6 +24,10 @@ type ArrayOfObjectsToObjectMap<T extends ReadonlyArray<Record<string, any>>, D e
24
24
  [K in T[number][D]]?: Extract<T[number], Record<D, K>>;
25
25
  };
26
26
 
27
+ type OmitUnderscoreKeys<T> = {
28
+ [K in keyof T as K extends `_${string}` ? never : K]: T[K];
29
+ };
30
+
27
31
  type PluginNames =
28
32
  | '@hey-api/schemas'
29
33
  | '@hey-api/sdk'
@@ -37,23 +41,39 @@ type PluginNames =
37
41
  | 'fastify'
38
42
  | 'zod';
39
43
 
44
+ type PluginTag = 'transformer' | 'validator';
45
+
46
+ interface PluginContext {
47
+ ensureDependency: (name: PluginNames | true) => void;
48
+ pluginByTag: (tag: PluginTag) => PluginNames | undefined;
49
+ }
50
+
40
51
  interface BaseConfig {
41
52
  // eslint-disable-next-line @typescript-eslint/ban-types
42
53
  name: PluginNames | (string & {});
43
54
  output?: string;
44
55
  }
45
56
 
46
- interface Dependencies {
57
+ interface Meta<Config extends BaseConfig> {
47
58
  /**
48
- * Required dependencies will be always processed, regardless of whether
49
- * a user defines them in their `plugins` config.
59
+ * Dependency plugins will be always processed, regardless of whether user
60
+ * explicitly defines them in their `plugins` config.
50
61
  */
51
62
  _dependencies?: ReadonlyArray<PluginNames>;
52
63
  /**
53
- * Optional dependencies are not processed unless a user explicitly defines
54
- * them in their `plugins` config.
64
+ * Allows overriding config before it's sent to the parser. An example is
65
+ * defining `validator` as `true` and the plugin figures out which plugin
66
+ * should be used for validation.
55
67
  */
56
- _optionalDependencies?: ReadonlyArray<PluginNames>;
68
+ _infer?: (
69
+ config: Config & Omit<Meta<Config>, '_infer'>,
70
+ context: PluginContext,
71
+ ) => void;
72
+ /**
73
+ * Optional tags can be used to help with deciding plugin order and inferring
74
+ * plugin configuration options.
75
+ */
76
+ _tags?: ReadonlyArray<PluginTag>;
57
77
  }
58
78
 
59
79
  /**
@@ -61,7 +81,7 @@ interface Dependencies {
61
81
  */
62
82
  declare namespace Plugin {
63
83
  export type Config<Config extends BaseConfig> = Config &
64
- Dependencies & {
84
+ Meta<Config> & {
65
85
  _handler: Plugin.Handler<Config>;
66
86
  _handlerLegacy: Plugin.LegacyHandler<Config>;
67
87
  };
@@ -78,10 +98,7 @@ declare namespace Plugin {
78
98
  plugin: Plugin.Instance<Config>;
79
99
  }) => void;
80
100
 
81
- export type Instance<Config extends BaseConfig> = Omit<
82
- Config,
83
- '_dependencies' | '_handler' | '_handlerLegacy' | '_optionalDependencies'
84
- > &
101
+ export type Instance<Config extends BaseConfig> = OmitUnderscoreKeys<Config> &
85
102
  Pick<Required<Config>, 'output'>;
86
103
 
87
104
  /**
@@ -3950,8 +3967,8 @@ interface IROperationObject {
3950
3967
  parameters?: IRParametersObject;
3951
3968
  path: keyof IRPathsObject;
3952
3969
  responses?: IRResponsesObject;
3970
+ security?: ReadonlyArray<SecuritySchemeObject>;
3953
3971
  // TODO: parser - add more properties
3954
- // security?: ReadonlyArray<SecurityRequirementObject>;
3955
3972
  // servers?: ReadonlyArray<ServerObject>;
3956
3973
  summary?: string;
3957
3974
  tags?: ReadonlyArray<string>;
@@ -4110,18 +4127,29 @@ interface Config$a extends Plugin.Name<'@hey-api/sdk'> {
4110
4127
  * Note that by enabling this option, your SDKs will **NOT**
4111
4128
  * support {@link https://developer.mozilla.org/docs/Glossary/Tree_shaking tree-shaking}.
4112
4129
  * For this reason, it is disabled by default.
4130
+ *
4113
4131
  * @default false
4114
4132
  */
4115
4133
  asClass?: boolean;
4116
4134
  /**
4135
+ * **This feature works only with the experimental parser**
4136
+ *
4137
+ * Should the generated functions contain auth mechanisms? You may want to
4138
+ * disable this option if you're handling auth yourself or defining it
4139
+ * globally on the client and want to reduce the size of generated code.
4140
+ *
4141
+ * @default true
4142
+ */
4143
+ auth?: boolean;
4144
+ /**
4145
+ * **This feature works only with the legacy parser**
4146
+ *
4117
4147
  * Filter endpoints to be included in the generated SDK. The provided
4118
4148
  * string should be a regular expression where matched results will be
4119
4149
  * included in the output. The input pattern this string will be tested
4120
4150
  * against is `{method} {path}`. For example, you can match
4121
4151
  * `POST /api/v1/foo` with `^POST /api/v1/foo$`.
4122
4152
  *
4123
- * This option does not work with the experimental parser.
4124
- *
4125
4153
  * @deprecated
4126
4154
  */
4127
4155
  filter?: string;
@@ -4138,17 +4166,21 @@ interface Config$a extends Plugin.Name<'@hey-api/sdk'> {
4138
4166
  // TODO: parser - rename operationId option to something like inferId?: boolean
4139
4167
  /**
4140
4168
  * Use operation ID to generate operation names?
4169
+ *
4141
4170
  * @default true
4142
4171
  */
4143
4172
  operationId?: boolean;
4144
4173
  /**
4145
4174
  * Name of the generated file.
4175
+ *
4146
4176
  * @default 'sdk'
4147
4177
  */
4148
4178
  output?: string;
4149
4179
  /**
4150
4180
  * Define shape of returned value from service calls
4181
+ *
4151
4182
  * @default 'body'
4183
+ *
4152
4184
  * @deprecated
4153
4185
  */
4154
4186
  response?: 'body' | 'response';
@@ -4157,9 +4189,38 @@ interface Config$a extends Plugin.Name<'@hey-api/sdk'> {
4157
4189
  * obtained from your OpenAPI specification tags.
4158
4190
  *
4159
4191
  * This option has no effect if `sdk.asClass` is `false`.
4192
+ *
4160
4193
  * @default '{{name}}Service'
4161
4194
  */
4162
4195
  serviceNameBuilder?: string;
4196
+ /**
4197
+ * Transform response data before returning. This is useful if you want to
4198
+ * convert for example ISO strings into Date objects. However, transformation
4199
+ * adds runtime overhead, so it's not recommended to use unless necessary.
4200
+ *
4201
+ * You can customize the selected transformer output through its plugin. You
4202
+ * can also set `transformer` to `true` to automatically choose the
4203
+ * transformer from your defined plugins.
4204
+ *
4205
+ * @default false
4206
+ */
4207
+ transformer?: '@hey-api/transformers' | boolean;
4208
+ /**
4209
+ * **This feature works only with the experimental parser**
4210
+ *
4211
+ * Validate response data against schema before returning. This is useful
4212
+ * if you want to ensure the response conforms to a desired shape. However,
4213
+ * validation adds runtime overhead, so it's not recommended to use unless
4214
+ * absolutely necessary.
4215
+ *
4216
+ * Ensure you have declared the selected library as a dependency to avoid
4217
+ * errors. You can customize the selected validator output through its
4218
+ * plugin. You can also set `validator` to `true` to automatically choose
4219
+ * the validator from your defined plugins.
4220
+ *
4221
+ * @default false
4222
+ */
4223
+ validator?: 'zod' | boolean;
4163
4224
  }
4164
4225
 
4165
4226
  interface Config$9 extends Plugin.Name<'@hey-api/transformers'> {
@@ -4213,15 +4274,16 @@ interface Config$8 extends Plugin.Name<'@hey-api/typescript'> {
4213
4274
  */
4214
4275
  identifierCase?: Exclude<StringCase, 'SCREAMING_SNAKE_CASE'>;
4215
4276
  /**
4216
- * Include only types matching regular expression.
4277
+ * **This feature works only with the legacy parser**
4217
4278
  *
4218
- * This option does not work with the experimental parser.
4279
+ * Include only types matching regular expression.
4219
4280
  *
4220
4281
  * @deprecated
4221
4282
  */
4222
4283
  include?: string;
4223
4284
  /**
4224
4285
  * Name of the generated file.
4286
+ *
4225
4287
  * @default 'types'
4226
4288
  */
4227
4289
  output?: string;