omissis / go-jsonschema

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

Fails to generate for Signal K, cannot generate referenced type. #173

Open kmpm opened 9 months ago

kmpm commented 9 months ago

Signal K has a JSON schema at https://github.com/SignalK/specification/tree/master/schemas which go-jsonschema fails to generate code for.

# when located in the `schemas` folder of the signal k specification
go-jsonschema -p signalk -o signalk.go -v signalk.json
go-jsonschema: Loading signalk.json
go-jsonschema: Failed: could not generate type for field "resources": cannot generate referenced type: value must point to definition within file: 'groups/resources.json#'

I'll gladly help out any way I can but I'll gladly get some pointers on where to start looking.

omissis commented 9 months ago

hi @kmpm, thanks for reporting this. I tried building from main and running the tool, and I was able to reproduce the problem. There are two things causing this that might require some work: the first one being go-jsonschema is not able to handle #-terminated urls in refs, and the second one is that it does not handle the way array items are specified in one of the files. As a quick fix, you can remove all the # from the end of urls, and patch definitions.json#definitions/waypoint.feature.geometry.coordinates 's items to a supported format. Two pics are worth two thousands words: hashes items