a-h / generate

Generates Go (golang) Structs from JSON schema.
MIT License
444 stars 137 forks source link

Handling $refs which are HTTP URLs #34

Open aktungmak opened 6 years ago

aktungmak commented 6 years ago

Hi!

First, I am super glad you have written this library, it already does most of what I need to do, namely programatically generate structs from schema definitions like these:

https://redfish.dmtf.org/schemas/ComputerSystem.v1_5_0.json

As you can see, the a lot of the $refs are specified with URLs pointing to other locations. I can see that in generator.go:getTypeForField() you are parsing the string as a URL. What do you think about checking the url.Scheme field and making an HTTP request to resolve it?

I need to find a way to process all the redfish schemata so if you are interested on working on this with me let me know.

a-h commented 6 years ago

Thanks, I wrote it initially to do some grunt work for me at a client I was working with, and thought it might be handy for others. People have made really good contributions and improved it, which is great!

First thoughts are that downloading resources from the Web on demand should be disabled by default so that a misconfigured or malicious schema doesn't cause lots of data to be downloaded, but enabled by a parameter. Complex schemas could reference a lot of files, so downloading could be slow, a local cache might be handy, but not essential. It absolutely sounds like a useful change.

I don't have time to work on this at the moment, but I'd happily take a pull request. The work to support multiple files was contributed by @sqs (thanks again!) - I think your idea would build on that to resolve URLs.

aktungmak commented 6 years ago

Yes, I completely agree - resolving remote resources should be an optional flag. I will fork and send you some PRs with any improvements I can make.

kequeen commented 1 year ago

is it still open ? where is you PR?