@mintlify/validation 0.1.448 → 0.1.450

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.
@@ -347,6 +347,10 @@ export class SchemaConverter extends BaseConverter {
347
347
  copyKeyIfDefined('readOnly', schema, sharedProps);
348
348
  copyKeyIfDefined('writeOnly', schema, sharedProps);
349
349
  copyKeyIfDefined('deprecated', schema, sharedProps);
350
+ copyKeyIfDefined('x-enum-for-clients', schema, sharedProps);
351
+ copyKeyIfDefined('x-enum-for-feature-flags', schema, sharedProps);
352
+ copyKeyIfDefined('x-for-feature-flags', schema, sharedProps);
353
+ copyKeyIfDefined('x-for-clients', schema, sharedProps);
350
354
  if (schema.type === undefined) {
351
355
  const inferredType = inferType(schema);
352
356
  if (inferredType === undefined) {
@@ -433,7 +437,9 @@ export class SchemaConverter extends BaseConverter {
433
437
  additionalProperties =
434
438
  // validator allows additionalProperties to be null
435
439
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
436
- typeof schema.additionalProperties === 'object' && schema.additionalProperties != null
440
+ typeof schema.additionalProperties === 'object' &&
441
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
442
+ schema.additionalProperties != null
437
443
  ? this.convertSchemaRecursive(addlPropsPath, schema.additionalProperties)
438
444
  : schema.additionalProperties;
439
445
  }
@@ -1,2 +1,3 @@
1
- import { DataSchema } from '../index.js';
1
+ import { DataSchema, DataSchemaArray } from '../index.js';
2
+ export declare const isDataSchemaArray: (schemaArray: unknown) => schemaArray is DataSchemaArray;
2
3
  export declare const generateExampleFromSchema: (schema: DataSchema, depth?: number) => unknown;
@@ -1,4 +1,43 @@
1
1
  const MAX_DEPTH = 100;
2
+ export const isDataSchemaArray = (schemaArray) => {
3
+ return Array.isArray(schemaArray) && schemaArray.length > 0;
4
+ };
5
+ const filterXAuth = (schema) => {
6
+ var _a, _b, _c, _d;
7
+ if (schema.type === 'object') {
8
+ const propertiesWithXAuthFiltered = Object.entries(schema.properties).filter(([_, [schema]]) => !('x-for-clients' in schema || 'x-for-feature-flags' in schema));
9
+ return Object.assign(Object.assign({}, schema), { properties: Object.fromEntries(propertiesWithXAuthFiltered) });
10
+ }
11
+ if (schema.type === 'array') {
12
+ const itemsWithXAuthFiltered = schema.items.filter((schema) => !('x-for-clients' in schema || 'x-for-feature-flags' in schema));
13
+ if (isDataSchemaArray(itemsWithXAuthFiltered)) {
14
+ return Object.assign(Object.assign({}, schema), { items: itemsWithXAuthFiltered });
15
+ }
16
+ }
17
+ if (schema.type === 'enum<string>') {
18
+ const enumValues = schema.enum;
19
+ const xFilteredEnumValues = [];
20
+ Object.entries((_a = schema['x-enum-for-clients']) !== null && _a !== void 0 ? _a : {}).forEach(([enumKey]) => {
21
+ xFilteredEnumValues.push(enumKey.toString());
22
+ });
23
+ Object.entries((_b = schema['x-enum-for-feature-flags']) !== null && _b !== void 0 ? _b : {}).forEach(([enumKey]) => {
24
+ xFilteredEnumValues.push(enumKey.toString());
25
+ });
26
+ return Object.assign(Object.assign({}, schema), { enum: enumValues.filter((enumValue) => !xFilteredEnumValues.includes(enumValue)) });
27
+ }
28
+ if (schema.type === 'enum<number>' || schema.type === 'enum<integer>') {
29
+ const enumValues = schema.enum;
30
+ const xFilteredEnumValues = [];
31
+ Object.entries((_c = schema['x-enum-for-clients']) !== null && _c !== void 0 ? _c : {}).forEach(([enumKey]) => {
32
+ xFilteredEnumValues.push(Number(enumKey));
33
+ });
34
+ Object.entries((_d = schema['x-enum-for-feature-flags']) !== null && _d !== void 0 ? _d : {}).forEach(([enumKey]) => {
35
+ xFilteredEnumValues.push(Number(enumKey));
36
+ });
37
+ return Object.assign(Object.assign({}, schema), { enum: enumValues.filter((enumValue) => !xFilteredEnumValues.includes(enumValue)) });
38
+ }
39
+ return schema;
40
+ };
2
41
  export const generateExampleFromSchema = (schema, depth = 0) => {
3
42
  if (schema.example !== undefined) {
4
43
  return schema.example;
@@ -6,24 +45,25 @@ export const generateExampleFromSchema = (schema, depth = 0) => {
6
45
  if (schema.default !== undefined) {
7
46
  return schema.default;
8
47
  }
9
- switch (schema.type) {
48
+ const schemaForExampleGeneration = filterXAuth(schema);
49
+ switch (schemaForExampleGeneration.type) {
10
50
  case 'string':
11
- return generateStringExample(schema);
51
+ return generateStringExample(schemaForExampleGeneration);
12
52
  case 'boolean':
13
53
  return true;
14
54
  case 'number':
15
55
  case 'integer':
16
- return generateNumericExample(schema);
56
+ return generateNumericExample(schemaForExampleGeneration);
17
57
  case 'enum<string>':
18
58
  case 'enum<number>':
19
59
  case 'enum<integer>':
20
- return schema.enum[0];
60
+ return schemaForExampleGeneration.enum[0];
21
61
  case 'null':
22
62
  return null;
23
63
  case 'any':
24
64
  return '<any>';
25
65
  case 'object':
26
- const entries = Object.entries(schema.properties)
66
+ const entries = Object.entries(schemaForExampleGeneration.properties)
27
67
  // generate examples for all properties until depth reached - then only required properties
28
68
  .filter(([_, [{ required }]]) => depth < MAX_DEPTH || required)
29
69
  .map(([propName, subschema]) => [
@@ -34,9 +74,9 @@ export const generateExampleFromSchema = (schema, depth = 0) => {
34
74
  case 'array':
35
75
  return depth < MAX_DEPTH
36
76
  ? [
37
- generateExampleFromSchema(schema.items[0],
77
+ generateExampleFromSchema(schemaForExampleGeneration.items[0],
38
78
  // prevent the weird [{}] example value by counting array<object> as one level
39
- schema.items[0].type === 'object' ? depth : depth + 1),
79
+ schemaForExampleGeneration.items[0].type === 'object' ? depth : depth + 1),
40
80
  ]
41
81
  : [];
42
82
  }
@@ -127,6 +127,8 @@ export type BaseSchema<T> = {
127
127
  isAllOf?: string;
128
128
  'x-enum-for-clients'?: string[];
129
129
  'x-enum-for-feature-flags'?: string[];
130
+ 'x-for-feature-flags'?: string[];
131
+ 'x-for-clients'?: string[];
130
132
  };
131
133
  export type BooleanSchema = {
132
134
  type: 'boolean';
@@ -246,4 +248,10 @@ export declare const XMintType: import("arktype/internal/methods/object.ts").Obj
246
248
  description?: string | undefined;
247
249
  } | undefined;
248
250
  }, {}>;
251
+ export type SchemaWithXFlags = OpenAPIV3_1.SchemaObject & {
252
+ 'x-enum-for-clients'?: string[];
253
+ 'x-enum-for-feature-flags'?: string[];
254
+ 'x-for-feature-flags'?: string[];
255
+ 'x-for-clients'?: string[];
256
+ };
249
257
  export {};
@@ -13,6 +13,8 @@ export type SimpleSchema = Omit<OpenAPIV3_1.SchemaObject, Compositions> & {
13
13
  isAllOf?: string;
14
14
  'x-enum-for-clients'?: string[];
15
15
  'x-enum-for-feature-flags'?: string[];
16
+ 'x-for-feature-flags'?: string[];
17
+ 'x-for-clients'?: string[];
16
18
  };
17
19
  export type SumOfProducts = SimpleSchema[][];
18
20
  export type SimpleSchemaWithSubschemas = SimpleSchema & {
@@ -30,4 +32,6 @@ export type SchemaOrRefComposition = SchemaOrRef & {
30
32
  isOneOf?: string;
31
33
  isAnyOf?: string;
32
34
  isAllOf?: string;
35
+ 'x-for-feature-flags'?: string[];
36
+ 'x-for-clients'?: string[];
33
37
  };
@@ -166,6 +166,8 @@ export function copyAndCombineKeys(acc, curr) {
166
166
  copyKeyIfDefined('const', curr, acc);
167
167
  copyKeyIfDefined('x-enum-for-clients', curr, acc);
168
168
  copyKeyIfDefined('x-enum-for-feature-flags', curr, acc);
169
+ copyKeyIfDefined('x-for-feature-flags', curr, acc);
170
+ copyKeyIfDefined('x-for-clients', curr, acc);
169
171
  combineKeyIfDefined('multipleOf', curr, acc, lcm);
170
172
  combineKeyIfDefined('maxLength', curr, acc, Math.min);
171
173
  combineKeyIfDefined('minLength', curr, acc, Math.max);