a-h / generate

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

Enable multifile output #49

Closed jamiehannaford closed 6 years ago

jamiehannaford commented 6 years ago

When you specify multiple input JSON files, only one generated file ever gets outputted. This is because root schemas have the same name of # which causes keys to be overriden here.

So one workaround is to treat the generated structs per file and iterate over them for output. Let me know if there's a better way to fix this.

antoineco commented 6 years ago

I think that's because your schemas do not have a valid $id (I generate a Go API from ~20 files in my project). If the $ids differ names you should not have conflicts with #, but maybe I got it wrong.

jamiehannaford commented 6 years ago

Oh derp. You're completely right, thanks for the heads up!

antoineco commented 6 years ago

You're welcome, I've had exactly the same problem in the past 😄 In the end setting my $ids to "$id": "http://example.com/mytype.json" was all I needed to change. Cross-references like "$ref": "mytype.json" also work that way.