asyncapi / asyncapi/asyncapi-react

Schema type badge does not show [TypeName] for non-object schemas with title (e.g. enums show as plain "string" instead of "string [OrderStatus]")

Open Beginner friendly
#1,308 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
243
Forks
182
Avg merge
3d 6h
Merged PRs (30d)
11

Description

## Description

When a named enum (or any non-object schema) has a `title` set, the type badge renders the bare primitive type (e.g. `string`) without appending `[TypeName]`.

Object schemas with a `title` already display correctly as `object [TypeName]`, this behaviour is missing for other types.

## Steps to reproduce

Expand the Order schema in the playground with this spec and look at the
`status` property type badge.

```
asyncapi: 3.0.0
info:
title: Enum Display Test
version: 1.0.0
components:
schemas:
OrderStatus:
type: string
title: OrderStatus
enum: [OPEN, IN_PROGRESS, CLOSED]
Order:
type: object
properties:
status:
$ref: '#/components/schemas/OrderStatus'
```

## Expected: `string [OrderStatus]`
## Actual: `string`

## Root cause

In `library/src/helpers/schema.ts`, `toSchemaType()` only appends `[title]`
when `type === 'object'`:

if (type === 'object' && schema.title()) {
type += ' [' + schema.title() + ']';
}

## Suggested fix

if (schema.title() && type !== schema.title()) {
type += ' [' + schema.title() + ']';
}

The `type !== schema.title()` guard prevents degenerate output like `string [string]`. This is consistent with existing object behaviour, it simply extends it to all named schema types.

Contributor guide

Open the contributing guide

Research direction

Start in library/src/helpers/schema.ts at toSchemaType(), then reproduce the OrderStatus example in the playground. The issue is done when titled non-object schemas display their primitive type with [TypeName], while avoiding duplicate labels such as string [string].

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.