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

Does not resolve a top level $ref to a definition when using dereference #279

Closed
JaredAAT opened this issue Sep 27, 2022 · 1 comment
Closed

Comments

@JaredAAT
Copy link

JaredAAT commented Sep 27, 2022

I don't know enough of the technical terms sorry, but i'm not sure if this is the correct behaviour. I have a schema that contains a $ref to a definition:

{
  "$schema": "http:https://json-schema.org/draft-04/schema#",
  "$ref": "#/definitions/PricingRuleDetail",
  "definitions": {
        "PricingRuleDetail": {
           "type": "string"
         }
   }
}

and when using this code:

const $RefParser = require("@apidevtools/json-schema-ref-parser");

const main = async () => {
  const file = 'schema.json'
  const deReferencedSchema = await $RefParser.dereference(`./schemas/${file}`, {})
}

main()

it returns me a schema like

{
  "$schema": "http:https://json-schema.org/draft-04/schema#",
  "$ref": "#",
  "definitions": {
        "PricingRuleDetail": {
           "type": "string"
         }
   }
}

I would expect the schema to be resolved like:

{
  "$schema": "http:https://json-schema.org/draft-04/schema#",
  "PricingRuleDetail": {
           "type": "string"
  },
  "definitions": {
        "PricingRuleDetail": {
           "type": "string"
         }
   }
}

Though i suspect i'm asking too much here... Is there a different tool or library I should use to get my expected result?

@abraha2d
Copy link

Encountered the same issue, looks like top-level refs aren't supported very well, see #201, #259, #48.

@jonluca jonluca closed this as completed Mar 6, 2024
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