Code Monkey home page Code Monkey logo

swagger-api / swagger-ui Goto Github PK

View Code? Open in Web Editor NEW
25.5K 649.0 8.8K 516.52 MB

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.

Home Page: https://swagger.io

License: Apache License 2.0

CSS 0.02% HTML 0.97% JavaScript 94.89% Shell 0.29% Dockerfile 0.07% SCSS 3.76%
swagger swagger-ui swagger-api swagger-js rest rest-api openapi-specification oas openapi openapi3

swagger-ui's Introduction

NPM version Build Status npm audit total GitHub contributors

monthly npm installs total docker pulls monthly packagist installs gzip size

Introduction

Swagger UI allows anyone — be it your development team or your end consumers — to visualize and interact with the API’s resources without having any of the implementation logic in place. It’s automatically generated from your OpenAPI (formerly known as Swagger) Specification, with the visual documentation making it easy for back end implementation and client side consumption.

General

👉🏼 Want to score an easy open-source contribution? Check out our Good first issue label.

🕰️ Looking for the older version of Swagger UI? Refer to the 2.x branch.

This repository publishes three different NPM modules:

  • swagger-ui is a traditional npm module intended for use in single-page applications that are capable of resolving dependencies (via Webpack, Browserify, etc.).
  • swagger-ui-dist is a dependency-free module that includes everything you need to serve Swagger UI in a server-side project, or a single-page application that can't resolve npm module dependencies.
  • swagger-ui-react is Swagger UI packaged as a React component for use in React applications.

We strongly suggest that you use swagger-ui instead of swagger-ui-dist if you're building a single-page application, since swagger-ui-dist is significantly larger.

If you are looking for plain ol' HTML/JS/CSS, download the latest release and copy the contents of the /dist folder to your server.

Compatibility

The OpenAPI Specification has undergone 5 revisions since initial creation in 2010. Compatibility between Swagger UI and the OpenAPI Specification is as follows:

Swagger UI Version Release Date OpenAPI Spec compatibility Notes
5.0.0 2023-06-12 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.1.0 tag v5.0.0
4.0.0 2021-11-03 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3 tag v4.0.0
3.18.3 2018-08-03 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3 tag v3.18.3
3.0.21 2017-07-26 2.0 tag v3.0.21
2.2.10 2017-01-04 1.1, 1.2, 2.0 tag v2.2.10
2.1.5 2016-07-20 1.1, 1.2, 2.0 tag v2.1.5
2.0.24 2014-09-12 1.1, 1.2 tag v2.0.24
1.0.13 2013-03-08 1.1, 1.2 tag v1.0.13
1.0.1 2011-10-11 1.0, 1.1 tag v1.0.1

Documentation

Usage

Customization

Development

Contributing

Integration Tests

You will need JDK of version 7 or higher as instructed here https://nightwatchjs.org/guide/getting-started/installation.html#install-selenium-server

Integration tests can be run locally with npm run e2e - be sure you aren't running a dev server when testing!

Browser support

Swagger UI works in the latest versions of Chrome, Safari, Firefox, and Edge.

Known Issues

To help with the migration, here are the currently known issues with 3.X. This list will update regularly, and will not include features that were not implemented in previous versions.

  • Only part of the parameters previously supported are available.
  • The JSON Form Editor is not implemented.
  • Support for collectionFormat is partial.
  • l10n (translations) is not implemented.
  • Relative path support for external files is not implemented.

Security contact

Please disclose any security-related issues or vulnerabilities by emailing [email protected], instead of using the public issue tracker.

License

SwaggerUI is licensed under Apache 2.0 license. SwaggerUI comes with an explicit NOTICE file containing additional legal notices and information.

swagger-ui's People

Contributors

aurelian avatar ayush avatar bodnia avatar char0n avatar dependabot[bot] avatar fehguy avatar glowcloud avatar heldersepu avatar hkosova avatar jonathanparrilla avatar lepinayl avatar mathis-m avatar minasokoni avatar mohsen1 avatar owenconti avatar ponelat avatar pose avatar renovate-bot avatar renovate[bot] avatar rpidikiti avatar rvken avatar scottohara avatar shockey avatar swagger-bot avatar swaggerhub-bot avatar symonenkov avatar thompsongl avatar tim-lai avatar webron avatar zeke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swagger-ui's Issues

support sending ApiKey as Basic Auth

Unless I cant see quite how to do it, I think there should be a way to configure sending the api key as a proper base 64 encoded basic auth header, for those apis that work in that manner.

Access-Control-Allow-Origin

There was an issue similar to the one I'm having, with a few important differences, posted a while ago:
#2

My issue is essentially the same as the OP. The differences here are in our implementations.

Fehguy posted this in response to the OP's question:

------------START POST-------------
Hi, that's possible. What server did you deploy? The java version or scala one? Or did you roll your own? There was a bug in our ApiOriginFilter which caused the allow orgin to not work.

I can tell you about your last question after you tell me what language/sample app you're working with.

Tony
-------------END POST---------------

I am getting the Access-Control-Allow-Origin problem myself, let me tell you about my setup.
Currently we have a PHP API hosted on one machine, and another machine hosting Swagger-Node-Express and a Swagger-UI. Since Swagger does not currently support auto documentation for PHP APIs, I have had to create my own doc template in javascript to be hosted from the node server. I used the node server's sample files as a template and modified them from there to create the Javascript files which are exported to .json. The Swagger-UI is hitting the node server, and all of my hard-coded API doc renders correctly into the UI. The problem happens when I try to use the "Try it now!" sandbox feature of the Swagger-UI. When looking at the errors through Firebug or Chrome, I get the Access-Control-Allow-Origin error on URLs that I can GET by simply copying and pasting it in another tab. Now, I understand one problem this may be solved is by making the API return headers to Allow Access Control, but I was wondering if there is any work around to this or if this is the only solution.

Access-Control-Allow-Origin

Hello,

I wonder where I have to deploy the UI in order to access the API. apparently I get an Access-Control-Allow-Origin because the ports are not the same but I would rather want to host the UI over the apache and run the api on another tomcat/jetty port. Is that possible?

Javascript:
XMLHttpRequest cannot load http://localhost:8081/slc/pet/resources.json. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

Also, is there any more documentation available? I can't quite figure out how the UI gets its information from the api, for example, where does this lead to:

swagger.api.basepath
http://localhost:8002/api

I mean, the UI asks for a resources.json file, but in the sample application I cannot find where path "/api" is defined and where a resources.json is returned.

Thanks for any help.
david

Add stylesheet in source (Sass?) format

I feel like src/main/html/css/screen.css is generated with Sass or something like that, as I doubt a human would write all of those insane "nested" (indented) rules with hyper-specific selectors.

Are we missing the source stylesheet?

OPTIONS method made for POST / PUT methods

Hi there,

I'm facing a strange problem I never had before with swagger: for all my POST/PUT method, swagger is making first an OPTIONS method, and then a POST/PUT one if Allowed.

I'm not really sure I want to implement OPTIONS method, which is extremely rare.

How to avoid this?

Thanks!

Build instructions

There don't seem to be any build instructions available.

I'm entirely new to haml and sass, and have no idea what other tools I might need to build this. A short build instruction would be awesome!

swagger-ui overhaul -- "?api_key=" always appended to operation URL

Even though no api_key is specified, the operation URL, will contain the api_key as a query parameter, such that the string "?api_key=" is appended at the end of the URL. This may not cause the operation to fail, but this is is somewhat misleading when viewing the request URL. Moreover, the master branch does not behave this way.

Roadmap

In this issue #4, an upcoming 1.1 release is mentioned, but that was 4 months ago. Is there any work in progress? Is there a list of features that should be built? From the top of my head:

  • Show more of the data in the resource description json in the UI
  • Show descriptions of the models in the UI
  • Allow non-GET requests from the UI

I'd like to help out, and I'm ready to fork and start making pull requests, but it would be a waste to duplicate work :)

Thanks,

Erik

cake dist fails in 1379f7ad1dddec6c73da9d94849ba5bc44fc97a9

I'm getting the following error trying to build

cake dist
Build distribution in ./dist

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
TypeError: Bad argument
    at Object.mkdirSync (fs.js:360:18)
    at Object.action (/Users/arulkumaran/git/swagger-ui/Cakefile:25:10)
    at /usr/lib/node_modules/coffee-script/lib/coffee-script/cake.js:42:26
    at Object.run (/usr/lib/node_modules/coffee-script/lib/coffee-script/cake.js:67:21)
    at Object.<anonymous> (/usr/lib/node_modules/coffee-script/bin/cake:7:38)
    at Module._compile (module.js:402:26)
    at Object..js (module.js:408:10)
    at Module.load (module.js:334:31)
    at Function._load (module.js:293:12)
    at Array.<anonymous> (module.js:421:10)

Nested parameters support

Is there any plan to support nested parameters like this ?

{
  "user": {
    "name" : "John",
    "type" : "guest"
  }
}

I am not really sure how it could be shown in the ui but it would a nice feature :)

naming schema

I have one more question about the naming conventions. I do not want to have ".json" or ".xml" in my URLs but when I delete it, the UI only shows "fetching..." but doesn't show the provided methods. For example,

@path("/pet.json")
@Api(value = "/pet", description = "Operations on a pet")
@singleton
@produces({"application/json"})

works, but

@path("/pet")
@Api(value = "/pet", description = "Operations on a pet")
@singleton
@produces({"application/json"})

does not work (only difference is the missing ".json" in the @path).

What are the conventions here? Can I somehow get rid of the ".json"?
Thanks a lot.

David

Allow pressing ENTER key to submit parameters

When entering a value for a parameter, and hitting ENTER, the whole page is submitted. It would be great if swagger-ui could catch the ENTER key pressed event, and submit the parameters for the relevant operation.

The default value for params is not respected

When you specify the default value for a param using the field defaultValue, the UI doesn't show the default value in the text field. Not only that, when you try the request, the default values are not sent in the request.

Patching in style

HTTP PATCH is naked with Swagger UI with out any style

Take a look at this picture to get a clear picture of what I mean

Patch No Skin

Ideally PATCH should get some color closer to PUT

Allow for a resource named 'resources'

I'm working on an API which has a resource at “/resources.json/...”, so I have a problem as Swagger by default expects to use “/resources.json” for its resource discovery URL. I changed the resource discovery URL for this API to “/apidoc.json” but found that Swagger-UI still wouldn't work. Through trial-and-error I found that the change linked to below is the most minimal find-replace-all of “resources” with [other string] I could do to make it work, though I honestly don't understand neither the code, nor JavaScript and CoffeeScript well enough to know why this fixes the problem or what a proper fix would be (since this one is a change on the generated, rather than the source files).

Yesplan@741858c

Redirect in Internet Explorer 9

I have recently written a lib called Swagger.Net to emit the spec for the new Asp.Net Web API.

There appears to be an issue with Swagger-UI in Internet Explorer that causes a redirect to the root of the site. Could be a bad route in Backbone?

I'd like to bundle up the Swagger UI as a NuGet pkg. Are there any plans to make Swagger UI work in IE for .NET community adoption?

Thanks!

Add printable stylesheet

Would be nice to have a stylesheet that enables nice printing of the UI.

This should have:

  • all UI controls (buttons, inputs) and "try it out" functionality hidden
  • all items expanded
  • header removed
  • page width constraints removed (fluid layout)

Looks like the existing stylesheet should be split out (since it's only for "screen" now) so relevant sections can be re-used for the printable version.

Need the ability to specify the inclusion of the format extensions.

When parsing the API documentation inclusion .{format} is required for the javascript to parse the JSON.

When calling the API from the web app it would be great if that could be optionally exluded.

For some reason the .json works locally with NGINX but Web Brick on Heroku chokes on it.

Boolean type handled as textarea

Right now, if you send a datatype boolean, it is rendered as a (multi-line) textarea, which is very unintuitive.

Expect that it would be rendered as eg: a drop-down with possible values true or false, or as a checkbox.

format option in UI

Having a option to select "json" or "xml" format in the UI would be nice to have

Separating the actual resource and api discovery

Currently swagger-ui demands that GET request on the resource root should provide the operation listing

I feel this is limiting, let me explain with the following scenario

/authors.json/{id} provides specific author's details. I want /authors.json to provide list of authors (using optional parameters to filter and do pagination) instead of the operation listing

While resources.json provides the resource listing

I want to use resources.json/authors to provide the operation listing

This way api discovery wont stand in the way of the resource. I tried it and found that it is not supported by the current version of swagger-ui.

I'm the author of the Restler API framework trying to add API Discovery features using Swagger UI. I love the ui design and functionality and willing to contribute to this project as well. Pointers and support are greatly appreciated :)

Parameters marked as type "header" are not place in the header.

I am trying to get a ruby project going with swagger - the API in question requires an API token be passed in the header.

In your examples you mark parameters as "header" but then it swagger-ui still places them in the query string - which only works for your API.

As a temp fix I am always making the token the first parameter and have make the following horrible, horrible hack to get things working; (in submitOperation of swagger-ui.js)

if (error_free) {
    var params = form.serializeArray();
    var token_name = params[0].name;
    var token_value = params[0].value;
    params.splice(0,1);
    var invocationUrl = this.operation.invocationUrl(params);
    $(".request_url", this.elementScope + "_content_sandbox_response").html(
        "<pre>" + invocationUrl + "</pre>"
    );
    $.ajax(
    {  url: invocationUrl,  dataType: 'json',  data: '{}',  success: this.showResponse, beforeSend: 
    function (xhr) {
                xhr.setRequestHeader(token_name, token_value);
            }

    }
    ).complete(this.showCompleteStatus).error(this.showErrorStatus);
}

Any thoughts on a permanent fix for this?

"build" folder not up-to-date w.r.t. "source" folder ?

The "build" folder seems to be older than the latest "source" folder. I think I need the "using basePath from the apis" change done by user "ayush" from about a month ago, while the "build" folder dates from about 2 months ago. Could you please update the "build" folder?

Nested resource discover

I've been trying to support a nested under a directory, like /test/testing.json. I have the discovery part at /test/test.json, which finds the resource discovery file no problem. It even lists /test/testing. But once you click on it, nothing seems to happen. If I move it back up to the root, it works without issue.

    {
      'apiVersion' => '0.2',
      'swaggerVersion' => '1.0',
      'basePath' => 'http://33.33.33.10:9292',
      'apis' => [
        {
          'path' => '/test/test.{format}',
          'description' => 'something about testing'
        }
      ]
    }

Replace the hardcoded {format} parameter with media type negotiation through an “Accept” header

Swagger seems to assume that resources have a URL with a {format} path parameter which can be “json” or “xml”, like “/pet.json/1” or “/pet.xml/1”. I'm still pretty new to REST API design, but from what I understand from reading the O'Reilly “REST API Design Rulebook" including such a format parameter in the URL isn't considered good REST design as it assigns two different URLs to what is really the same resource (but in two different representations). The relevant rule in the book is “Rule: File extensions should not be included in URIs” which appears on page 13. The author recommends that “REST API clients should be encouraged to utilize HTTP’s provided format selection mechanism, the Accept request header ... when multiple representations are available.”

Misplaced and missing files

The index.html file in src/main/html/ expects the lib/ directory to exist in src/main/html/ it is also looking there for swagger-ui.js, which I cannot find anywhere.

spec.html in src/test/ expects all the jasmine files to live in lib/ when, in fact, they live in bin/.

cake dist is failing on windows 7 - Error: Command failed: 'node_modules' is not recognized as an internal or external command, operable program or batch file.

Using
nodejs - v0.8.11
coffee-script - latest
cake - latest

C:\Arjun\projects\swagger-ui>cake dist
path.existsSync is now called fs.existsSync.
Build distribution in ./dist
: Reading src/main/coffeescript/SwaggerUi.coffee
: Reading src/main/coffeescript/view/HeaderView.coffee
: Reading src/main/coffeescript/view/MainView.coffee
: Reading src/main/coffeescript/view/ResourceView.coffee
: Reading src/main/coffeescript/view/OperationView.coffee
: Reading src/main/coffeescript/view/ParameterView.coffee
: Precompiling templates...
: Compiling src/main/template/main.handlebars
: Compiling src/main/template/operation.handlebars
: Compiling src/main/template/param.handlebars
: Compiling src/main/template/param_list.handlebars
: Compiling src/main/template/param_readonly.handlebars
: Compiling src/main/template/param_readonly_required.handlebars
: Compiling src/main/template/param_required.handlebars
: Compiling src/main/template/resource.handlebars

C:\Arjun\servicemesh\projects\swagger-ui\Cakefile:59
throw err;
^
Error: Command failed: 'node_modules' is not recognized as an internal or external command,
operable program or batch file.

at ChildProcess.exithandler (child_process.js:540:15)
at ChildProcess.EventEmitter.emit (events.js:96:17)
at maybeClose (child_process.js:638:16)
at Socket.ChildProcess.spawn.stdin (child_process.js:815:11)
at Socket.EventEmitter.emit (events.js:93:17)
at Socket._destroy.destroyed (net.js:357:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)

build/index.html breaks with "new build" commit

I pulled down the current version of swagger-ui to work with the newest version of swagger-core, and it appears to be broken since the "new build" commit (4ce5b8f). Once I hit that commit, I'm eternally stuck with a "Fetching API List...", whether exploring the live petstore, a locally-running petstore, or my own work.

In the console, I see "GET http://petstore.swagger.wordnik.com/resources 404 (Not Found)".

Failing in Safari and Chrome.

I know you are trying to support some alternative formats, but shouldn't this be backward compatible?

Model/object information as toggle at the bottom of implementation notes

For example in the pet store, a pet object can be posted in "post /pet.json". The Pet object is already defined as a model with property descriptions and this information is available in the resource JSON files.

It would be very nice to add a "View model/object description" link at the bottom of de implementation notes and above the parameters. If a user clicks the link, then he will see exactly how the pet object he wants to post must look like!

parameters don't work

It's that simple: in the new version the parameters of type 'query' don't work. Except only the ones that relate to 'auth' or 'api'?

Swagger API explorer only shows Content-Type header

I am returning a 'Range' header on the response. I see it in the response headers when inspecting the HTTP response, in addition to other auto generated headers, but it does not show in the Headers block in the UI. Not a huge deal, but since this is useful as documentation to a consumer, it would be nice to show it explicitly.

Add support for “multi” path parameters

I have an API with tree resources, which are handled by a single handler method in the implementation. The URL template for these resources is something like: (in RFC 6570 syntax)

/tree.{format}/{name}{/nodeid*}

So /tree.json/foo points to a JSON representation of the root node of the tree named “foo”, /tree.json/foo/4/2 points to the second child node of the fourth child node of the root node and so on. There doesn't seem to be a convenient way to describe these resources as a single API GET operation in Swagger. The Swagger specification implies that the “allowMultiple” attribute can only be used for query parameters, not for path parameters.

meta-characters in resources

there schould be a replace of meta-characters in all swagger-ui functions

If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, you must escape the character with two backslashes: .

ex:

toggleEndpointListForResource: function(resource) {
    var elem = $('li#resource_' + resource.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&") + ' ul.endpoints');
    if (elem.is(':visible')) {
        Docs.collapseEndpointListForResource(resource);
    } else {
        Docs.expandEndpointListForResource(resource);
    }
},

Alternative name to api_key

Our server doesn't have a concept like api key. Instead, since it uses sessions, it has a special kind of session. For example, while testing, developers can append "?sessionID=sessionDebug" to the URL for testing purposes, to avoid asking for a proper session (and that would imply logging in, etc.).
The existing api key feature does exactly this, except that it always creates a parameter name 'api_key'. It would be nice if we could explicity set what this parameter would be named.
Like the recently created "supportedSubmitMethods" parameter, there could be a new one called "apiKeyName" that could control the name of the URL parameter of the api key (it would default to "api_key")

top-level resources collide

When specifying sibling top-level resources (/resource1, /resource2), swagger-ui collapses all subsequent top-level resources into the UI container for the first:

The #! urls for both /user and /team in the screenshot are as follows:

I tried playing around with the path on the apis for each resource and they would collapse as long as there was an operation that was the same path as the top-level resource. If I changed the path in the operations file for the create (POST) for either user or team to even just append a slash (/) then the collapsing behavior disappeared.

EDIT: It isn't just any change that makes the problem go away. There has to be a slash to trigger it.

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.