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

InvalidPointerError: Invalid $ref pointer. Pointers must begin with "#/" #345

Closed
Envek opened this issue Oct 28, 2020 · 1 comment
Closed
Labels
bug external This is an issue with a library that we depend on

Comments

@Envek
Copy link

Envek commented Oct 28, 2020

I tried to use json2ts with complex schema which uses references to elements in another schema (see examples below), but got following error:

  code: 'EINVALIDPOINTER',
  message: 'Invalid $ref pointer "email". Pointers must begin with "#/"',
  source: '/home/envek/types.json',
  name: 'InvalidPointerError',

This probably caused by APIDevTools/json-schema-ref-parser#42, also see APIDevTools/json-schema-ref-parser#136

It (possibly) can be solved by APIDevTools/json-schema-ref-parser#141 (I tried to pull, rebase, and use it, but got stuck in TypeScript errors about JSONSchema4 vs JSONSchema6 incompatibilites).

Steps to reproduce:

person.json
{
  "title": "Example Schema",
  "type": "object",
  "properties": {
    "fullName": {
      "type": "string"
    },
    "emailAddress": {
      "allOf": [{ "$ref": "types.json#email" }]
    }
  },
  "additionalProperties": false,
  "required": ["fullName", "emailAddress"]
}
types.json
{
  "$id": "https://example.com/example.json",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "types": {
    "email": {
      "$id": "#email",
      "type": "string",
      "format": "email"
    }
  }
}
json2ts person.json

Expected result:

person.d.ts
export interface ExampleSchema {
  fullName: string;
  emailAddress: string;
}

Any workarounds?

Is there a way to workaround this? Real schemas I want to process are huge and full of such $id-references…

@bcherny bcherny added bug external This is an issue with a library that we depend on labels Nov 29, 2020
@bcherny
Copy link
Owner

bcherny commented Nov 29, 2020

Thank you for the report + investigation. Mind filing this in the json-schema-ref-parser repo, and comment back when the fix has been merged so we can upstream it here?

@bcherny bcherny closed this as completed Nov 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug external This is an issue with a library that we depend on
Projects
None yet
Development

No branches or pull requests

2 participants