APIDevTools / json-schema-ref-parser

Parse, Resolve, and Dereference JSON Schema $ref pointers in Node and browsers
https://apitools.dev/json-schema-ref-parser
MIT License
942 stars 226 forks source link

Fail to parse circular reference defined in external file: wrong file path is updated to ref value #308

Closed xiaoxuqi-ms closed 5 months ago

xiaoxuqi-ms commented 1 year ago

file1.json: { "swagger": "2.0", "paths": { "/:analyze-text": { "post": { "parameters": [ { "$ref": "common.json#/parameters/ApiVersionParameter" } ], "responses": { "default": { "description": "Unexpected error", "schema": { "$ref": "common.json#/definitions/ErrorResponse" } } } } } }, "definitions": { "DocumentError": { "type": "object", "required": [ "error" ], "properties": { "error": { "type": "object", "description": "Document Error.", "$ref": "common.json#/definitions/Error" } } } } }

File2.json { "swagger": "2.0", "paths": {}, "definitions": { "ErrorResponse": { "type": "object", "description": "Error response.", "additionalProperties": false, "properties": { "error": { "description": "The error object.", "$ref": "#/definitions/Error" } }, "required": [ "error" ] }, "Error": { "type": "object", "description": "The error object.", "additionalProperties": true, "required": [ "code", "message" ], "properties": { "message": { "type": "string", "description": "A human-readable representation of the error." }, "target": { "type": "string", "description": "The target of the error." }, "details": { "type": "array", "description": "An array of details about specific errors that led to this reported error.", "items": { "$ref": "#/definitions/Error" } } } } }, "parameters": { "ApiVersionParameter": { "name": "api-version", "in": "query", "required": true, "type": "string", "description": "Client API version." } } } After deference with option circular: ignore { swagger: "2.0",

paths: { "/:analyze-text": { post: { summary: "Request text analysis over a collection of documents.", operationId: "AnalyzeText", consumes: [ "application/json", ], produces: [ "application/json", ], parameters: [ { name: "api-version", in: "query", required: true, type: "string", description: "Client API version.", }, ], responses: { default: { schema: { $ref: "common.json#/definitions/ErrorResponse", }, }, }, }, }, }, definitions: { DocumentError: { type: "object", required: [ "error", ], properties: { error: { $ref: "#/definitions/Error",//wrong filepath since Error is defined in external file type: "object", }, }, }, }, }