Giter Site home page Giter Site logo

oas_parser's Introduction

⚠️ This repository is no longer maintained.


Open API Definition Parser

Nexmo is now known as Vonage

A Ruby parser for Open API Spec 3.0+ definitions.

Install

Install the gem:

$ gem install oas_parser

Or add it to your Gemfile:

gem 'oas_parser'

Usage

Here is a basic example of how you can traverse through an Open API Spec 3 Definition:

require 'oas_parser'

definition = OasParser::Definition.resolve('petstore.yml')
# => #<OasParser::Definition>

# Get a specific path
path = definition.path_by_path('/pets')
# => #<OasParser::Path>

# Get all paths.
definition.paths
# => [#<OasParser::Path>, ...]

# Get a specific endpoint by method
endpoint = path.endpoint_by_method('get')
# => #<OasParser::Endpoint>

# Get all endpoints
path.endpoints
# => [#<OasParser::Endpoint>, ...]

# Get endpoint description
endpoint.description
# => "Returns all pets from the system that the user has access to"

Checkout the tests and lib directory for more classes and methods.

Development

Run tests:

$ rspec

Publishing

Clone the repo and navigate to its directory:

$ cd oas-parser

Bump the latest version in oas_parser/lib/oas_parser/version.rb:

//old
module OasParser
  VERSION = '1.0.0'.freeze
end

//new
module OasParser
  VERSION = '1.1.0'.freeze
end

Build the gem:

$ gem build oas_parser.gemspec

This will create a oas_parser-1.1.0.gem file.

Push the gem to rubygems.org:

$ gem push oas_parser-1.1.0.gem

Verify the change was made by checking for the new version on rubygems.org

Contributing

Contributions are welcome, please follow GitHub Flow

oas_parser's People

Contributors

adambutler avatar ahx avatar chrisguzman avatar dependabot[bot] avatar dragonmantank avatar fabianrbz avatar j-a-m-l avatar kfalconer avatar lornajane avatar mheap avatar noma4i avatar ota42y avatar pardel avatar piao-mdsol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oas_parser's Issues

Return nil or custom error when an object cannot be found

Currently oas_parser raises a StandardError when an object cannot be found:

OasParser::Definition#path_by_path('/an_unknown_path')
# => StandardError: So such path exists

This make it a bit hard to use oas_parser if you want to react in a certain way if an object (path, method, status code) could not be found in the spec.

I think this could be improved by either

  1. Return nil if an object cannot be found
    or
  2. Raise a custom error like OasParser::NotFound, OasParser::PathNotFound, OasParser::CodeNotFound or the like

That way consuming apps could easily react on it in a controlled way.

What do you think? – 1 , 2 or 3 (leave it like it is)

Response schema does not support strings

In an OpenAPI spec, none of the fields in a response is required. This parser requires that within a response, the schema key is required and within that schema key the type can only be "array" or "object" - where as many other types are supported.

Example of what I wanted to write:

      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type:  string
              example: "success"

This is valid in OpenAPI spec but causes this parser to error. It should also be possible to omit the schema tag completely.

problem parsing azure netapp swagger circular reference

When parsing https://github.com/Azure/azure-rest-api-specs/blob/main/specification/netapp/resource-manager/Microsoft.NetApp/stable/2022-11-01/netapp.json I get
Error: key not found: "ErrorDetail"
backtrace:

/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/pointer.rb:11:in `fetch'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/pointer.rb:11:in `block in resolve'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/pointer.rb:10:in `each'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/pointer.rb:10:in `reduce'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/pointer.rb:10:in `resolve'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:68:in `expand_pointer'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:41:in `expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:20:in `deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:24:in `block in deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `each'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `reduce'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:24:in `block in deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `each'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `reduce'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:24:in `block in deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `each'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `reduce'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:24:in `block in deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `each'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `reduce'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:24:in `block in deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `each'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `reduce'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:24:in `block in deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `each'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `reduce'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:24:in `block in deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `each'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `reduce'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:24:in `block in deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `each'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `reduce'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:24:in `block in deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `each'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `reduce'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:24:in `block in deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `each'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `reduce'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:24:in `block in deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `each'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `reduce'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:23:in `deeply_expand_refs'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:14:in `resolve'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/parser.rb:5:in `resolve'
/Users/marioruizsanchez/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/oas_parser-0.25.4/lib/oas_parser/definition.rb:12:in `resolve'

Parsing the "components" section

I dont think there is support currently for parsing the components section of an OAS file. I'm particularly interested in the schemas part of that, and securitySchemes. Is being able to parse that something you would like to see supported in this library?

Support integer status codes in responses

Currently, this parser requires the response elements to be in quotes: '200':. OpenAPI supports them just being numbers: 200: but this fails because to check if it's a success case we match a specific pattern in the string.

We should support numbers as keys in the responses section of an OpenAPI spec.

To test: remove the quotes around any OAS

Dependency conflict with Sinatra (Mustermann)

I have a bit of an issue.

Trying to resolve https://security.snyk.io/vuln/SNYK-RUBY-SINATRA-3150405, however I cannot update Sinatra because oas_parser is still using mustermann 1.x.

Bundler could not find compatible versions for gem "mustermann":
  In snapshot (Gemfile.lock):
    mustermann (= 1.1.1)

  In Gemfile:
    oas_parser (= 0.25.4) was resolved to 0.25.4, which depends on
      mustermann-contrib (~> 1.1.1) was resolved to 1.1.1, which depends on
        mustermann (= 1.1.1)

    sinatra (~> 2.2.3) was resolved to 2.2.3, which depends on
      mustermann (~> 2.0)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

Would it be possible to update oas_parser to use mustermann 2.x?

example: 0755 returns example: 493 when parsing

if we have a swagger with this:
unixPermissions: title: unixPermissions type: string description: >- blabla example: 0755
when parsing we get:
"unixPermissions"=>{"title"=>"unixPermissions", "type"=>"string", "description"=>"blabla", "example"=>493}

Publish the API?

Would it be possible to publish a set of generated API docs, so the full API can be seen?

Alternatively listing each of the major elements of OAS and what properties of each are supported would be very helpful :-)

Parsing `allOf` for XML and JSON

If you look at niResponseXmlStandard in '#/components/schemas', you can see that it uses allOf to include the responses to niResponseXmlBasic and then add additional fields:

    niResponseXmlStandard:
      type: object
      description: 'Standard'
      xml:
        name: lookup
      allOf:
        - $ref: '#/components/schemas/niResponseXmlBasic'
        - properties:
            request_price:
              type: number
              description: 'If there is an internal lookup error, the `refund_price` will reflect the lookup price. If `cnam` is requested for a non-US number the `refund_price` will reflect the `cnam` price. If both of these conditions occur, `refund_price` is the sum of the lookup price and `cnam` price.'
              example: '0.01500000'
            remaining_balance:
              type: number
              description: 'Your account balance in EUR after this request. Not returned with Number Insight Advanced Async API.'
              example: '1.23456789'

I’m trying to do the same with niResponseJsonStandard, but it won't render properly (or at all), breaking both XML and JSON versions:

screen shot 2018-10-12 at 13 02 35

Is json_schema actually a dependency?

I see that json_schema is specified as a dependency in the Gemspec and required in lib/oas_parser.rb, but I don't see it used anywhere in the codebase. Is this dependency actually required or could we drop it?

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.