-
Notifications
You must be signed in to change notification settings - Fork 23
feat: request body raw/json mode editor #1050
Conversation
…nto feat/json-editor
…plorer into feat/json-editor
…plorer into feat/json-editor
…nto feat/json-editor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, had a question though about the feature.
Should the form data sync with the JSON?
e.g. if I put 12345 in the form's ID field, should the JSON initialize with the ID? Should it work the other direction too?
Not sure if this is an easy fix or not, but it would be pretty pleasant UX.
packages/api-explorer/src/Doc.jsx
Outdated
data = JSON.parse(rawData); | ||
|
||
return { | ||
dirty: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side thought, and doesn't block the review approval, but do we even need a dirty flag anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually we might need to still split up the dirty flag and let the form and json editor maintain their own dirty states because right now if you edit the json tab and switch over to the form it'll be dirty despite nothing being changed in it.
@Dashron We decided for the MVP that data wouldn't sync between the form and json tabs because we'll need to introduce JSON schema validation to prevent people from turning object requests into arrays and breaking the form (which is very brittle). |
Def makes sense. 👍 |
The button is still in the invalid state if the form request is good when:
|
🧰 What's being changed?
This adds a new JSON tab on
application/json
-compatible request bodies to allow users to edit the raw JSON contents of their request.The initial contents of this editor is populated from the first example we can grab off the request. If we can't grab an example, we'll default to an empty JSON object.
Syncing this data between the form inputs is not currently supported.
enableRequestBodyJsonEditor
prop on the explorer.🧪 Testing
Load up the test server and check the petstore example. You should be able to: