@mintlify/common 1.0.806 → 1.0.807

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.
@@ -0,0 +1,2 @@
1
+ import { AnyRecord } from '../types/asyncapi.js';
2
+ export declare const getEnumValues: (value: AnyRecord | undefined) => Array<string | number | boolean> | undefined;
@@ -0,0 +1,7 @@
1
+ export const getEnumValues = (value) => {
2
+ if (!Array.isArray(value === null || value === void 0 ? void 0 : value.enum)) {
3
+ return undefined;
4
+ }
5
+ const enumValues = value.enum.filter((option) => typeof option === 'string' || typeof option === 'number' || typeof option === 'boolean');
6
+ return enumValues.length > 0 ? enumValues : undefined;
7
+ };
@@ -2,4 +2,5 @@ export * from './getAsyncApiDocumentFromUrl.js';
2
2
  export * from './validateAsyncApi.js';
3
3
  export * from './parseAsyncApiString.js';
4
4
  export * from './parser/getChannelData.js';
5
+ export * from './getEnumValues.js';
5
6
  export * from './prepAsyncApiFrontmatter.js';
@@ -2,4 +2,5 @@ export * from './getAsyncApiDocumentFromUrl.js';
2
2
  export * from './validateAsyncApi.js';
3
3
  export * from './parseAsyncApiString.js';
4
4
  export * from './parser/getChannelData.js';
5
+ export * from './getEnumValues.js';
5
6
  export * from './prepAsyncApiFrontmatter.js';
@@ -1,3 +1,23 @@
1
+ import { getEnumValues } from '../getEnumValues.js';
2
+ const getSchemaType = (value, keys) => {
3
+ if ('type' in value) {
4
+ return value.type;
5
+ }
6
+ const customTypeKey = keys.find((key) => /^x-.*type$/.test(key));
7
+ if (customTypeKey) {
8
+ return value[customTypeKey];
9
+ }
10
+ const enumValues = getEnumValues(value);
11
+ if (enumValues === null || enumValues === void 0 ? void 0 : enumValues.length) {
12
+ const firstValue = enumValues[0];
13
+ if (typeof firstValue === 'boolean')
14
+ return 'boolean';
15
+ if (typeof firstValue === 'number')
16
+ return 'number';
17
+ return 'string';
18
+ }
19
+ return undefined;
20
+ };
1
21
  export const extractSchemaProperties = (schema) => {
2
22
  if (!schema) {
3
23
  return [];
@@ -36,12 +56,13 @@ export const extractSchemaProperties = (schema) => {
36
56
  }
37
57
  if (typeof value === 'object' && !Array.isArray(value)) {
38
58
  const keys = Object.keys(value);
39
- if ('type' in value || keys.some((key) => /^x-.*type$/.test(key))) {
40
- const typeKey = 'type' in value ? 'type' : keys.find((key) => /^x-.*type$/.test(key));
59
+ const type = getSchemaType(value, keys);
60
+ if (type !== undefined) {
41
61
  const prop = {
42
62
  name: name,
43
- type: value[typeKey],
63
+ type,
44
64
  description: value.description || value['const'],
65
+ enumValues: getEnumValues(value),
45
66
  deprecated: value.deprecated,
46
67
  required: requiredFields.has(name),
47
68
  };