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

Specmatic Not resolving $ref examples. #1263

Closed
barath121 opened this issue Aug 28, 2024 · 3 comments
Closed

Specmatic Not resolving $ref examples. #1263

barath121 opened this issue Aug 28, 2024 · 3 comments
Assignees

Comments

@barath121
Copy link

Description
Specmatic Not resolving $ref examples.

Steps to reproduce

  1. Create a api spec with example with ref as given below.
content:
    application/json:
        schema:
            $ref: '#/components/schemas/ExampleSchema'
        examples:
            success:
                value:
                $ref: '#/components/examples/ExampleSample'
  1. Run specmatic test this error occours.
[specmatic] 28-08-2024 17:06:46 debug: Test:   "Load Error FAILED"
        Reason: Error loading test data for Scenario: GET /service/application/content/v1.0/announcements -> 200
	   
    	   >> RESPONSE.BODY.$ref
	   
    	      The key $ref was found in the example success but was not in the specification

Expected behavior
Should resolve ref before validation.

System Information:

  • Specmatic version: Tested on Specmatic JS wrapper - 2.0.7 & 1.3.38 was working on 1.3.10.
@yogeshnikam671 yogeshnikam671 self-assigned this Aug 28, 2024
@yogeshnikam671
Copy link
Member

Hi @barath121, thanks for reporting this issue.
We will look into it and get back.

@yogeshnikam671
Copy link
Member

Hi @barath121, the spec you have provided here has the "value" and "$ref" keys as siblings.
In such case, the "value" will be ignored as there can be no siblings to "$ref". Refer this documentation for more details.

If we go by the spec snippet you have shared, we will never see the error message that you have reported.

That said, I was able to reproduce the issue by indenting the "$ref" key such that it is the child of the value. e.g.

   value:
      $ref:  SomeSchema

As per OpenAPI, this setup will not resolve the $ref, but will consider it as a key within some object with its value being "SomeSchema".
I am guessing you must have faced the issue that you've reported due to such a setup.
Can you please check this and get back to us?

You can also refer to this documentation which explains how examples can be reused using $ref.

Looking forward to your response. Thanks.

@barath121
Copy link
Author

Thank you @yogeshnikam671 this works.

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

2 participants