Skip to content
Merged
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
13 changes: 13 additions & 0 deletions demo/examples/tests/anyOf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ paths:
- type: integer
- type: boolean
- type: null
- enum:
- dealValue
- price
- userRating
- popularityScore
```

Note: The last option is an inline enum without an explicit type,
which is valid JSON Schema. The enum values should be displayed.
responses:
"200":
description: Successful response
Expand All @@ -32,6 +40,11 @@ paths:
- type: integer
- type: boolean
- type: "null"
- enum:
- dealValue
- price
- userRating
- popularityScore

/anyof-oneof:
get:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
import { SchemaObject } from "../openapi/types";

function prettyName(schema: SchemaObject, circular?: boolean) {
// Handle enum-only schemas (valid in JSON Schema)
// When enum is present without explicit type, treat as string
if (schema.enum && !schema.type) {
return "string";
}

if (schema.format) {
if (schema.type) {
return `${schema.type}<${schema.format}>`;
Expand Down
6 changes: 6 additions & 0 deletions packages/docusaurus-theme-openapi-docs/src/markdown/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import { OPENAPI_SCHEMA_ITEM } from "../theme/translationIds";
import { SchemaObject } from "../types";

function prettyName(schema: SchemaObject, circular?: boolean) {
// Handle enum-only schemas (valid in JSON Schema)
// When enum is present without explicit type, treat as string
if (schema.enum && !schema.type) {
return "string";
}

if (schema.format) {
return schema.format;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,5 +999,10 @@ const PRIMITIVE_TYPES: Record<PrimitiveSchemaType, true> = {
} as const;

const isPrimitive = (schema: SchemaObject) => {
// Enum-only schemas (without explicit type) should be treated as primitives
// This is valid JSON Schema where enum values define the constraints
if (schema.enum && !schema.type) {
return true;
}
return PRIMITIVE_TYPES[schema.type as PrimitiveSchemaType];
};