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

Windows: File references can't be resolved #441

Closed
djpesic opened this issue Nov 27, 2023 · 2 comments · Fixed by #577
Closed

Windows: File references can't be resolved #441

djpesic opened this issue Nov 27, 2023 · 2 comments · Fixed by #577

Comments

@djpesic
Copy link

djpesic commented Nov 27, 2023

I have two json schemas, both placed inside resources/schema directory. Root dir is a cargo project dir. Main schema (extracted and simplified from my project):

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "file://resources/programSegment.schema.json",
  "$defs": {
    "portType": {
      "type": "array",
      "description": "Port list",
      "items": {
        "type": "string"
      }
    }
  },
  "type": "object",
  "properties": {
    "a": {
      "type": "string"
    },
    "b": {
      "$ref": "file://resources/schema/ports.schema.json#/$defs/portType"
    }
  }
}

Second schema:

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "file://resources/ports.schema.json",
    "$defs": {
      "portType": {
        "type": "array",
        "description": "Port list",
        "items": {
          "type": "string"
        }
      }
    }
}

When I create Json example, if portType is placed in the same file with the rest of the schema, everything works with local $ref. If I try to reference to another file, like in the example, validation fails.

@djpesic
Copy link
Author

djpesic commented Nov 28, 2023

After some debugging, I found that the issue may lie inside resolver.rs file. The current code simply tries to open an absolute path. As I work on Windows, it can't work, because of Windows path format. Also, that approach is not portable. Currently, I wrote my own resolver, who finds schemas inside directory inside cargo project. It would be nice to have such feature implemented.

@eirnym
Copy link

eirnym commented Feb 11, 2024

Code clearly shows, that it's possible to set custom resolver instead of a default

@Stranger6667 Stranger6667 changed the title Can't resolve local url schema Windows: File references can't be resolved Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants