All Projects → zuzannast → Swagger_ui_engine

zuzannast / Swagger_ui_engine

Licence: mit
Include swagger-ui as rails engine and document your API with simple JSON or YAML files.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Swagger ui engine

Aspnetcore Webapi Course
Professional REST API design with ASP.NET Core 3.1 WebAPI
Stars: ✭ 323 (+319.48%)
Mutual labels:  swagger, swagger-ui
Swagger Ui Themes
💥 A collection of css themes to spice up your Swagger docs
Stars: ✭ 470 (+510.39%)
Mutual labels:  swagger, swagger-ui
Rapidoc
RapiDoc - Custom-Element for OpenAPI Spec
Stars: ✭ 444 (+476.62%)
Mutual labels:  swagger, swagger-ui
echoswagger
Swagger UI generator for Echo framework
Stars: ✭ 34 (-55.84%)
Mutual labels:  swagger, swagger-ui
Spring Boot Elasticsearch Lire Docker
Spring-boot+ElasticSearch+LIRE+SwaggerUI RESTful.
Stars: ✭ 7 (-90.91%)
Mutual labels:  swagger, swagger-ui
Swaggerlume
Lumen swagger
Stars: ✭ 277 (+259.74%)
Mutual labels:  swagger, swagger-ui
Springdoc Openapi
Library for OpenAPI 3 with spring-boot
Stars: ✭ 1,113 (+1345.45%)
Mutual labels:  swagger, swagger-ui
Swagger Bootstrap Ui
Swagger-bootstrap-ui is the Swagger front-end UI implementation, the purpose is to replace the Swagger default UI implementation Swagger-UI, make the document more friendly....
Stars: ✭ 2,816 (+3557.14%)
Mutual labels:  swagger, swagger-ui
Spark Swagger
Spark (http://sparkjava.com/) support for Swagger (https://swagger.io/)
Stars: ✭ 25 (-67.53%)
Mutual labels:  swagger, swagger-ui
Go Book Store Api
Go Sample project to understand Mysql CRUD operation with best practises Includes logging, JWT, Swagger and Transactions
Stars: ✭ 18 (-76.62%)
Mutual labels:  swagger, swagger-ui
guias-de-rails-espanol
Guías de Rails en Español (Rails 5) Estas son las guías de Rails 5 en Español (Guías Completas, con todos los Capítulos). Estas guías están diseñadas para que tengas una productividad inmediata con Rails, y para ayudarte a entender como encajan las piezas en Rails.
Stars: ✭ 42 (-45.45%)
Mutual labels:  rails-engine, rails5
Fastapi
FastAPI framework, high performance, easy to learn, fast to code, ready for production
Stars: ✭ 39,588 (+51312.99%)
Mutual labels:  swagger, swagger-ui
Flasgger
Easy OpenAPI specs and Swagger UI for your Flask API
Stars: ✭ 2,825 (+3568.83%)
Mutual labels:  swagger, swagger-ui
Dorado
基于Netty4开发的简单、轻量级、高性能的的Http restful api server
Stars: ✭ 65 (-15.58%)
Mutual labels:  swagger, swagger-ui
Hexo Theme Doc
A documentation theme for the Hexo blog framework
Stars: ✭ 222 (+188.31%)
Mutual labels:  swagger, swagger-ui
Swagger Ui
Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
Stars: ✭ 21,279 (+27535.06%)
Mutual labels:  swagger, swagger-ui
Swagger Toolbox
💡 Swagger schema model (in yaml, json) generator from json data
Stars: ✭ 194 (+151.95%)
Mutual labels:  swagger, swagger-ui
Gradle Swagger Generator Plugin
Gradle plugin for OpenAPI YAML validation, code generation and API document publishing
Stars: ✭ 197 (+155.84%)
Mutual labels:  swagger, swagger-ui
Django Ninja
💨 Fast, Async-ready, Openapi, type hints based framework for building APIs
Stars: ✭ 875 (+1036.36%)
Mutual labels:  swagger, swagger-ui
Swagger Editor
Swagger Editor
Stars: ✭ 7,365 (+9464.94%)
Mutual labels:  swagger, swagger-ui

SwaggerUiEngine

Include swagger-ui as Rails engine and document your API with simple YAML files.

Gem Version Build Status Code Climate

Versions

Swagger UI version Rails version
2.2.10 >= 4.2, <6

Features

  • Supports API documentation versioning / multiple APIs documentation
  • Easily configurable Swagger interface and OAuth2 authorization
  • Enables using Swagger interface translations
  • Works with API-only applications
  • Simple, clear and actively maintained 🙆

Problem

Working on a Rails API, I've wanted to document my endpoints in the clearest and easiest way possible. My goal was to have the documentation separated from the actual codebase and to have a web UI version of Swagger for testing and reading it. Using Rails 5 default API, I didn't need to include Grape, so I took a look into some other existing solutions. Most of them were no longer supported (e.g. swagger_engine and swagger-ui_rails) or required adding some extra code for the actual documentation (e.g. swagger-docs). Also, none of them supported Swagger web UI configuration, so I decided to write and maintain a gem on my own that would allow others to include Swagger web UI as Rails engine and support writing simple documentation in YAML files.

Installation

Add to Gemfile

gem 'swagger_ui_engine'

And then run:

$ bundle

Usage

Mount

Add to your config/routes.rb

mount SwaggerUiEngine::Engine, at: "/api_docs"

You can place this route under admin_constraint or other restricted path, or configure basic HTTP authentication.

Devise auth

authenticate :user, lambda { |u| u.admin? } do
  mount SwaggerUiEngine::Engine, at: "/api_docs"
end

Basic HTTP auth

Set admin username and password in an initializer:

# config/initializers/swagger_ui_engine.rb

SwaggerUiEngine.configure do |config|
  config.admin_username = ENV['ADMIN_USERNAME']
  config.admin_password = ENV['ADMIN_PASSWORD']
end

Initialize

Versioned API documentations

Set the path of your json/yaml versioned documentations in an initializer:

# config/initializers/swagger_ui_engine.rb

SwaggerUiEngine.configure do |config|
  config.swagger_url = {
    v1: 'api/v1/swagger.yaml',
    v2: 'api/v2/swagger.yaml',
  }
end

and place your main documentation file under /public/api path.

Single API documentation

NOTE: This is a compatibility patch for the SwaggerUiEngine gem versions <= 0.0.5. It's recommended to version your API documentation from the beginning.

You can define your main documentation url in a hash value (same way as in the versioned documentations) or pass single string with the url:

# config/initializers/swagger_ui_engine.rb

SwaggerUiEngine.configure do |config|
  config.swagger_url = 'api/swagger.yaml'
end

Configure

Config Name Swagger parameter name Description
config.swagger_url url The url pointing swagger.yaml (Swagger 2.0) as per OpenAPI Spec. Accepts a Hash, with API version names as keys and documentation URLs as values. Also accepts a String pointing to documentation for all versions.
config.doc_expansion 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).
config.model_rendering defaultModelRendering Controls how models are shown when the API is first rendered. It can be set to 'model' or 'schema', and the default is 'schema'.
config.request_headers showRequestHeaders Whether or not to show the headers that were sent when making a request via the 'Try it out!' option. Defaults to false.
config.json_editor jsonEditor Enables a graphical view for editing complex bodies. Defaults to false.
config.translator_enabled translations Enables Swagger Ui translations. Defaults to false.
config.validator_enabled validatorUrl Enables documentation validator. Defaults to false (validatorUrl: 'null').

OAuth2 configuration

You can configure OAuth2 default authorization.

Config Name Swagger parameter name Description
config.oauth_client_id client_id Default clientId. MUST be a string
config.oauth_client_secret client_secret Default clientSecret. MUST be a string
config.oauth_realm realm realm query parameter (for oauth1) added to authorizationUrl and tokenUrl . MUST be a string
config.oauth_app_name appName application name, displayed in authorization popup. MUST be a string
config.oauth_scope_separator scopeSeparator scope separator for passing scopes, encoded before calling, default value is a space (encoded value %20). MUST be a string
config.oauth_query_string_params additionalQueryStringParams Additional query parameters added to authorizationUrl and tokenUrl. MUST be an object

Edit your json/yaml files

You can use Swagger editor to write and validate your Swagger docs.

Example app

Here's an example use of SwaggerUiEngine in Rails application.

Contributing

You're very much welcome to contribute to this repository. Start by creating a Github issue and describing your change thoroughly. If you decide to publish a pull request, please make sure it points to the latest versioned branch instead of master.

License

This project is available under MIT-LICENSE. ☀️

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].