All Projects → swagger-rb → swagger-rb

swagger-rb / swagger-rb

Licence: MIT license
Swagger parser for Ruby (WARNING: see issue #19)

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to swagger-rb

apitest
this is a tool for testing Laravel REST API
Stars: ✭ 11 (-71.05%)
Mutual labels:  api-documentation
restdocs-spec
A maven plugin for generating Open API and Postman Collection specifications using Spring Restdocs.
Stars: ✭ 43 (+13.16%)
Mutual labels:  api-documentation
flixel-docs
Documentation for HaxeFlixel
Stars: ✭ 59 (+55.26%)
Mutual labels:  api-documentation
liuye
柳叶清单开放 API 文档
Stars: ✭ 32 (-15.79%)
Mutual labels:  api-documentation
csharp-docs-generator
An action that generates html documentation for C# programs to use for GitHub pages.
Stars: ✭ 21 (-44.74%)
Mutual labels:  api-documentation
sails-hook-swagger-generator
A tool to help generate Swagger specification documentation based on OAS 3.0 for Sails APIs
Stars: ✭ 71 (+86.84%)
Mutual labels:  swagger-specification
apidox
Generate node.js module API markdown with dox
Stars: ✭ 14 (-63.16%)
Mutual labels:  api-documentation
ad integration
Documentação para a Importação de Anúncios (API, JSON e XML) da OLX Brasil
Stars: ✭ 36 (-5.26%)
Mutual labels:  api-documentation
protean
Evolve your RESTful API's and Web Services
Stars: ✭ 31 (-18.42%)
Mutual labels:  api-documentation
trade-opskins-api
API docs for trade.opskins.com
Stars: ✭ 44 (+15.79%)
Mutual labels:  api-documentation
apiguardian
@API Guardian
Stars: ✭ 153 (+302.63%)
Mutual labels:  api-documentation
PlayStation-Trophies
Sony has an API for retrieving details of the trophies an account has earned, but there is no public documentation for using it. This is an attempt at documenting the API by capturing the requests made by the https://my.playstation.com web site.
Stars: ✭ 62 (+63.16%)
Mutual labels:  api-documentation
API-Portal
API Portal lets you create and publish a customized site with API documentation, for free and without writing any code.
Stars: ✭ 162 (+326.32%)
Mutual labels:  api-documentation
MDSL-Specification
A domain-specific language to specify (micro-)service contracts, data representations and endpoints.
Stars: ✭ 35 (-7.89%)
Mutual labels:  api-documentation
nei-toolkit
NEI 接口文档管理平台配套自动化工具
Stars: ✭ 814 (+2042.11%)
Mutual labels:  api-documentation
openapi-viewer
Browse and test a REST API described with the OpenAPI 3.0 Specification
Stars: ✭ 85 (+123.68%)
Mutual labels:  api-documentation
mattermost-api-reference
Mattermost API reference documentation.
Stars: ✭ 74 (+94.74%)
Mutual labels:  api-documentation
chappe
🧑‍💻 Developer Docs builder. Write guides in Markdown and references in API Blueprint. Comes with a built-in search engine.
Stars: ✭ 132 (+247.37%)
Mutual labels:  api-documentation
platform
Apinf - Open source API management platform with multi proxy and protocol support
Stars: ✭ 69 (+81.58%)
Mutual labels:  api-documentation
go-slate
A CLI tool to generate API documentation using Slate layout by Robert Lord
Stars: ✭ 19 (-50%)
Mutual labels:  api-documentation

Swagger

Swagger is a Ruby library for parsing, building, and traversing Swagger API definitions.

WARNING

- WARNING: Swagger is currently locked to an old verison of Hashie.
- If you use this gem you may run into version compatiblity issues. Help is needed to resolve the issue (#19).

Installation

NOTE: The gem is named swagger-core, because swagger was taken by an unrelated project.

Add this line to your application's Gemfile:

gem 'swagger-core'

And then execute:

$ bundle

Or install it yourself as:

$ gem install swagger-core

Features

  • Structural and semantic validation of Swagger objects
  • Convenient traversal APIs: use hierarchical or flat traversals
  • Handles derived or combined properties, like joining root, path, and operation level property definitions
  • A Swagger::Builder to help create valid Swagger documents from other data

Usage

Parsing

If you're loading a Swagger document from a file, you can use #load. The Swagger version will be detected from the file content.

api = Swagger.load('swagger.yaml')

If you already have the Swagger content loaded as a Hash you can call build, or you can call build and tell Swagger the content is a JSON or YAML string it needs to parse.

api = Swagger.build(hash)
# or
api = Swagger.build(json, format: :json)
# or
api = Swagger.build(yaml, format: :yaml)

Traversing

The parsing methods above all return an API object. The object has a hierarchical object that mirrors the Swagger specification. You can traverse it hierarchically, for example:

api.paths['/pets'].get
# {"tags"=>["Pet Operations"],
# "summary"=>"finds pets in the system",
# "responses"=>
  {"200"=>{"description"=>"pet response", "schema"=>{"type"=>"array", "items"=>{"$ref"=>"#/definitions/Pet"}}, "headers"=>[{"x-expires"=>{"type"=>"string"}}]},
   "default"=>{"description"=>"unexpected error", "schema"=>{"$ref"=>"#/definitions/Error"}}}}

There are also methods available to provide flatter APIs or convenient derived properties. For example:

api.operations.each do | operation |
  puts operation.signature
end
# GET petstore.swagger.wordnik.com/api/pets
# POST petstore.swagger.wordnik.com/api/pets
# GET petstore.swagger.wordnik.com/api/pets/{id}
# DELETE petstore.swagger.wordnik.com/api/pets/{id}

See the RDoc documentation for more details.

Building

If you want to build a Swagger document from another structure, you can use the builder. It will validate the structure and data types as you build the Swagger document, but it won't enforce constraints about required Swagger fields until you call Swagger::Builder#build.

builder = Swagger.builder
# or builder = Swagger.builder(version: '2.0')

builder.swagger = 2.0
builder.info do |info|
  info.title = 'Sample Swagger API'
  info.version = '1.0'
end
builder.paths = {
  '/foo' => {}
}
builder.paths['/foo'].get do |get|
  get.description = 'Testing...'
  get.tags = %w(foo bar)
end

api = builder.build

TODO

  • Support Swagger 1.2 - right now only Swagger 2.0 is supported
  • Better handling of $ref
  • Handle combined parameters, respones, etc

Contributing

  1. Fork it ( https://github.com/[my-github-username]/swagger/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
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].