Giter Site home page Giter Site logo

swagger-api / swagger-editor Goto Github PK

View Code? Open in Web Editor NEW
8.7K 259.0 2.2K 1.65 GB

Swagger Editor

Home Page: https://editor.swagger.io

License: Apache License 2.0

JavaScript 94.84% HTML 1.64% Shell 0.68% Dockerfile 0.10% Less 2.74% Roff 0.01%
swagger swagger-editor swagger-ui rest-api rest openapi-specification openapi3 hacktoberfest openapi31 open-source

swagger-editor's Issues

Move project into swagger org

…assuming we can set one up, otherwise possibly Wordnik org.

  • Move to new org (do issues move, too?)
  • Add licensing notice
  • Update the readme with info and how to participate

Move JSON out of editor and over to html pane

YAML has reusable bits that get rendered into JSON. The problem is that is lossy—there isn't an easy way to preserve the relationship of the JSON back to the original definition. This has potential to complicate the 2-way editing process (as does the multiple file aspect of JSON).

Instead, let's move JSON out of the edit pane and over to the swagger-ui pane. Then you can see the docs or switch to the JSON view.

Explore parsing YAML syntax

We need to get access to AST of YAML in order to able to modify the YAML programmatically. Explore our options.

Refactor the YAML syntax

For example, editing the "resourcePath" doesn't update the child APIs' paths. Also, the "path" could be a top-level element rather than a child of "apis".

Marsh and Tony will work this out.

Can't run locally

Any ideas why I'd get this message when running locally?

fehguy:phonics tony$ grunt serve

/Users/tony/dev/projects/fehguy/phonics/node_modules/grunt/node_modules/findup-sync/lib/findup-sync.js:33
    }).flatten().uniq().value();
       ^
TypeError: Object Gruntfile.js has no method 'flatten'
    at Object.module.exports [as findup] (/Users/tony/dev/projects/fehguy/phonics/node_modules/grunt/node_modules/findup-sync/lib/findup-sync.js:33:8)
    at Task.task.init (/Users/tony/dev/projects/fehguy/phonics/node_modules/grunt/lib/grunt/task.js:427:16)
    at Object.grunt.tasks (/Users/tony/dev/projects/fehguy/phonics/node_modules/grunt/lib/grunt.js:117:8)
    at Object.module.exports [as cli] (/Users/tony/dev/projects/fehguy/phonics/node_modules/grunt/lib/grunt/cli.js:38:9)
    at Object.<anonymous> (/usr/local/lib/node_modules/grunt-cli/bin/grunt:43:20)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

I have the following runtimes:

fehguy:phonics tony$ node --version
v0.10.21
fehguy:phonics tony$ grunt --version
grunt-cli v0.1.11
grunt v0.4.4

Autocompletion of swagger-yaml

related to #25, is the idea of autocompletion. At its simplest, this might be tab-completion of a key name. Even better would be if it could also understand the YAML schema, so that appropriate values could be decided between. ACE has both "snippets" and "autocomplete, see: https://github.com/ajaxorg/ace/wiki/How-to-enable-Autocomplete-in-the-Ace-editor

Snippets example using XSLT: https://github.com/ajaxorg/ace/blob/a4a30b6665da5f5ef9c3bd23d7bac01374bae450/lib/ace/snippets/xslt.snippets

Consider snippets for adding a full now path or method element. Best of all would be if it could pull context from the working doc so that if I've defined a reusable YAML param, then I could choose from the list of those names.

Add codegen support

The killer demo is using the consolidated spec for codegen. It works like this.

There is an online codegen that lives here. It has a swagger description available here:

http://generator.wordnik.com

There are some bugs in the input model right now so the POST methods are not accurate. A proper usage is like such:

generate a java client:

EDIT: this is now on the wordnik domain

curl -X POST http://generator.wordnik.com/online/api/gen/client/java -H "Content-Type:application/json" -d @client.json -o java-client.zip

generate a objc client:

curl -X POST http://generator.wordnik.com/online/api/gen/client/objc -H "Content-Type:application/json" -d @client.json -o objc-client.zip

generate a jaxrs server:

curl -X POST http://generator.wordnik.com/online/api/gen/server/jaxrs -H "Content-Type:application/json" -d @server.json -o jaxrs-server.zip

client.json:

https://gist.github.com/mohsen1/ec3afcadef5e88a8cb50

Allow definition of re-usable YAML bits

Swagger's YAML generator does support re-usable YAML bits that can then be referred to later. We should support this and allow creation of those reusable snippets.

Resolve the conflict between distributed resources

Swagger-JSON defines the root description with api-doc, such as:
petstore.swagger.wordnik.com/api/api-docs

This tells you the individual resources families that you get a description for each.

YAML should have a unified view of all the description in one file. How to deal with this?

Design error pane

When the YAML syntax is incorrect we hide documents and show an error pane. Please design the error pane with some icons and fonts. You can find the html file at invalid-docs.html.

Buttons for common tasks

Beginners unfamiliar with the swagger-yaml syntax may benefit from buttons to add path, method, params, and even re-usable params.

Guidance for users unfamiliar with the YAML format

There will be many people who do not know the syntax for Swagger-YAML. We can help them with approaches like a syntax list on the right-hand pane, autocomplete, and/or buttons to "add a resource" or "add a method" or "add a query parameter", etc.

Add delay for refreshing right-hand pane

Right now, when you start typing, the swagger-ui blanks out and tries to redraw. This can be jerky.

Instead, try leaving the swagger-ui in place until there hasn't been a keystroke for 500ms. Then draw the update.

This should solve the "jerkiness" and may enable us to remove the "live update" button.

Enable saving and loading of one's work

If you do work, you need a way to save and restore it. This could be done in localstorage, or it could be a github repo/gist integration, or it could be the filesystem.

Compatibiity with Swagger-styling

Today the header is orange, but that isn't necessarily harmonious with the Swagger styles. Petstore is a good example. @fehguy may have guidance here…

Note that Swagger 2 will present a chance to revisit the Swagger style.

YAML Linting

This story refers to item number 3 below…

There are at least three ways we can help guide users:

  1. Auto-complete. Minimum is the total syntax, best is contextual to the structure's location
  2. Contextual help to offer syntax guidance (could be as simple as an expandable pane or dialog)
  3. Validation of the Swagger-YAML (linting). This is more than just creating valid YAML—it includes checking for required elements, etc.
  4. Buttons such as "add a resource" or "add a method" or "add a query parameter", etc.

The guiding question is, "How do we make authoring the swagger-yaml easy for people who do not yet know the synax?"

Deal with consolidated swagger-json

Guidance from @fehguy:
Updated library which takes consolidated JSON:
https://github.com/wordnik/swagger-js/blob/develop/lib/swagger.js

and corresponding swagger-ui branch:

https://github.com/wordnik/swagger-ui/tree/develop/dist

You can see an example in this test script:

https://github.com/wordnik/swagger-js/blob/develop/src/specs/petstore_1_2_spec.js#L441

Note there is an array of “apiDeclarations” which literally map to the swagger json for each root resource. So if you take this:

http://petstore.swagger.wordnik.com/api/api-docs

add a key “apiDeclarations” with array value containing each of these:

http://petstore.swagger.wordnik.com/api/api-docs/pet

http://petstore.swagger.wordnik.com/api/api-docs/store

http://petstore.swagger.wordnik.com/api/api-docs/user

You’d have the “consolidated JSON”.

When using this with swagger-ui, you simply initialize it as follows:

window.swaggerUi = new SwaggerUi({url: “URL”, obj: THE_SWAGGER_CONSOLIDATED_OBJECT, ….

Make a checkbox on header to disable auto render of docs

Put a checkbox on header for disabling auto rendering of docs.

Checkbox label should say "Auto-generate docs"
Initial state should be checked
By unchecking it auto generation of docs will be stopped and docs panel go dim
By checking it, docs get generated automatically and preview panel will un-dim

YAML merge issue

seems like the YAML 2 JSON process is not processing merges or anchors

Additional panels beyond YAML and Swagger-ui panes

Consider an approach more like jsbin where you can toggle multiple panels. This might include:

  • YAML
  • JSON
  • Template (for generating docs)
  • HTML (or docs)

As you edit in YAML, the JSON would update, and vice versa (except for the reusable bit, need to think about that)

Remove try-it functionality

No need to try it when the API is being designed and doesn't exist yet! In the short term, remove the try-it button and hide the auth config.

URL will get updated on navigation

SwaggerUI has it's own navigation router system. Manage to integrate that routing system into our app.

For example #!/pet/deletePet should be translated to /#/pet/deletePet

Add filters for custom YAML specification

We like to have more specs on top of JSON specific specs. For example renamed keys in YAML. Those keys would get translated during YAML-to-JSON conversion

@earth2marsh please write specific key names we need to translate to generate JSON

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.