omissis / go-jsonschema

A tool to generate Go data types from JSON Schema definitions.
MIT License
582 stars 93 forks source link

local file ref failure #110

Closed ldemailly closed 11 months ago

ldemailly commented 1 year ago

repro:

go install github.com/atombender/go-jsonschema/cmd/gojsonschema@latest

(btw consider fixing it so the github.com/omissis/go-jsonschema path works)

in ids.json

{
  "id": {
    "enum": [
       "a",
       "b"
    ]
  }
}

in schema.json

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Bug",
  "type": "array",
  "uniqueItems": true,
  "items": {
    "type": "object",
    "properties": {
      "idref": {
        "$ref": "file://./ids.json#/id"
      }
    }
  }
}

then

$ gojsonschema -p main schema.json 
go-jsonschema: Failed: could not generate type for field "idref": unsupported $ref format; must point to definition within file: "file://./ids.json#/id"
samherrmann commented 1 year ago

I'm not sure if file://./ids.json#/id is actually a valid reference. VSCode's validator also complains about that reference. But I can confirm that go-jsonschema also doesn't work with ./ids.json#/id and ids.json#/id while VSCode is happy with either of those.

ldemailly commented 1 year ago

We use https://github.com/neilpa/yajsv/ which takes that syntax fine, happy to change to whichever works for that tool and would work (better) with go-jsonschema

omissis commented 1 year ago

Hi! I have started the work here: https://github.com/omissis/go-jsonschema/pull/147 In the next few days I will also add @ldemailly 's example to the test suite and see to make it work. Thanks!

omissis commented 11 months ago

I merged the issue #147 , which should solve the problem. The feature will become available in the upcoming v0.15.0 release, in the meantime it can be tested by building from main. closing.