Skip to content

Bundle replaces duplicate $refs with relative pointers #101

Closed
@philosowaffle

Description

@philosowaffle

First and foremost, this may be a non-issue, I just wanted to confirm the behavior was intended and verify that I am using the library correctly. This also may not be the correct repo for this issue.

I had an issue logged where a user was getting errors in their swagger doc after using multiple $refs to the same file. Example Schema

The following test code demonstrates the issue using the linked schema:

const refParser = require('json-schema-ref-parser')
const path = require('path');

var source = path.join(__dirname, '/schema/petstore.yaml');

refParser.bundle(source, (err, schema) => {
    if (err) {
        console.error('ERROR:', err);
    }
    else {
       // at this point swagger editor claims the schema is invalid
        console.log('SUCCESS:', JSON.stringify(schema, null, 2)); 
        console.log("DEREFERENCE");

        refParser.dereference(schema, (err, drSchema) => {
            if (err) {
                console.error('ERROR:', err);
            }
            else {
               // after a dereference, swagger editor says schema is valid
                console.log('SUCCESS:', JSON.stringify(drSchema, null, 2)); 
            }
        });
    }
});

An initial call to bundle creates a schema that uses local json pointers for the duplicate references. However, this throws errors when copy/pasted into the official Swagger Editor. I noticed that this same bundled schema does not yield any errors when plugged into your Swagger Validator Demo.

After reading through this issue I determined that you must be calling dereference before doing the validation. When I add a follow up call to dereference, as seen in the test above, the relative json pointers are dereferenced and swagger editor is happy again.

  1. Is this intended behavior?
  2. Is calling bundle followed by dereference a suitable workaround, or should I be doing something else in entirely?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions