All Projects → icyleaf → swagger

icyleaf / swagger

Licence: MIT license
Swagger contains a OpenAPI / Swagger universal documentation generator and HTTP server handler.

Programming Languages

crystal
512 projects
HTML
75241 projects

Projects that are alternatives of or similar to swagger

cakephp-swagger-bake
Automatically generate OpenAPI, Swagger, and Redoc documentation from your existing CakePHP code.
Stars: ✭ 48 (+33.33%)
Mutual labels:  swagger-documentation
spring-boot-jwt-auth
🔑 Sample Spring boot application secured using JWT auth in custom header(X-Auth-Token).
Stars: ✭ 57 (+58.33%)
Mutual labels:  swagger-documentation
go-swagger-merger
Tool for merging multiple YAML swagger files into one
Stars: ✭ 15 (-58.33%)
Mutual labels:  swagger-generator
spring-boot-template
Template for Spring Boot applications
Stars: ✭ 59 (+63.89%)
Mutual labels:  swagger-documentation
travels-java-api
An API for travel management. It is built with Java, Spring Boot, and Spring Framework. A toy-project to serve as a theoretical basis for the Medium series of articles I wrote about Java+Spring.
Stars: ✭ 139 (+286.11%)
Mutual labels:  swagger-documentation
swagger-spec-compatibility
Python library to check Swagger Spec backward compatibility
Stars: ✭ 16 (-55.56%)
Mutual labels:  swagger-documentation

Swagger

Language Tag Source Document Build Status

Swagger is a low-level library which generates a document compatible with Swagger / OpenAPI Spec 3.0.3, and wrapped many friendly APIs let developer understand and use it easier.

Installation

dependencies:
  swagger:
    github: icyleaf/swagger

Quick look

require "swagger"

builder = Swagger::Builder.new(
  title: "App API",
  version: "1.0.0",
  description: "This is a sample api for users",
  terms_url: "http://yourapp.com/terms",
  contact: Swagger::Contact.new("icyleaf", "[email protected]", "http://icyleaf.com"),
  license: Swagger::License.new("MIT", "https://github.com/icyleaf/swagger/blob/master/LICENSE"),
  authorizations: [
    Swagger::Authorization.jwt(description: "Use JWT Auth"),
  ]
)

builder.add(Swagger::Controller.new("Users", "User resources", [
  Swagger::Action.new("get", "/users", description: "All users", responses: [
    Swagger::Response.new("200", "Success response")
  ]),
  Swagger::Action.new("get", "/users/{id}", description: "Get user by id", parameters: [
    Swagger::Parameter.new("id", "path")
  ], responses: [
    Swagger::Response.new("200", "Success response"),
    Swagger::Response.new("404", "Not found user")
  ], authorization: true),
  Swagger::Action.new("post", "/users", description: "Create User", responses: [
    Swagger::Response.new("201", "Return user resource after created"),
    Swagger::Response.new("401", "Unauthorizated")
  ], authorization: false)
]))

document = builder.built
puts document.to_json

Structure

Structure in src directory:

.
├── xxx.cr                        # Friendly APIs
├── http                          # HTTP assets and libraries
└── objects                       # OpenAPI objects

Running on web

Swagger provids a built-in web server, if you have no idea how to preview it:

require "swagger"
require "swagger/http/server"

# made your document (See `builder` code example above)
document = builder.built

# Run web server
Swagger::HTTP::Server.run(document)

Integrating

Swagger has two HTTP handlers which you can integrate it to bult-in HTTP Server and mostly frameworks (like kemal, amber, lucky etc):

  • Swagger::HTTP::APIHandler
  • Swagger::HTTP::WebHandler

Examples

See more examples.

Todo

  • openapi
  • Info Object
  • Paths Object
    • PathItem Object
      • Parameter Object
      • RequestBody Object
      • Responses Object
      • Security Object
      • Tag Object
  • Tags Object
  • Servers Objec
    • ServerVariables Object
  • Security Object
  • Components Object
    • Schemas Object
    • SecuritySchemes Object
      • Basic
      • Bearer (include JWT)
      • APIKey
      • OAuth2
  • ExternalDocs Object

How to Contribute

Your contributions are always welcome! Please submit a pull request or create an issue to add a new question, bug or feature to the list.

Here is a throughput graph of the repository for the last few weeks:

All Contributors are on the wall.

You may also like

  • halite - HTTP Requests Client with a chainable REST API, built-in sessions and middlewares.
  • totem - Load and parse a configuration file or string in JSON, YAML, dotenv formats.
  • markd - Yet another markdown parser built for speed, Compliant to CommonMark specification.
  • poncho - A .env parser/loader improved for performance.
  • popcorn - Easy and Safe casting from one type to another.
  • fast-crystal - 💨 Writing Fast Crystal 😍 -- Collect Common Crystal idioms.

License

MIT License © icyleaf

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].