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

Failed to use $ref reference to whole file #132

Open
yckimura opened this issue Mar 28, 2022 · 2 comments
Open

Failed to use $ref reference to whole file #132

yckimura opened this issue Mar 28, 2022 · 2 comments

Comments

@yckimura
Copy link
Contributor

yckimura commented Mar 28, 2022

When using $ref to reference to whole yaml file, NoMethodError is thrown.

RSpec example that can reproduce error: master...yckimura:ref-whole-file
Failed logs: https://github.com/yckimura/openapi_parser/runs/5725197901

openapi.yaml:

openapi: 3.0.0
info:
  version: 1.0.0
  title: OpenAPI3 Test
paths:
  /whole_local_file:
    post:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: schema-object.yaml
      responses:
        '200':
          description: correct

schema-object.yaml:

type: object
required:
  - name
properties:
  name:
    type: string
  tag:
    type: string

Stacktrace:

NoMethodError:
  undefined method `any_of' for #
# ./lib/openapi_parser/schema_validator.rb:98:in `validator'
# ./lib/openapi_parser/schema_validator.rb:74:in `validate_schema'
# ./lib/openapi_parser/schema_validator.rb:62:in `validate_data'
# ./lib/openapi_parser/schema_validator.rb:45:in `validate'
# ./lib/openapi_parser/schemas/media_type.rb:15:in `validate_parameter'
# ./lib/openapi_parser/schemas/request_body.rb:24:in `validate_request_body'
# ./lib/openapi_parser/schemas/operation.rb:25:in `validate_request_body'
# ./lib/openapi_parser/request_operation.rb:52:in `validate_request_body'
# ./spec/openapi_parser/concerns/findable_spec.rb:40:in `block (4 levels) in <top (required)>'
@kuboon
Copy link

kuboon commented Apr 14, 2022

I found that reference parser inherits owner's schema.

loader = ::OpenAPIParser::SchemaLoader.new(self, self.class._parser_core)

On this situation, schema-object.yaml should have paths components on top level. other props will be ignored.

@nerixim
Copy link

nerixim commented May 21, 2023

Basically it's a use case described in the OpenAPI docs so it'd be nice to have it 👍

paths:
  /users:
    $ref: '../resources/users.yaml'
  /users/{userId}:
    $ref: '../resources/users-by-id.yaml'

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