- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 239
Open
Description
We have to process a bunch of json schemas produced by another team and bundled using @hyperjump/json-schema.
For reference (pun intended) here is a simple sample of such bundles.
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://common-schemas.redacted.com",
  "type": "object",
  "properties": {
    "dateInMilliseconds": { "$ref": "#/definitions/DateInMilliseconds" },
    "monetary": { "$ref": "#/definitions/Monetary" },
    "reference": { "$ref": "#/definitions/Reference" },
    "referenceWithExternalId": {
      "$ref": "#/definitions/ReferenceWithExternalId"
    }
  },
  "required": [
    "dateInMilliseconds",
    "monetary",
    "reference",
    "referenceWithExternalId"
  ],
  "additionalProperties": false,
  "title": "CommonTypes",
  "description": "Bunndle of common types",
  "definitions": {
    "DateInMilliseconds": {
      "$ref": "http://common-schemas.redacted.com/date-in-milliseconds"
    },
    "Monetary": {
      "$ref": "http://common-schemas.redacted.com/monetary"
    },
    "Reference": {
      "$ref": "http://common-schemas.redacted.com/reference"
    },
    "ReferenceWithExternalId": {
      "$ref": "http://common-schemas.redacted.com/reference-with-external-id"
    },
    "http://common-schemas.redacted.com/date-in-milliseconds": {
      "$id": "http://common-schemas.redacted.com/date-in-milliseconds",
      "title": "DateInMilliseconds",
      "description": "A UTC datetime in milliseconds",
      "type": "integer"
    },
    "http://common-schemas.redacted.com/monetary": {
      "$id": "http://common-schemas.redacted.com/monetary",
      "title": "Monetary",
      "description": "An amount of money in a specific currency.",
      "type": "object",
      "properties": {
        "amount": {
          "type": "number",
          "description": "The net monetary value. A negative amount denotes a debit; a positive amount a credit."
        },
        "currency": {
          "type": "string",
          "description": "The [ISO 4217 currency code](https://en.wikipedia.org/wiki/ISO_4217) for this monetary value. This is always upper case ASCII.",
          "minLength": 3,
          "maxLength": 3
        }
      },
      "required": ["amount", "currency"],
      "additionalProperties": false
    },
    "http://common-schemas.redacted.com/reference": {
      "$id": "http://common-schemas.redacted.com/reference",
      "title": "Reference",
      "description": "Reference to an API object",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "description": "Well known global unique identifier",
          "minLength": 1
        },
        "lastModif": { "$ref": "#/definitions/DateInMilliseconds" }
      },
      "required": ["id", "lastModif"],
      "definitions": {
        "DateInMilliseconds": {
          "$ref": "http://common-schemas.redacted.com/date-in-milliseconds"
        }
      }
    },
    "http://common-schemas.redacted.com/reference-with-external-id": {
      "$id": "http://common-schemas.redacted.com/reference-with-external-id",
      "title": "ReferenceWithExternalId",
      "description": "Reference to an API object which has an `externalId' property",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "externalId": {
          "type": ["string", "null"],
          "description": "Well known global unique identifier from an external data source",
          "minLength": 1
        },
        "id": {
          "type": "string",
          "description": "Well known global unique identifier",
          "minLength": 1
        },
        "lastModif": { "$ref": "#/definitions/DateInMilliseconds" }
      },
      "required": ["externalId", "id", "lastModif"],
      "definitions": {
        "DateInMilliseconds": {
          "$ref": "http://common-schemas.redacted.com/date-in-milliseconds"
        }
      }
    }
  }
}Above bundle references four schemas which are plainly defined under #/definitions with matching $ids.
- "$id": "http://common-schemas.redacted.com/date-in-milliseconds"
- "$id": "http://common-schemas.redacted.com/monetary"
- "$id": "http://common-schemas.redacted.com/reference"
- "$id": "http://common-schemas.redacted.com/reference-with-external-id"
Whenever we attempt to process it (initially via json-schema-to-typescript or using json-schema-ref-parser's dereference() function) we get the bellow ResolverError.
/Users/redacted/dev/redacted/node_modules/.pnpm/@apidevtools+json-schema-ref-parser@11.9.3/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/resolvers/http.js:123
        throw new errors_js_1.ResolverError((0, ono_1.ono)(err, `Error downloading ${u.href}`), u.href);
              ^
ResolverError: Error downloading http://common-schemas.redacted.com/date-in-milliseconds 
fetch failed
    at download (/Users/redacted/dev/redacted/node_modules/.pnpm/@apidevtools+json-schema-ref-parser@11.9.3/node_modules/@apidevtools/json-schema-ref-parser/dist/lib/resolvers/http.js:123:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  code: 'ERESOLVER',
  source: 'http://common-schemas.redacted.com/date-in-milliseconds',
  path: null,
  toJSON: [Function: toJSON],
  [Symbol(nodejs.util.inspect.custom)]: [Function: inspect]
}
We are probably missing something obvious, but couldn't find how to prevent "bundled" references to be (wrongfully) processed by the http parser while already referenced under #/definitions.
Any advice?
Thanks in advance,
Metadata
Metadata
Assignees
Labels
No labels