Skip to content

Commit 68be02b

Browse files
committed
Support for x-gitbook-enum
1 parent 90b25a7 commit 68be02b

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

packages/openapi-parser/src/types.ts

+15
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ export interface OpenAPICustomOperationProperties {
4747
* Description in Document format.
4848
*/
4949
'x-gitbook-description-document'?: object;
50+
51+
/**
52+
* Enums with name and description
53+
*/
54+
'x-enumDescriptions'?: object;
55+
56+
/**
57+
* Enums with name and description
58+
*/
59+
'x-gitbook-enum'?: {
60+
[key: string]: {
61+
description: string;
62+
name: string;
63+
};
64+
};
5065
}
5166

5267
/**

packages/react-openapi/src/OpenAPISchema.tsx

+20-2
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,33 @@ function OpenAPISchemaEnum(props: {
242242
}) {
243243
const { schema } = props;
244244

245-
if (!schema.enum || !schema.enum.length || !schema['x-enumDescriptions']) {
245+
if (!schema.enum?.length || (!schema['x-enumDescriptions'] && !schema['x-gitbook-enum'])) {
246246
return null;
247247
}
248248

249249
const enumValues = (() => {
250+
if (schema['x-gitbook-enum']) {
251+
return Object.entries(schema['x-gitbook-enum']).map(([_, { description, name }]) => {
252+
return {
253+
value: name,
254+
description,
255+
};
256+
});
257+
}
258+
259+
if (schema['x-enumDescriptions']) {
260+
return Object.entries(schema['x-enumDescriptions']).map(([value, description]) => {
261+
return {
262+
value,
263+
description,
264+
};
265+
});
266+
}
267+
250268
return schema.enum.map((value) => {
251269
return {
252270
value,
253-
description: schema['x-enumDescriptions']?.[value],
271+
description: undefined,
254272
};
255273
});
256274
})();

0 commit comments

Comments
 (0)