Possiblily to display String as JSON in the Response samples block
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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