livingsocial / swagger_yard

Swagger-UI compliant JSON generated from YARD. For RESTful Rails apps.
MIT License
51 stars 28 forks source link

Host doesn't include port number #35

Closed johngiffin closed 8 years ago

johngiffin commented 8 years ago

The host name returned in swagger json should include the port so that swagger UI can generate the right "curl" and "try it" urls.

The spec indicates that host may include a port: http://swagger.io/specification/

tpitale commented 8 years ago

Yes it should. Will take a look, probably early next week. I expect it's due to our usage of URI.

johngiffin commented 8 years ago

Here are my changes to lib/swagger_yard/swagger.rb. I can submit a PR if that would be helpful.

    def to_h

host { "swagger" => "2.0", "info" => Info.new.to_h, "host" => host, "basePath" => URI(SwaggerYard.config.api_base_path).request_uri }.merge(ResourceListing.all.to_h) end

private

def host uri = URI(SwaggerYard.config.api_base_path)

if uri.default_port == uri.port uri.host else "#{uri.host}:#{uri.port}" end end


  end