Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError thrown when $ref path cant be resolved #29

Closed
aaroncouture opened this issue Apr 26, 2019 · 5 comments
Closed

NoMethodError thrown when $ref path cant be resolved #29

aaroncouture opened this issue Apr 26, 2019 · 5 comments

Comments

@aaroncouture
Copy link

aaroncouture commented Apr 26, 2019

When referencing a ref path that cannot be resolved the following error is thrown:

#<NoMethodError: undefined method `any_of' for #OpenAPIParser::Schemas::Reference:0x000055bceb4393f8>

This error should be translated to something that better indicates the root cause.

This is a pretty minor problem since the schema should be validated against OpenApi specs to begin with.

Sample YAML file:

openapi: 3.0.0
paths:
  /api/v1/events:
    get:
      parameters:
        - in: query
          name: start_time
          description: start time
          required: true
          schema:
            $ref: "#/components/schemas/time"
@ota42y
Copy link
Owner

ota42y commented May 14, 2019

Ok, I will try to validate the OpenAPI definition itself
(Because other definition errors are similarly prevented)

@makdad
Copy link
Contributor

makdad commented Oct 18, 2021

@ota42y I had this problem again. I think if we are validating, and there is a OpenAPIParser::Schemas::Reference object, it means that the reference could not be resolved, and thus maybe a simple raise with the name of the reference would help OAS3 authors find out where their "spec bug" is. I can contribute a PR on this topic if you're favorable to work in that direction.

Something like:

def validator(value, schema)
return any_of_validator if schema.any_of
return all_of_validator if schema.all_of
return one_of_validator if schema.one_of
return nil_validator if value.nil?

    def validator(value, schema)
      raise "#{schema} could not be resolved for validation" unless schema.respond_to(:any_of)

      return any_of_validator if schema.any_of
      return all_of_validator if schema.all_of

I don't think that's the most elegant solution, but effectively something like it.

@ota42y
Copy link
Owner

ota42y commented Nov 27, 2021

Thanks to feedback!!

I think we can find this error when we load the schema, so instead of raising an exception at runtime, raising an exception on loading phease like this line.

obj = root.find_object(reference.ref)

@makdad
Copy link
Contributor

makdad commented Dec 8, 2021

@ota42y I have changed my PR from a draft PR. Please confirm if it's acceptable for you 👍

ota42y added a commit that referenced this issue Dec 15, 2021
Add `strict_reference_validation` config and implementation to address/implement #29
@ota42y
Copy link
Owner

ota42y commented Dec 15, 2021

We have released a version with a fix for this issue! ( Thanks @makdad !!!)
https://rubygems.org/gems/openapi_parser/versions/1.0.0.beta1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants