@kubb/ast 5.17.1 → 5.18.1

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.ts CHANGED
@@ -293,6 +293,16 @@ type SchemaNodeBase = BaseNode & {
293
293
  * Schema `format` value.
294
294
  */
295
295
  format?: string;
296
+ externalDocs?: ExternalDocs;
297
+ /**
298
+ * `if`/`then`/`else`, `dependentRequired` and `dependentSchemas`. A required `unknown` property in `if` means "key is present".
299
+ * Visitors do not walk it.
300
+ */
301
+ conditionals?: Array<{
302
+ if: SchemaNode;
303
+ then?: SchemaNode;
304
+ else?: SchemaNode;
305
+ }>;
296
306
  };
297
307
  /**
298
308
  * Object schema with ordered properties.
@@ -349,10 +359,18 @@ type ObjectSchemaNode = SchemaNodeBase & {
349
359
  /**
350
360
  * Minimum number of properties allowed.
351
361
  */
352
- minProperties?: number;
362
+ min?: number;
353
363
  /**
354
364
  * Maximum number of properties allowed.
355
365
  */
366
+ max?: number;
367
+ /**
368
+ * @deprecated Use `min`. Removed in Kubb v6.
369
+ */
370
+ minProperties?: number;
371
+ /**
372
+ * @deprecated Use `max`. Removed in Kubb v6.
373
+ */
356
374
  maxProperties?: number;
357
375
  };
358
376
  /**
@@ -392,6 +410,14 @@ type ArraySchemaNode = SchemaNodeBase & {
392
410
  * Whether all items must be unique.
393
411
  */
394
412
  unique?: boolean;
413
+ /**
414
+ * At least `min` (default 1) and at most `max` items match `schema`. Visitors do not walk `schema`.
415
+ */
416
+ contains?: {
417
+ schema: SchemaNode;
418
+ min?: number;
419
+ max?: number;
420
+ };
395
421
  };
396
422
  /**
397
423
  * Shared shape for union and intersection schemas.
@@ -627,6 +653,14 @@ type StringSchemaNode = SchemaNodeBase & {
627
653
  * Regex pattern.
628
654
  */
629
655
  pattern?: string;
656
+ /**
657
+ * The value the string encodes, such as a JSON document or `base64` bytes. Visitors do not walk `schema`.
658
+ */
659
+ content?: {
660
+ mediaType?: string;
661
+ encoding?: string;
662
+ schema?: SchemaNode;
663
+ };
630
664
  };
631
665
  /**
632
666
  * Numeric schema (`number`, `integer`, or `bigint`).
@@ -650,11 +684,18 @@ type NumberSchemaNode = SchemaNodeBase & {
650
684
  */
651
685
  max?: number;
652
686
  /**
653
- * Exclusive minimum value.
687
+ * Bounds the value may not equal: it must be greater than `min` and less than `max`.
688
+ */
689
+ exclusive?: {
690
+ min?: number;
691
+ max?: number;
692
+ };
693
+ /**
694
+ * @deprecated Use `exclusive.min`. Removed in Kubb v6.
654
695
  */
655
696
  exclusiveMinimum?: number;
656
697
  /**
657
- * Exclusive maximum value.
698
+ * @deprecated Use `exclusive.max`. Removed in Kubb v6.
658
699
  */
659
700
  exclusiveMaximum?: number;
660
701
  /**
@@ -801,6 +842,7 @@ type InputServerVariable = {
801
842
  */
802
843
  type InputServer = {
803
844
  url: string;
845
+ name?: string;
804
846
  description?: string;
805
847
  /**
806
848
  * Variables of the source URL template, copied as-is. `url` already has their defaults filled in, so
@@ -808,18 +850,66 @@ type InputServer = {
808
850
  */
809
851
  variables?: Record<string, InputServerVariable>;
810
852
  };
853
+ type ExternalDocs = {
854
+ url: string;
855
+ description?: string;
856
+ };
857
+ type InputTag = {
858
+ name: string;
859
+ summary?: string;
860
+ description?: string;
861
+ /**
862
+ * Name of the tag this tag nests under. `group: { type: 'tag' }` places its files in the parent's folder.
863
+ */
864
+ parent?: string;
865
+ kind?: string;
866
+ externalDocs?: ExternalDocs;
867
+ };
868
+ type OAuthFlow = {
869
+ authorizationUrl?: string;
870
+ deviceAuthorizationUrl?: string;
871
+ tokenUrl?: string;
872
+ refreshUrl?: string;
873
+ scopes?: Record<string, string>;
874
+ };
875
+ /**
876
+ * How a client sends a credential, in the same shape as the `Auth` object the generated clients pass to `auth`.
877
+ */
878
+ type AuthCredential = {
879
+ type: 'http';
880
+ scheme: 'bearer' | 'basic' | (string & {});
881
+ bearerFormat?: string;
882
+ } | {
883
+ type: 'apiKey';
884
+ in: 'header' | 'query' | 'cookie';
885
+ name: string;
886
+ } | {
887
+ type: 'oauth2';
888
+ flows: Record<string, OAuthFlow>;
889
+ metadataUrl?: string;
890
+ } | {
891
+ type: 'openIdConnect';
892
+ url?: string;
893
+ } | {
894
+ type: 'mutualTLS';
895
+ };
811
896
  /**
812
- * An authentication scheme from the source document, keyed by `name`. `parameterName` is the header, query, or cookie name of an `apiKey`.
897
+ * One way to authenticate, keyed by `name`, which operations refer to in `auth`.
813
898
  */
814
- type InputSecurityScheme = {
899
+ type AuthScheme = {
815
900
  name: string;
816
- type: string;
817
901
  description?: string;
818
- scheme?: string;
819
- bearerFormat?: string;
820
- in?: string;
821
- parameterName?: string;
902
+ deprecated?: boolean;
903
+ credential: AuthCredential;
822
904
  };
905
+ /**
906
+ * One way to meet an operation's auth. Every scheme in it applies together. `scopes` are the OAuth2 or OpenID
907
+ * Connect scopes the call needs. An empty list means the call may be sent without credentials.
908
+ */
909
+ type AuthRequirement = Array<{
910
+ scheme: string;
911
+ scopes?: Array<string>;
912
+ }>;
823
913
  /**
824
914
  * Metadata for an API document, populated by the adapter and available to every generator.
825
915
  * Every field is a plain JSON value.
@@ -842,12 +932,26 @@ type InputMeta = {
842
932
  * API version string from `info.version` in the source document.
843
933
  */
844
934
  version?: string;
935
+ summary?: string;
936
+ termsOfService?: string;
937
+ contact?: {
938
+ name?: string;
939
+ url?: string;
940
+ email?: string;
941
+ };
942
+ license?: {
943
+ name: string;
944
+ identifier?: string;
945
+ url?: string;
946
+ };
947
+ externalDocs?: ExternalDocs;
845
948
  /**
846
949
  * Resolved base URL from the first matching server entry in the source document.
847
950
  */
848
951
  baseURL?: string | null;
849
952
  servers?: Array<InputServer>;
850
- securitySchemes?: Array<InputSecurityScheme>;
953
+ tags?: Array<InputTag>;
954
+ auth?: Array<AuthScheme>;
851
955
  /**
852
956
  * Vendor extensions (`x-*` keys) from the document root, copied as-is. Absent when the root has none.
853
957
  */
@@ -896,83 +1000,6 @@ type InputNode = BaseNode & {
896
1000
  * ```
897
1001
  */
898
1002
  declare function createInput(overrides?: Partial<Omit<InputNode, 'kind'>>): InputNode;
899
- /**
900
- * Where a parameter is sent. `querystring` carries the whole query string as one value, serialized per `contentType`.
901
- */
902
- type ParameterLocation = 'path' | 'query' | 'header' | 'cookie' | 'querystring';
903
- /**
904
- * Parameter serialization style, controlling how a parameter value is rendered into the request.
905
- */
906
- type ParameterStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject';
907
- /**
908
- * AST node representing one operation parameter.
909
- *
910
- * @example
911
- * ```ts
912
- * const param: ParameterNode = {
913
- * kind: 'Parameter',
914
- * name: 'petId',
915
- * in: 'path',
916
- * schema: createSchema({ type: 'string' }),
917
- * required: true,
918
- * }
919
- * ```
920
- */
921
- type ParameterNode = BaseNode & {
922
- kind: 'Parameter';
923
- /**
924
- * Parameter name.
925
- */
926
- name: string;
927
- /**
928
- * Parameter location (`path`, `query`, `header`, `cookie`, or `querystring`).
929
- */
930
- in: ParameterLocation;
931
- /**
932
- * Parameter schema.
933
- */
934
- schema: SchemaNode;
935
- /**
936
- * Whether the parameter is required.
937
- */
938
- required: boolean;
939
- /**
940
- * Serialization style. Absent when the source omits it, leaving consumers to apply the
941
- * per-location default.
942
- */
943
- style?: ParameterStyle;
944
- /**
945
- * Whether array and object values expand into separate values. Absent when the source omits it,
946
- * leaving consumers to apply the default for the style.
947
- */
948
- explode?: boolean;
949
- /**
950
- * Whether reserved characters (RFC 3986 `:/?#[]@!$&'()*+,;=`) are sent as-is instead of
951
- * percent-encoded. Only applies to query parameters. Absent when the source omits it.
952
- */
953
- allowReserved?: boolean;
954
- /**
955
- * Media type of a parameter described with `content` instead of `schema`, for example
956
- * `application/json` when the value is sent as a JSON-encoded string. Absent for `schema` parameters.
957
- */
958
- contentType?: string;
959
- };
960
- type UserParameterNode = Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>;
961
- /**
962
- * Creates a `ParameterNode`. `required` defaults to `false`, and the schema's
963
- * `optional`/`nullish` flags are derived from it.
964
- *
965
- * @example
966
- * ```ts
967
- * const param = createParameter({
968
- * name: 'petId',
969
- * in: 'path',
970
- * required: true,
971
- * schema: createSchema({ type: 'string' }),
972
- * })
973
- * ```
974
- */
975
- declare function createParameter(input: UserParameterNode): ParameterNode;
976
1003
  /**
977
1004
  * How one body property is serialized, from the `encoding` entry of its media type.
978
1005
  */
@@ -993,6 +1020,16 @@ type EncodingNode = {
993
1020
  * Whether reserved characters are sent as-is instead of percent-encoded.
994
1021
  */
995
1022
  allowReserved?: boolean;
1023
+ encoding?: Record<string, EncodingNode>;
1024
+ prefixEncoding?: Array<EncodingNode>;
1025
+ itemEncoding?: EncodingNode;
1026
+ };
1027
+ type ExampleNode = {
1028
+ name?: string;
1029
+ summary?: string;
1030
+ description?: string;
1031
+ value?: unknown;
1032
+ serializedValue?: string;
996
1033
  };
997
1034
  /**
998
1035
  * AST node representing one content-type entry of a request body or response.
@@ -1046,11 +1083,100 @@ type ContentNode = BaseNode & {
1046
1083
  * Serialization settings per body property that sets at least one field in the spec's `encoding`.
1047
1084
  */
1048
1085
  encoding?: Record<string, EncodingNode>;
1086
+ examples?: Array<ExampleNode>;
1087
+ /**
1088
+ * Serialization of the first parts by position, for a body sent as an array of parts such as `multipart/mixed`.
1089
+ */
1090
+ prefixEncoding?: Array<EncodingNode>;
1091
+ /**
1092
+ * Serialization of every part after `prefixEncoding`, for a body sent as an array of parts such as `multipart/mixed`.
1093
+ */
1094
+ itemEncoding?: EncodingNode;
1049
1095
  };
1050
1096
  /**
1051
1097
  * Creates a `ContentNode` for a single request-body or response content type.
1052
1098
  */
1053
1099
  declare const createContent: (input: Omit<ContentNode, "kind">) => ContentNode;
1100
+ /**
1101
+ * Where a parameter is sent. `querystring` carries the whole query string as one value, serialized per `contentType`.
1102
+ */
1103
+ type ParameterLocation = 'path' | 'query' | 'header' | 'cookie' | 'querystring';
1104
+ /**
1105
+ * Parameter serialization style, controlling how a parameter value is rendered into the request.
1106
+ */
1107
+ type ParameterStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject' | 'cookie';
1108
+ /**
1109
+ * AST node representing one operation parameter.
1110
+ *
1111
+ * @example
1112
+ * ```ts
1113
+ * const param: ParameterNode = {
1114
+ * kind: 'Parameter',
1115
+ * name: 'petId',
1116
+ * in: 'path',
1117
+ * schema: createSchema({ type: 'string' }),
1118
+ * required: true,
1119
+ * }
1120
+ * ```
1121
+ */
1122
+ type ParameterNode = BaseNode & {
1123
+ kind: 'Parameter';
1124
+ /**
1125
+ * Parameter name.
1126
+ */
1127
+ name: string;
1128
+ /**
1129
+ * Parameter location (`path`, `query`, `header`, `cookie`, or `querystring`).
1130
+ */
1131
+ in: ParameterLocation;
1132
+ /**
1133
+ * Parameter schema.
1134
+ */
1135
+ schema: SchemaNode;
1136
+ /**
1137
+ * Whether the parameter is required.
1138
+ */
1139
+ required: boolean;
1140
+ /**
1141
+ * Serialization style. Absent when the source omits it, leaving consumers to apply the
1142
+ * per-location default.
1143
+ */
1144
+ style?: ParameterStyle;
1145
+ /**
1146
+ * Whether array and object values expand into separate values. Absent when the source omits it,
1147
+ * leaving consumers to apply the default for the style.
1148
+ */
1149
+ explode?: boolean;
1150
+ /**
1151
+ * Whether reserved characters (RFC 3986 `:/?#[]@!$&'()*+,;=`) are sent as-is instead of
1152
+ * percent-encoded. Absent when the source omits it.
1153
+ */
1154
+ allowReserved?: boolean;
1155
+ /**
1156
+ * Media type of a parameter described with `content` instead of `schema`, for example
1157
+ * `application/json` when the value is sent as a JSON-encoded string. Absent for `schema` parameters.
1158
+ */
1159
+ contentType?: string;
1160
+ examples?: Array<ExampleNode>;
1161
+ deprecated?: boolean;
1162
+ allowEmptyValue?: boolean;
1163
+ };
1164
+ type UserParameterNode = Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>;
1165
+ /**
1166
+ * Creates a `ParameterNode`. `required` defaults to `false`, and the schema's
1167
+ * `optional`/`nullish` flags are derived from it.
1168
+ *
1169
+ * @example
1170
+ * ```ts
1171
+ * const param = createParameter({
1172
+ * name: 'petId',
1173
+ * in: 'path',
1174
+ * required: true,
1175
+ * schema: createSchema({ type: 'string' }),
1176
+ * })
1177
+ * ```
1178
+ */
1179
+ declare function createParameter(input: UserParameterNode): ParameterNode;
1054
1180
  /**
1055
1181
  * AST node representing an operation request body.
1056
1182
  *
@@ -1095,7 +1221,7 @@ type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
1095
1221
  /**
1096
1222
  * Response status code literal used by operations.
1097
1223
  *
1098
- * Includes three-digit HTTP status code strings and `"default"` for catch-all responses.
1224
+ * Includes three-digit HTTP status code strings, ranges such as `"2xx"`, and `"default"` for catch-all responses.
1099
1225
  *
1100
1226
  * @example
1101
1227
  * ```ts
@@ -1103,7 +1229,7 @@ type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
1103
1229
  * const fallback: StatusCode = 'default'
1104
1230
  * ```
1105
1231
  */
1106
- type StatusCode = `${1 | 2 | 3 | 4 | 5}${Digit}${Digit}` | 'default';
1232
+ type StatusCode = `${1 | 2 | 3 | 4 | 5}${Digit}${Digit}` | `${1 | 2 | 3 | 4 | 5}xx` | 'default';
1107
1233
  /**
1108
1234
  * AST node representing one operation response variant.
1109
1235
  *
@@ -1129,6 +1255,7 @@ type ResponseNode = BaseNode & {
1129
1255
  * HTTP status code or `'default'` for a fallback response.
1130
1256
  */
1131
1257
  statusCode: StatusCode;
1258
+ summary?: string;
1132
1259
  /**
1133
1260
  * Optional response description.
1134
1261
  */
@@ -1150,6 +1277,22 @@ type ResponseNode = BaseNode & {
1150
1277
  * ```
1151
1278
  */
1152
1279
  content?: Array<ContentNode>;
1280
+ /**
1281
+ * Response headers, as `in: 'header'` parameters. `Content-Type` is left out.
1282
+ */
1283
+ headers?: Array<ParameterNode>;
1284
+ links?: Record<string, ResponseLink>;
1285
+ };
1286
+ /**
1287
+ * A link to another operation. `parameters` and `requestBody` hold runtime expressions such as `$response.body#/id`.
1288
+ */
1289
+ type ResponseLink = {
1290
+ operationId?: string;
1291
+ operationRef?: string;
1292
+ parameters?: Record<string, unknown>;
1293
+ requestBody?: unknown;
1294
+ description?: string;
1295
+ server?: InputServer;
1153
1296
  };
1154
1297
  type ResponseInput = Pick<ResponseNode, 'statusCode'> & Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'content'>> & {
1155
1298
  content?: Array<ContentNode>;
@@ -1204,6 +1347,7 @@ type OperationNodeBase = BaseNode & {
1204
1347
  * Marks the operation as deprecated.
1205
1348
  */
1206
1349
  deprecated?: boolean;
1350
+ externalDocs?: ExternalDocs;
1207
1351
  /**
1208
1352
  * Query, path, header, and cookie parameters for the operation.
1209
1353
  */
@@ -1222,6 +1366,10 @@ type OperationNodeBase = BaseNode & {
1222
1366
  extensions?: Record<string, unknown>;
1223
1367
  /** The operation's own `servers`, else its path item's, such as an upload host. Absent when neither declares any. */
1224
1368
  servers?: Array<InputServer>;
1369
+ /**
1370
+ * Ways to authenticate, from the operation or else the document. Any one entry is enough. `[]` means no auth.
1371
+ */
1372
+ auth?: Array<AuthRequirement>;
1225
1373
  };
1226
1374
  /**
1227
1375
  * Operation served over HTTP. `method` and `path` are guaranteed.
@@ -2515,7 +2663,8 @@ export declare function collectSchemaRefs(node: SchemaNode): ReadonlySet<string>
2515
2663
  *
2516
2664
  * Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the
2517
2665
  * same file (a union member created by name) is left out. That leaves exactly the set
2518
- * `resolver.imports` emits.
2666
+ * `resolver.imports` emits. Refs inside `conditionals`, `contains` and `content` count only with
2667
+ * `checks: true`, for a plugin that prints those checks.
2519
2668
  *
2520
2669
  * @example
2521
2670
  * ```ts
@@ -2523,7 +2672,9 @@ export declare function collectSchemaRefs(node: SchemaNode): ReadonlySet<string>
2523
2672
  * // ['Category', 'Tag']
2524
2673
  * ```
2525
2674
  */
2526
- export declare function collectImportedRefNames(node: SchemaNode): ReadonlyArray<string>;
2675
+ export declare function collectImportedRefNames(node: SchemaNode, { checks }?: {
2676
+ checks?: boolean;
2677
+ }): ReadonlyArray<string>;
2527
2678
  /**
2528
2679
  * Collects the names of all top-level schemas transitively used by a set of operations.
2529
2680
  *
@@ -2673,7 +2824,7 @@ type ParserOptions = {
2673
2824
  enumSuffix: 'enum' | (string & {});
2674
2825
  };
2675
2826
  declare namespace index_d_exports {
2676
- export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateOnlyTypeValue, DateSchemaNode, DateTimeTypeValue, DateTypeOptions, DatetimeSchemaNode, DistributiveOmit, EncodingNode, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InlineLanguage, InputMeta, InputNode, InputSecurityScheme, InputServer, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeKind, NotSchemaNode, NumberSchemaNode, ObjectSchemaNode, OperationNode, ParameterLocation, ParameterNode, ParameterStyle, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, index_d_exports as ast, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, compareEnforce, createPrinter, defineMacro, extractStringsFromNodes, index_d_exports$1 as factory, findCircularSchemas, findSchema, getSchemaLiteralValues, inferDiscriminatorPropertyName, inlineFiles, isBareRef, isHttpOperationNode, mergeRefWithSchema, narrowSchema, nodeKinds, optionality, refName, resolveRef, resolveRefName, resolveSchemaProperties, schemaTypes, transform };
2827
+ export { ArraySchemaNode, ArrowFunctionNode, AuthCredential, AuthRequirement, AuthScheme, BreakNode, CodeNode, ConstNode, ContentNode, DateOnlyTypeValue, DateSchemaNode, DateTimeTypeValue, DateTypeOptions, DatetimeSchemaNode, DistributiveOmit, EncodingNode, Enforce, EnumSchemaNode, ExampleNode, ExportNode, ExternalDocs, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InlineLanguage, InputMeta, InputNode, InputServer, InputTag, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeKind, NotSchemaNode, NumberSchemaNode, OAuthFlow, ObjectSchemaNode, OperationNode, ParameterLocation, ParameterNode, ParameterStyle, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseLink, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, index_d_exports as ast, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, compareEnforce, createPrinter, defineMacro, extractStringsFromNodes, index_d_exports$1 as factory, findCircularSchemas, findSchema, getSchemaLiteralValues, inferDiscriminatorPropertyName, inlineFiles, isBareRef, isHttpOperationNode, mergeRefWithSchema, narrowSchema, nodeKinds, optionality, refName, resolveRef, resolveRefName, resolveSchemaProperties, schemaTypes, transform };
2677
2828
  }
2678
- export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateOnlyTypeValue, type DateSchemaNode, type DateTimeTypeValue, type DateTypeOptions, type DatetimeSchemaNode, type DistributiveOmit, type EncodingNode, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InlineLanguage, type InputMeta, type InputNode, type InputSecurityScheme, type InputServer, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeKind, type NotSchemaNode, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, index_d_exports as ast, index_d_exports$1 as factory };
2829
+ export { type ArraySchemaNode, type ArrowFunctionNode, type AuthCredential, type AuthRequirement, type AuthScheme, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateOnlyTypeValue, type DateSchemaNode, type DateTimeTypeValue, type DateTypeOptions, type DatetimeSchemaNode, type DistributiveOmit, type EncodingNode, type Enforce, type EnumSchemaNode, type ExampleNode, type ExportNode, type ExternalDocs, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InlineLanguage, type InputMeta, type InputNode, type InputServer, type InputTag, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeKind, type NotSchemaNode, type NumberSchemaNode, type OAuthFlow, type ObjectSchemaNode, type OperationNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseLink, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, index_d_exports as ast, index_d_exports$1 as factory };
2679
2830
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -188,7 +188,7 @@ const VISITOR_KEYS = {
188
188
  ],
189
189
  RequestBody: ["content"],
190
190
  Content: ["schema", "stream"],
191
- Response: ["content"],
191
+ Response: ["content", "headers"],
192
192
  Schema: [
193
193
  "properties",
194
194
  "items",
@@ -201,6 +201,15 @@ const VISITOR_KEYS = {
201
201
  Property: ["schema"],
202
202
  Parameter: ["schema"]
203
203
  };
204
+ /**
205
+ * Schema fields that hold checks rather than shape: the `conditionals` entries, `contains` and a string's `content`.
206
+ * `transform` and `collect` skip them, and `visitChildNodes` walks them with `checks: true`.
207
+ */
208
+ const schemaCheckKeys = [
209
+ "conditionals",
210
+ "contains",
211
+ "content"
212
+ ];
204
213
  /** Visitor callback names in traversal order, the keys of {@link Visitor}. */
205
214
  const visitorKeys = [
206
215
  "input",
@@ -251,28 +260,35 @@ function getChildren(node, recurse) {
251
260
  });
252
261
  return children;
253
262
  }
254
- /** Calls `visit` for each direct child node and stops at the first call that returns `true`. */
255
- function visitChildNodes(node, visit) {
256
- const keys = VISITOR_KEYS[node.kind];
263
+ /**
264
+ * Calls `visit` for each direct child node and stops at the first call that returns `true`.
265
+ * With `checks: true`, a schema's {@link schemaCheckKeys} fields are walked too.
266
+ */
267
+ function visitChildNodes(node, visit, { checks = false } = {}) {
268
+ const keys = checks && node.kind === nodeKinds.schema ? [...VISITOR_KEYS[node.kind] ?? [], ...schemaCheckKeys] : VISITOR_KEYS[node.kind];
257
269
  if (!keys) return false;
258
270
  const record = node;
259
271
  const seen = /* @__PURE__ */ new Set();
260
272
  const visitOnce = (child) => !seen.has(child) && (seen.add(child), visit(child));
273
+ const visitRecord = (value) => {
274
+ for (const name in value) {
275
+ if (!Object.hasOwn(value, name)) continue;
276
+ const item = value[name];
277
+ if (isNode(item) && visitOnce(item)) return true;
278
+ }
279
+ return false;
280
+ };
261
281
  for (const key of keys) {
262
282
  const value = record[key];
263
283
  if (Array.isArray(value)) {
264
- for (const item of value) if (isNode(item) && visitOnce(item)) return true;
284
+ for (const item of value) if (isNode(item) ? visitOnce(item) : isNodeRecord(item) && visitRecord(item)) return true;
265
285
  continue;
266
286
  }
267
287
  if (isNode(value)) {
268
288
  if (visitOnce(value)) return true;
269
289
  continue;
270
290
  }
271
- if (isNodeRecord(value)) for (const name in value) {
272
- if (!Object.hasOwn(value, name)) continue;
273
- const item = value[name];
274
- if (isNode(item) && visitOnce(item)) return true;
275
- }
291
+ if (isNodeRecord(value) && visitRecord(value)) return true;
276
292
  }
277
293
  return false;
278
294
  }
@@ -1181,23 +1197,33 @@ function memo(store, key, compute) {
1181
1197
  return value;
1182
1198
  }
1183
1199
  // src/utils/schemaGraph.ts
1184
- /**
1185
- * Walks a node's subtree once and lists every ref it holds, in traversal order, as the resolved
1186
- * name plus whether the ref carries a `$ref` pointer. Memoized by node identity, so
1187
- * `collectSchemaRefs` and `collectImportedRefNames` share one scan per schema.
1188
- */
1189
1200
  const refEntries = /* @__PURE__ */ new WeakMap();
1201
+ const checkRefEntries = /* @__PURE__ */ new WeakMap();
1190
1202
  const schemaRefs = /* @__PURE__ */ new WeakMap();
1191
1203
  const importedRefNames = /* @__PURE__ */ new WeakMap();
1192
- function collectRefEntries(node) {
1193
- return memo(refEntries, node, () => collectSync(node, { schema(child) {
1194
- if (child.type !== "ref") return void 0;
1195
- const name = resolveRefName(child);
1196
- return name ? {
1197
- name,
1198
- hasPointer: Boolean(child.ref)
1199
- } : void 0;
1200
- } }));
1204
+ const importedCheckRefNames = /* @__PURE__ */ new WeakMap();
1205
+ /**
1206
+ * Walks a node's subtree once and lists every ref it holds, in traversal order, as the resolved
1207
+ * name plus whether the ref carries a `$ref` pointer. Memoized per node and per `checks` mode, so
1208
+ * each helper below scans a schema once.
1209
+ */
1210
+ function collectRefEntries(node, { checks }) {
1211
+ return memo(checks ? checkRefEntries : refEntries, node, () => {
1212
+ const entries = [];
1213
+ const walk = (current) => {
1214
+ if (current.kind === nodeKinds.schema && current.type === "ref") {
1215
+ const name = resolveRefName(current);
1216
+ if (name) entries.push({
1217
+ name,
1218
+ hasPointer: Boolean(current.ref)
1219
+ });
1220
+ }
1221
+ visitChildNodes(current, walk, { checks });
1222
+ return false;
1223
+ };
1224
+ walk(node);
1225
+ return entries;
1226
+ });
1201
1227
  }
1202
1228
  /**
1203
1229
  * Collects the names of every schema a node's subtree references, resolved with `resolveRefName`.
@@ -1211,7 +1237,7 @@ function collectRefEntries(node) {
1211
1237
  * ```
1212
1238
  */
1213
1239
  function collectSchemaRefs(node) {
1214
- return memo(schemaRefs, node, () => new Set(collectRefEntries(node).map((entry) => entry.name)));
1240
+ return memo(schemaRefs, node, () => new Set(collectRefEntries(node, { checks: true }).map((entry) => entry.name)));
1215
1241
  }
1216
1242
  /**
1217
1243
  * Collects the de-duplicated target names of every pointer-carrying ref in a node's subtree, in
@@ -1220,7 +1246,8 @@ function collectSchemaRefs(node) {
1220
1246
  *
1221
1247
  * Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the
1222
1248
  * same file (a union member created by name) is left out. That leaves exactly the set
1223
- * `resolver.imports` emits.
1249
+ * `resolver.imports` emits. Refs inside `conditionals`, `contains` and `content` count only with
1250
+ * `checks: true`, for a plugin that prints those checks.
1224
1251
  *
1225
1252
  * @example
1226
1253
  * ```ts
@@ -1228,8 +1255,8 @@ function collectSchemaRefs(node) {
1228
1255
  * // ['Category', 'Tag']
1229
1256
  * ```
1230
1257
  */
1231
- function collectImportedRefNames(node) {
1232
- return memo(importedRefNames, node, () => [...new Set(collectRefEntries(node).flatMap((entry) => entry.hasPointer ? [entry.name] : []))]);
1258
+ function collectImportedRefNames(node, { checks = false } = {}) {
1259
+ return memo(checks ? importedCheckRefNames : importedRefNames, node, () => [...new Set(collectRefEntries(node, { checks }).flatMap((entry) => entry.hasPointer ? [entry.name] : []))]);
1233
1260
  }
1234
1261
  /**
1235
1262
  * Collects the names of all top-level schemas transitively used by a set of operations.