swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

generate models for definitions that haven't been referenced within paths?

Open jaz-ah opened this issue 10 years ago • 5 comments

@wing328 I had a quick question - I have a file called bar.json that basically looks like:

{ "swagger": "2.0", "info": { "version": "1.0.0", "title": "xxx", "description": "yyy", "termsOfService": "xxx", "contact": { "name": "xxx" }, "license": { "name": "MIT" } }, "host": "xxx", "basePath": "", "schemes": [ "https" ], "consumes": [ "application/json" ], "produces": [ "application/json" ], "paths": { "/foo": { "$ref":"./Foo.json#/thefoo" } } }

and in Foo.json I have:

{ "thefoo": { "get": { "operationId": "getFoo", "produces": [ "application/json" ], "responses": { "200": { "schema": { "$ref": "./Foo.json#FooResponse" } } } } }, "definitions": { "FooResponse" : { "type": "object" }, "OtherStuff": { "type": "object" } } }

Everything gets generated correctly except OtherStuff doesn't get generated - it's not referenced explicitly but I would like to figure out a way to still generate an object for it (because it can be buried within a FooResponse sometimes)...

jaz-ah avatar May 09 '16 20:05 jaz-ah

(btw this happens for Swift + Android but my guess it's an overall thing that is probably by design - but if there is a way to override this behavior that would help - thx)

jaz-ah avatar May 09 '16 21:05 jaz-ah

(one hack could be to just add a new property to fooResponse like this: "xxxCodeGenxxx": { "type": "object", "$ref": "./Foo.json#OtherStuff" }

but this feels gross

jaz-ah avatar May 09 '16 22:05 jaz-ah

(I did end up just referencing everything through definitions in the main file but seems like swagger should look at definitions in other files as well somehow...)

jaz-ah avatar May 11 '16 11:05 jaz-ah

Hi @jaz-ah, that is by design. We only bring in externally-referenced models if they're referenced. In fact, we don't parse the entire remote file--just what you ask for (and any references it may have).

The problem is, many remote files are extremely large (common files) and bringing in everything would be really ugly if you don't need it all.

fehguy avatar May 11 '16 14:05 fehguy

@fehguy fair enough - thx!

jaz-ah avatar May 11 '16 16:05 jaz-ah