livingsocial / swagger_yard

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

Yaml generation fails to generate a correct tags block. #61

Open garpur opened 5 years ago

garpur commented 5 years ago

The write to yaml is broken. generates: .... tags:

the json writer generates: ... "tags": [ { "name": "Phenotypes foobar", "description": "Some descr" } ], "components": { ...

The tags seems to be the only block that is broken, the other blocks are as expected.

nicksieger commented 5 years ago

How are you generating YAML? If you're using one of the SwaggerYard::Swagger or OpenAPI objects, may I suggest modifying your code to call the #to_h method first like so:

s = SwaggerYard::Swagger.new
puts YAML::dump(s.to_h)
garpur commented 5 years ago

Sorry for being unclear (imprecise)

My config. `SwaggerYard.configure do |config| config.title = 'Endpoint reference' config.description = 'Below is a list of the endpoints in the API along with examples and parameter documentation.' config.api_version = "0.1"

host = ENV['XXX_ZZZ'] || 'localhost' config.api_base_path = "https://#{host}/"

config.swagger_version = '3.0' config.controller_path = Dir.glob Rails.root.join('app/controllers/*/').to_s config.model_path = Dir.glob Rails.root.join('app/serializers/*/').to_s end `

Currently just running interactively in "rails c" `SwaggerYard.register_custom_yard_tags!

spec = SwaggerYard::OpenAPI.new File.open("openapi.yml", "w") { |f| f << YAML.dump(spec.to_h) }

specc = SwaggerYard::OpenAPI.new File.open("openapi.json", "w") { |ff| ff << JSON.pretty_generate(specc.to_h) } `

This generates a valid .JSON file but the YAML file has noise in the middle.

speccc = SwaggerYard::OpenAPI.new puts YAML::dump(speccc.to_h) this also generates invalid YAML