-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON Body Editor (Master PR) #1589
Conversation
Conflicts: dist/index.html dist/swagger-ui.js dist/swagger-ui.min.js src/main/coffeescript/view/MainView.coffee src/main/coffeescript/view/OperationView.coffee src/main/coffeescript/view/ParameterView.coffee src/main/coffeescript/view/ResourceView.coffee src/main/coffeescript/view/SignatureView.coffee src/main/html/index.html
Conflicts: dist/index.html dist/swagger-ui.js dist/swagger-ui.min.js
Conflicts: dist/swagger-ui.js dist/swagger-ui.min.js
…ditor Conflicts: dist/swagger-ui.js dist/swagger-ui.min.js package.json
Conflicts: dist/swagger-ui.js dist/swagger-ui.min.js
Conflicts: dist/index.html dist/swagger-ui.js dist/swagger-ui.min.js src/main/html/index.html src/main/template/param.handlebars src/main/template/param_required.handlebars
Fix $ref strings treated as objects by JSONEditor
Conflicts: dist/swagger-ui.js dist/swagger-ui.min.js src/main/less/screen.less
Thanks again for all the work. I'll test the functionality in the upcoming days and hopefully we'll manage to get it merged soon. I'm sure many users would be excited for it. If any user wants to clone the fork and test the PR and provide feedback, that would be great too. |
@lepinayl Thanks for this PR! It looks really awesome. I have a question about the functionality-- is the editor supposed to serialize automatically? For example: The user field is incorrectly set up when I load the page (it should be an object): But when I choose "object" it is serialized properly. It seems to me that the "user" field should be pre chosen as an object (maybe I shouldn't even have an option to send it as a boolean?) Its possible my swagger definition has an error in it, but this seems like confusing behavior to me. Best, |
@jontonsoup thank you for the testing feedback, it would be great if you could share your json spec so that I can have a look to the issue because you are right it should serialize automatically, I haven't encountered this behaviour yet. |
I tried to clean it up to the relevant parts. Please let me know if its missing anything. @lepinay
|
@jontonsoup this was indeed a regression, I've tested it on your schema and it should be fixed now. |
Awesome! This is a great feature-- thanks for adding it. On Wed, Sep 16, 2015 at 5:00 AM, foo bar code notifications@github.com
|
@lepinay I actually just checked out the new branch and I still have the error. I'm wondering if it has something to do with my data type being undefined. Best, |
Conflicts: dist/swagger-ui.js dist/swagger-ui.min.js
@frol Thanks for pointing out the images issue, it's fixed now. |
@lepinayl I've been using your fork for the last 3 days and it has been working great even on semi-complex nested schemas! Great job! I have spotted only one minor bug. JSON Editor ignores validation of required fields and sends empty string values instead of preventing sending the data. Here is my endpoint config: "post": {
"operationId": "post_users",
"parameters": [
{
"in": "body",
"name": "body",
"required": true,
"schema": {
"properties": {
"username": {
"description": "Example: root",
"location": "json",
"type": "string"
},
"password": {
"description": "No rules yet",
"location": "json",
"type": "string"
}
},
"required": [
"username",
"password"
]
}
}
]
} P.S. It would be nice if JSON Editor might use free space of "Description" column to be wider. |
@frol Thanks for the kind feedback, I'll look into that issue. |
@lepinayl I caught one more minor bug - re-adding (add -> remove -> add) a new item to a list results in ignoring (not-showing) non-required fields (see Here is my endpoint specification: "patch": {
"operationId": "patch_user_by_id",
"parameters": [
{
"in": "path",
"name": "user_id",
"required": true,
"type": "integer"
},
{
"in": "body",
"name": "body",
"required": true,
"schema": {
"items": {
"properties": {
"op": {
"enum": [
"replace",
"remove",
"test",
"add"
],
"location": "json",
"type": "string"
},
"path": {
"enum": [
"/password",
"/email",
],
"location": "json",
"type": "string"
},
"value": {
"location": "json",
"type": "string"
}
},
"required": [
"op",
"path"
]
},
"location": "json",
"type": "array"
}
}
]
} |
@lepinayl There is a minor UI bug after "Delete last item" of an array: the "Move Down" button of the last item remains. The steps to reproduce: "Add item" to "Item 3" -> "Delete Last item". |
Here's an updated implementation of the JSON Body Editor with the RingCentral API Spec:
We found that our property descriptions were long enough that they used too much vertical space so we've implemented an initial approach to convert these descriptions to tooltips. |
Conflicts: dist/swagger-ui.js dist/swagger-ui.min.js src/main/javascript/view/OperationView.js src/main/less/screen.less
@agongdai I've been trying to reproduce the issue on http://thomsonreuters.github.io/swagger-ui/ but with no success, could you double check if you have the issue there ? |
@grokify I like the idea of the tooltip, if you have time to make a PR on https://github.com/thomsonreuters/swagger-ui/tree/JSONEditorMaster with a feature toggle in swagger options (some people might prefer to use the current version) then I will merge it. Update: If you are up to it, you can now make you PR directly into swagger's master |
@frol Thanks got it now |
First off, thank you again for keeping this PR going. The delay merging has been on our side. Next, I'm setting the editor to off by default, and we'll update the documentation. Finally, it's getting merged into master now. Thanks again! |
@fehguy Thanks for the merge, it will definitively help other interested into that feature to contribute and help manage bug fixes more efficiently. I'll now focus on getting the pending PR I have at jdorn/json-editor to be merged so that we can rely on the official version instead of the custom built one coming with this PR. |
Yes, again many thanks for the patience, and apologies for the delay on merging. I did default it to |
@lepinay Thanks for the suggestion for a tooltip PR. I think it's a good idea and would like to do that. First, there's a dependency on getting a PR into jdorn/json-editor. Once that's been done we can work on a PR for the JSON body editor. |
Would it be possible to be able to toggle between the json-editor and text field, rather either having to use one or the other? In some cases the editor is simpler to use and in others the text field is easier. |
@lucasweb78 It's hard trying to make everything configurable at that level. This is not only about code, but about UX. Having you and others wanting this feature doesn't mean others would want it as well. However, this being an open source project with a permissive license allows you to customize the code to your own needs. We're not offended by it, we even encourage you to do so. |
With this update, is the payload now getting validated within the editor as well? It'd be cool if it compared the JSON payload returned to the Swagger schema. |
@atdiffthis unfortunately no... |
Bummer. Thanks @lepinay. Do you know if there are plans to integrate that as an option at some point? I might log it as an issue if not. |
@atdiff No there are no plans to share functionality between the two. I think it might be a good idea to raise that as a separated issue for the standard editor only. |
Feature proposal: JSON Body Editor
Previous history
This PR is a continuation of #1088
You will find earlier informations/comments there about the history of this PR.
Related work
This is a proposal to add a JSON editor for body requests in swagger UI.
This work is based on another open source project called Json-editor by Jeremy Dorn.
You will be able to find a demo of Jeremy's editor here to give you an idea of the great potential of this editor.
Configuration
The editor can be enabled/disabled using the swagger configuration key
jsonEditor
:The option is currently enabled by default (just because it is more practical for e2e tests).
Visual preview
This is how it looks like at the moment in a post request:
Online preview
You can try the UI with the editor here: http://thomsonreuters.github.io/swagger-ui/
you will need to have CORS enabled on your endpoint
Backward compatibility
According to the way swagger now works, Specs 1.2 are now automaticaly converted to 2.0.
So it should work with 1.2 as well but I haven't not tested it yet.
Current state of the implementation
Please let me know how I could improve both the internal design (code, unit tests, configuration) and external design (css, user experience).
External dependencies
The following PR have been created on JSONEditor to implement this feature
jdorn/json-editor#461 (closed)
jdorn/json-editor#456 (open, need some rework)
jdorn/json-editor#512 (merged)
So at the moment this PR is using a custom JSONEditor version until both remaining PR will be accepted.
Tests
Tested on
http://petstore.swagger.io/v2/swagger.json
https://raw.githubusercontent.com/jabr9983/swagger.json/master/swagger.json
Not tested yet
http://ringcentral.github.io/api-explorer-beta/swagger-ring.json
https://api.swaggerhub.com/apis/fehguy/ringcentral-api/1.0