All Projects → braintree → Open_api_parser

braintree / Open_api_parser

Licence: mit
A parser for Open API specifications

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Open api parser

serverless-rack
Serverless plugin to deploy Ruby Rack applications (Sinatra/Rails/Padrino/Cuba etc.) and bundle gems
Stars: ✭ 58 (+93.33%)
Mutual labels:  rack
Client ruby
Prometheus instrumentation library for Ruby applications
Stars: ✭ 369 (+1130%)
Mutual labels:  rack
Rack Tracker
Tracking made easy: Don’t fool around with adding tracking and analytics partials to your app and concentrate on the things that matter.
Stars: ✭ 601 (+1903.33%)
Mutual labels:  rack
panda
🐼 Panda is an mvc web application framework built with Ruby.
Stars: ✭ 12 (-60%)
Mutual labels:  rack
Lamby
Simple Rails & AWS Lambda Integration 🐑🛤
Stars: ✭ 336 (+1020%)
Mutual labels:  rack
Rack App
minimalist framework for building rack applications
Stars: ✭ 389 (+1196.67%)
Mutual labels:  rack
rack-ratelimit
Flexible rate limiting for your Rack apps
Stars: ✭ 111 (+270%)
Mutual labels:  rack
Rack Throttle
Rack middleware for rate-limiting incoming HTTP requests.
Stars: ✭ 898 (+2893.33%)
Mutual labels:  rack
Rack Dev Mark
Show dev mark on development env
Stars: ✭ 350 (+1066.67%)
Mutual labels:  rack
Rack Attack
Rack middleware for blocking & throttling
Stars: ✭ 5,012 (+16606.67%)
Mutual labels:  rack
Shrine
File Attachment toolkit for Ruby applications
Stars: ✭ 2,903 (+9576.67%)
Mutual labels:  rack
Stubb
Specify REST API stubs using your file system.
Stars: ✭ 289 (+863.33%)
Mutual labels:  rack
Async sinatra
A plugin for Sinatra to provide a DSL extension for using Thin for asynchronous responses
Stars: ✭ 434 (+1346.67%)
Mutual labels:  rack
rack-fluentd-logger
Rack middleware to send traffic logs to Fluentd
Stars: ✭ 21 (-30%)
Mutual labels:  rack
Agoo
A High Performance HTTP Server for Ruby
Stars: ✭ 679 (+2163.33%)
Mutual labels:  rack
yatpl
Yet Another Template Engine 🚀
Stars: ✭ 14 (-53.33%)
Mutual labels:  rack
Raxx
Interface for HTTP webservers, frameworks and clients
Stars: ✭ 378 (+1160%)
Mutual labels:  rack
Puma
A Ruby/Rack web server built for parallelism
Stars: ✭ 6,924 (+22980%)
Mutual labels:  rack
Iodine
iodine - HTTP / WebSockets Server for Ruby with Pub/Sub support
Stars: ✭ 720 (+2300%)
Mutual labels:  rack
Rack
A modular Ruby web server interface.
Stars: ✭ 4,260 (+14100%)
Mutual labels:  rack

OpenApiParser

Build Status

A gem for parsing Open API specifications.

Usage

First, resolve a specification given an absolute file path.

specification = OpenApiParser::Specification.resolve("/path/to/my/specification.yaml")

When you resolve your file, all references will be expanded and inlined. The fully resolved specification will be validated against the Open API V2 meta schema. If you'd like to prevent meta schema validation, you can provide an option to do so.

specification = OpenApiParser::Specification.resolve("/path/to/my/specification.yaml", validate_meta_schema: false)

If you'd rather instantiate a specification with a fully resolved ruby hash, you can do so by directly instantiating an OpenApiParser::Specification::Root.

OpenApiParser::Specification::Root.new({...})

Reference resolution

OpenApiParser::Specification.resolve will fully resolve the provided Open API specification by inlining all JSON References. Two types of references are allowed:

Pointers are resolved from the root of the document in which they appear. File references are resolved relative to the file in which they appear. Here's an example of each:

definitions:
  person:
    type: object
    properties:
      name:
        type: string
      age:
        type: integer

info:
  person:
    $ref: "/definitions/person"
  other:
    $ref: "file:another/file.yaml"

For more information, see the specs.

Endpoints

With a resolved schema, you can access the information for an endpoint given a path and an HTTP verb.

endpoint = specification.endpoint("/animals", "post")

With an endpoint, you can get access to JSON schema representations of the body, headers, path, query params and response body and headers defined in your Open API specification. You can use these to validate input using any existing JSON Schema library. We recommend JsonSchema.

endpoint.body_schema
# => {...}

endpoint.header_schema
# => {...}

endpoint.path_schema
# => {...}

endpoint.query_schema
# => {...}

endpoint.response_body_schema(201)
# => {...}

endpoint.response_header_schema(201)
# => {...}

You can also use the endpoint to transform user input into json that can be validated against the schemas generated in the previous examples.

endpoint.header_json(request_headers_as_hash)
# => {...}

endpoint.path_json("/animals/123?query=param")
# => {...}

endpoint.query_json(request_query_params_as_hash)
# => {...}

For more information, see the specs.

Installation

Add this line to your application's Gemfile:

gem 'open_api_parser'

And then execute:

$ bundle

Or install it yourself as:

$ gem install open_api_parser
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].