Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,12 @@ <h2> Supported vendor extensions</h2>
</td>
<td style="width:130px;"><a href="./examples/code-samples.html"> Usage Example </a> </td>
</tr>
<tr id="x-extensible-enum">
<td class="mono bold right" style="width:160px;" >x-extensible-enum</td>
<td class="gray"> Use this vendor-extension to provide document extensible enums/growable lists.
</td>
<td style="width:130px;"><a href="./examples/extensible-enum.html"> Usage Example </a> </td>
</tr>
<tr id="x-badges">
<td class="mono bold right" style="width:130px;">x-badges </td>
<td class="gray"> Use this vendor-extension to annotate end-points with short color coded lables.
Expand Down
12 changes: 12 additions & 0 deletions docs/examples/extensible-enum.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
<script src="./load-rapidoc-and-other-common-scripts.js"></script>
</head>

<body>
<rapi-doc spec-url="../specs/x-extensible-enum.yaml" render-style="read" allow-try="false"> </rapi-doc>
</body>
</html>
7 changes: 7 additions & 0 deletions docs/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ <h2 style="font-weight:700"> RapiDoc Mini </h2>
</div>
</div>

<div class = "container">
<a href="./examples/extensible-enum.html"> Extensible Enums </a>
<div class = "c-description" >
Support for x-extensible-enum (vendor extension) in schemas
</div>
</div>

<div class = "container">
<a href="./examples/badges.html"> Endpoint Badges </a>
<div class = "c-description" >
Expand Down
61 changes: 61 additions & 0 deletions docs/specs/x-extensible-enum.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
openapi: 3.0.0
info:
title: x-extensible-enum Example
description: Example API demonstrating x-extensible-enum usage.
version: 1.0.0
tags:
- name: Person
description: Operations related to people
servers:
- url: https://api.example.com
paths:
/people:
post:
summary: Create person
description: Create a new person with various attributes including hobbies and marital status.
operationId: createPerson
tags:
- Person
requestBody:
description: Person object that needs to be added
content:
application/json:
schema:
type: object
properties:
name:
type: string
hobbies:
type: array
minItems: 1
maxItems: 3
items:
type: string
x-extensible-enum:
- computers
- hiking
- swimming
- movies
- music
- dancing
- reading
- painting
default: hiking
tags:
type: array
items:
type: string
maritalStatus:
type: string
enum:
- married
- unmarried
- widowed
required:
- name
- hobbies
responses:
"200":
description: successful operation
"404":
description: not found
1 change: 1 addition & 0 deletions src/styles/schema-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default css`
.null { color:var(--red); }
.bool, .boolean { color:var(--orange) }
.enum { color:var(--purple) }
.xext { color:var(--purple) }
.cons { color:var(--purple) }
.recu { color:var(--brown) }
.toolbar {
Expand Down
17 changes: 11 additions & 6 deletions src/utils/schema-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ export function getTypeInfo(schema) {
let constrain = '';
// let examples;

const enumValues = schema.enum || schema['x-extensible-enum'];
if (schema.$ref) {
const n = schema.$ref.lastIndexOf('/');
const schemaNode = schema.$ref.substring(n + 1);
dataType = `{recursive: ${schemaNode}} `;
} else if (schema.type) {
dataType = Array.isArray(schema.type) ? schema.type.join('┃') : schema.type;
if (schema.format || schema.enum || schema.const) {
dataType = dataType.replace('string', schema.enum ? 'enum' : schema.const ? 'const' : schema.format);
if (schema.format || schema.enum || schema.const || schema['x-extensible-enum']) {
dataType = dataType.replace(
'string',
schema.enum ? 'enum' : schema.const ? 'const' : schema['x-extensible-enum'] ? 'x-extensible-enum' : schema.format,
);
}
if (schema.nullable) {
dataType += '┃null';
Expand Down Expand Up @@ -79,20 +83,21 @@ export function getTypeInfo(schema) {
// Set Allowed Values
info.allowedValues = schema.const
? schema.const
: Array.isArray(schema.enum)
? schema.enum.map((v) => (getPrintableVal(v))).join('┃')
: Array.isArray(enumValues)
? enumValues.map((v) => (getPrintableVal(v))).join('┃')
: '';

if (dataType === 'array' && schema.items) {
const arrayItemType = schema.items?.type;
const arrayItemDefault = getPrintableVal(schema.items.default);
const arrayEnumValues = schema.items?.enum || schema.items?.['x-extensible-enum'];

info.arrayType = `${schema.type} of ${Array.isArray(arrayItemType) ? arrayItemType.join('') : arrayItemType}`;
info.default = arrayItemDefault;
info.allowedValues = schema.items.const
? schema.const
: Array.isArray(schema.items?.enum)
? schema.items.enum.map((v) => (getPrintableVal(v))).join('┃')
: Array.isArray(arrayEnumValues)
? arrayEnumValues.map((v) => (getPrintableVal(v))).join('┃')
: '';
}
if (dataType.match(/integer|number/g)) {
Expand Down