Skip to content

Constants Do Not Display when oneOf Syntax is used on String Elements #2865

@kentbulza

Description

@kentbulza

Context

JSON Schema does not support description/titles on enums. Therefore the recommended work-around is to use oneOf syntax with an array of constants, which does support descriptions.

Current Behavior

Although the description or title displays, the const does not. This is really a bug because you can't easily see what value you are expected to use. See below:

Image

Expected Behavior

My recommendation on non-object oneOfs would be to treat them visually just like enums and display the possible values along with their descriptions. The drop-down is valuable for more complex situations like objects, but nonsensical for what should be simple enums but for the JSON schema limitation.

Sample Doc

Here is a sample OpenAPI 3.1 document demonstrating the issue:

{ "openapi": "3.1.0", "info": { "title": "Dog Food API", "version": "1.0.0", "description": "API for adding dog food SKUs" }, "paths": { "/addDogFood": { "post": { "operationId": "addDogFood", "summary": "Add dog food items", "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "dogFoods": { "type": "array", "items": { "type": "object", "properties": { "sku": { "type": "string" }, "name": { "type": "string", "readOnly": true }, "flavor": { "type": "string", "oneOf": [ { "const": "beef", "title": "Beef-flavored" }, { "const": "chicken", "title": "Chicken-flavored" }, { "const": "fish", "title": "Fish or other seafood flavored" } ] } }, "required": [ "sku", "name", "flavor" ] }, "uniqueItems": true, "minItems": 1 } }, "required": [ "dogFoods" ] } } } }, "responses": { "200": { "description": "Dog food items added successfully" } } } } } }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions