richhollis / swagger-docs

Generates swagger-ui json files for Rails APIs with a simple DSL.
MIT License
750 stars 150 forks source link

Question: Is there support for $ref #87

Closed ghost closed 10 years ago

ghost commented 10 years ago

Is there a way to define references?

https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#433-data-type-fields

nunogoncalves commented 10 years ago

I'm having the same question.

nunogoncalves commented 10 years ago

This works for me, maybe it works for you. Check this out: https://github.com/richhollis/swagger-docs/issues/71

richhollis commented 10 years ago

@yo-mash Did #71 resolve the issue for you?

ghost commented 10 years ago

sort of, In that case I think if you want to specify an array you need to be able to set the 'type' : 'array' and 'items' : 'ModelName' which I don't think can be done with the gem currently.

nunogoncalves commented 10 years ago

If I understood you well, check if this won't help you. :)

For example, for an index action I have this:

swagger_api :show do 
   type 'index_response'
end

swagger_model :index_response do
   property :foos, :array, :required, "List of foos", { "items" => { "$ref" => "foo_index_item" } }
end

swagger_model :foo_index_item do
   (...)
   id (...)
   name(...)
   (...)
end

For a show action:

swagger_api :show do
   param :path, 'id', :integer, :required, 'id'

   type :foo_show_item
end

swagger_model :foo_show_item do
   (...)
   id (...) 
   name (...) 
   bar (...)
   (...)
end
ghost commented 10 years ago

That works, Thanks!