You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 6.6 KiB

13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
13 years ago
12 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. Swagger UI
  2. ==========
  3. Swagger UI is part of [Swagger](http://swagger.wordnik.com/) project. The Swagger project allows you to produce, visualize and consume your OWN RESTful
  4. services. No proxy or 3rd party services required. Do it your own way.
  5. Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically
  6. generate beautiful documentation and sandbox from a [Swagger-compliant](https://github.com/wordnik/swagger-core/wiki) API. Because Swagger UI has no
  7. dependencies, you can host it in any server environment, or on your local machine.
  8. How to Use It
  9. -------------
  10. ### Download
  11. You can use the swagger-ui code AS-IS! No need to build or recompile--just [download](https://github.com/wordnik/swagger-ui/downloads) the distribution,
  12. unpack and start using it. If you like swagger-ui as-is, stop here.
  13. ### Build
  14. You can rebuild swagger-ui on your own to tweak it or just so you can say you did. To do so, follow these steps:
  15. 1. Install [CoffeeScript](http://coffeescript.org/#installation) which will give you [cake](http://coffeescript.org/#cake)
  16. 2. Install [handlebars](http://handlebarsjs.com/) using 'npm install handlebars -g'
  17. 3. Run cake dist
  18. 4. You should see the distribution under the dist folder. Open ./dist/index.html to launch Swagger UI in a browser
  19. ### Use
  20. Once you open the Swagger UI, it will load the [Swagger Petstore](http://petstore.swagger.wordnik.com/api/resources.json) service and show its APIs.
  21. You can enter your own server url and click explore to view the API.
  22. ### Customize
  23. You may choose to customize Swagger UI for your organization. Here is an overview of whats in its various directories:
  24. - dist: Contains a distribution which you can deploy on a server or load from your local machine.
  25. - bin: Contains files used by swagger-ui for its build/test. These are not required by the distribution.
  26. - lib: Contains javascript dependencies which swagger-ui depends on
  27. - node_modules: Contains node modules which swagger-ui uses for its development.
  28. - src
  29. - src/main/coffeescript: main code in CoffeeScript
  30. - src/main/templates: [handlebars](http://handlebarsjs.com/) templates used to render swagger-ui
  31. - src/main/html: the html files, some images and css
  32. - src/main/javascript: some legacy javascript referenced by CofffeeScript code
  33. ### SwaggerUi
  34. To use swagger-ui you should take a look at the [source of swagger-ui html page](https://github.com/wordnik/swagger-ui/tree/master/src/main/html) and customize it. This basically requires you to instantiate a SwaggerUi object and call load() on it as below:
  35. ```javascript
  36. window.swaggerUi = new SwaggerUi({
  37. discoveryUrl:"http://petstore.swagger.wordnik.com/api/resources.json",
  38. dom_id:"swagger-ui-container",
  39. apiKey:"special-key",
  40. supportHeaderParams: false,
  41. headers: { "Authorization": "XXXX", "someOtherHeader": "YYYY" },
  42. supportedSubmitMethods: ['get', 'post', 'put']
  43. });
  44. window.swaggerUi.load();
  45. ```
  46. * *discoveryUrl* parameter should point to a resource listing url as per [Swagger Spec](https://github.com/wordnik/swagger-core/wiki)
  47. * *dom_id parameter* is the the id of a dom element inside which SwaggerUi will put the user interface for swagger
  48. * *booleanValues* SwaggerUI renders boolean data types as a dropdown. By default it provides a 'true' and 'false' string as the possible choices. You can use this parameter to change the values in dropdown to be something else, for example 0 and 1 by setting booleanValues to new Array(0, 1)
  49. * *docExpansion* controls how the API listing is displayed. It can be set to 'none' (default), 'list' (shows operations for each resource), or 'full' (fully expanded: shows operations and their details)
  50. * *onComplete* is a callback function parameter which can be passed to be notified of when SwaggerUI has completed rendering successfully.
  51. * *onFailure* is a callback function parameter which can be passed to be notified of when SwaggerUI encountered a failure was unable to render.
  52. * All other parameters are explained in greater detail below
  53. ### HTTP Methods and API Invocation
  54. swagger-ui supports invocation of all HTTP methods APIs but only GET methods APIs are enabled by default. You can choose to enable other HTTP methods like POST, PUT and DELETE. This can be enabled by [setting the supportedSubmitMethods parameter when creating SwaggerUI instance](https://github.com/wordnik/swagger-ui/blob/f2e63c65a759421aad590b7275371cd0c06c74ea/src/main/html/index.html#L49).
  55. For example if you wanted to enable GET, POST and PUT but not for DELETE, you'd set this as:
  56. supportedSubmitMethods: ['get', 'post', 'put']
  57. _Note that for POST/PUT body, you'd need to paste in the request data in an appropriate format which your service can unmarshall_
  58. ### Header Parameters
  59. header parameters are supported. However because of [Cross-Origin Resource Sharing](http://www.w3.org/TR/cors/) restrictions, swagger-ui, by default, does not send header parameters. This can be enabled by [setting the supportHeaderParams to true when creating SwaggerUI instance](https://github.com/wordnik/swagger-ui/blob/f2e63c65a759421aad590b7275371cd0c06c74ea/src/main/html/index.html#L48) as below:
  60. supportHeaderParams: true
  61. ### Custom Header Parameters - (For Basic auth etc)
  62. If you have some header parameters which you need to send with every request, use the headers as below:
  63. headers: { "Authorization": "XXXX", "someOtherHeader": "YYYY" }
  64. ### Api Key Parameter
  65. If you enter an api key in swagger-ui, it sends a parameter named 'api\_key' as a query (or as a header param if you've enabled it as described above). You may not want to use the name 'api\_key' as the name of this parameter. You can change its name by setting the _apiKeyName_ parameter when you instantiate a SwaggerUI instance. For example to call it 'sessionId'
  66. apiKeyName: "sessionId"
  67. How to Improve It
  68. -----------------
  69. Create your own fork of [wordnik/swagger-ui](https://github.com/wordnik/swagger-ui)
  70. To share your changes, [submit a pull request](https://github.com/wordnik/swagger-ui/pull/new/master).
  71. License
  72. -------
  73. Copyright 2011-2012 Wordnik, Inc.
  74. Licensed under the Apache License, Version 2.0 (the "License");
  75. you may not use this file except in compliance with the License.
  76. You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
  77. Unless required by applicable law or agreed to in writing, software
  78. distributed under the License is distributed on an "AS IS" BASIS,
  79. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  80. See the License for the specific language governing permissions and
  81. limitations under the License.