Coder Social home page Coder Social logo

swagui.jl's Introduction

Julia Swagger UI

codecov

Want to use Swagger UI in Julia? This package has your back!

Inspired by swagger-ui-express, the package auto-generates Swagger UI based on swagger.json. The generated API documentation can be served as an endpoint using package such as Genie.jl.

Pre-built swagger-ui is used. Because swagger-ui is implemented in Node.js, all pre-built files and assets are included in the dist folder for serving. (Open an issue if there are better ways to do this.)

Installation

julia> ]
pkg> add SwagUI

Usage

Genie simple setup

using Genie, Genie.Router
using JSON
using SwagUI

# use a swagger json from the local machine
swagger_document = JSON.parsefile("./swagger.json")

route("/docs") do 
    render_swagger(swagger_document)
end

Inegrate with Swagger Markdown

using Genie, Genie.Router
using JSON
using SwagUI
using SwaggerMarkdown

@swagger """
/doge:
  get:
    description: Doge to the moon!
    responses:
      '200':
        description: Doge to the moon!!.
"""
route("/doge") do 
    JSON.json("Doge to the moon!!")
end

# build a swagger document from markdown
info = Dict{String, Any}()
info["title"] = "Swagger Petstore"
info["version"] = "1.0.5"
openApi = OpenAPI("2.0", info)
swagger_document = build(openApi)

route("/docs") do 
    render_swagger(swagger_document)
end

up(8001, async = false)

SwaggerMarkdown builds the swagger document from markdown comments in the code. It returns a swagger_document::Dict{String, Any} that can be used by SwaggerUI.render_swagger to render the API documentation as Swagger's fashion.

Configuration & Customization

Swagger Explorer

The explorer can be turned off through setting the Options.show_explorer to false. It's turned on, i.e. Options.show_explorer = true by default.

using Genie, Genie.Router
using JSON
using SwagUI

swagger_document = JSON.parsefile("./swagger.json")

# turn off the explorer
options = Options()
options.show_explorer = false

route("/docs") do 
    render_swagger(swagger_document, options=options)
end

Custom swagger options

Swagger UI can be configured by setting Options.swagger_options::Dict{String, Any}. The key is the name of the configuration while the value is the setting. More details about configuration can be found through the Official Swagger UI Configuration page. The example below sets the URL pointing to API definition to https://petstore.swagger.io/v2/swagger.json.

using Genie, Genie.Router
using JSON
using SwagUI

# set the URL pointing to API definition
options = Options()
options.swagger_options["url"] = "https://petstore.swagger.io/v2/swagger.json"

route("/docs") do 
    # if swagger_options["url"] or swagger_options["urls"] is set,
    # swagger_document is not needed
    render_swagger(nothing, options=options)
end

Custom CSS

Set Options.custom_css to a custom CSS as String.

using Genie, Genie.Router
using JSON
using SwagUI

swagger_document = JSON.parsefile("./swagger.json")

# set custom css using options
options = Options()
options.custom_css = ".swagger-ui .topbar { display: none }"

route("/docs") do 
    render_swagger(swagger_document, options=options)
end

TODO

More examples

swagui.jl's People

Contributors

essenciary avatar expandingman avatar jiachengzz avatar

Stargazers

 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

Forkers

expandingman

swagui.jl's Issues

Join GenieFramework

Hi,

We're currently setting up a dev hub around Genie and various packages working on top of it. Making all these awesome libraries easy to find and creating a documentation section that integrates all the packages, with integrated API search.

Would you like to bring SwagUI into the GenieFramwork Github organisation and/or integrate it on GenieFramework.com?

Adrian

Hey I would like to contribute SwagUI

I have worked fulltime with expressjs and all things node. Also worked a bit with swagger express. I think will be contribute this package :)

What are your plans regarding new features and taking this forward? Can we do like zoom call or something on coming weekend? ๐Ÿ‘ฏโ€โ™‚๏ธ

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

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.