Redocly / Redocly/redoc

Possiblily to display String as JSON in the Response samples block

Open
#2,469 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Enhancement
Dominant language
TypeScript
Stars
25.9k
Forks
2.4k
Avg merge
13h 10m
Merged PRs (30d)
4

Description

Describe the problem to be solved
Is there any way to detect the media type application/json and display the JSON in the Response samples block?

For example

in this case, it works properly, it can display the JSON in the Response samples block

openapi: 3.0.1
info:
  title: Example
  version: 1.0.0
paths:
  /example:
    get:
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Config'
        "404":
          content:
            application/json:
              schema:
                type: object
                example: {'errors': [{'code': 'E001', 'message': 'NotFound'}]}
components:
  schemas:
    Config:
      type: object
      properties:
        name:
          type: string
      example: {'name': 'A'}

But in this case it will display as a plain text

openapi: 3.0.1
info:
  title: Example
  version: 1.0.0
paths:
  /example:
    get:
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Config'
        "404":
          content:
            application/json:
              schema:
                type: object
                example: "{'errors': [{'code': 'E001', 'message': 'NotFound'}]}"
components:
  schemas:
    Config:
      type: object
      properties:
        name:
          type: string
      example: "{'name': 'A'}"

Describe the solution you'd like
Display the example based on the media type

Describe alternatives you've considered
N/A

Additional context
N/A

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two OpenAPI examples in the Response samples block and compare how object examples and string examples are rendered. Trace the Response samples implementation to see where the application/json media type is handled; done means JSON-looking string examples render as JSON while other plain-text examples remain text.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, documentation
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.