Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to import into Swagger Editor - extra comma in generated JSON file #121

Open
belgoros opened this issue Dec 3, 2018 · 0 comments
Open

Comments

@belgoros
Copy link

belgoros commented Dec 3, 2018

I followed the README guidelines and created a JSON file after copy-pasting JSON response when hitting http://localhost:3000/apidocs URL.
Swagger Editor fails to accept it saying:

screenshot 2018-12-03 at 17 36 24

Here is ApidocsController:

class ApidocsController < ApplicationController
  skip_before_action :authorize_request
  
  include Swagger::Blocks
  
  swagger_root do
    key :swagger, '2.0'
    info do
      key :version, '1.0.0'
      key :title, 'Example Project API'
      key :description, 'A Swagger Project API that uses a bla-bla-bla project features ' \
                        'in commliance with the swagger-2.0 specification'
      contact do
        key :name, 'Fancy API Team'
      end
      license do
        key :name, 'MIT'
      end
    end
    
    tag do
      key :name, 'fancy_project'
      key :description, 'Example Project API operations'
      externalDocs do
        key :description, 'Find more info here'
        key :url, 'https://swagger.io'
      end
    end
    key :host, 'https://api-eu.swagger/example-project'
    key :basePath, '/v1'
    key :consumes, ['application/json']
    key :produces, ['application/json']
  end
  
  # A list of all classes that have swagger_* declarations.
    SWAGGERED_CLASSES = [
      V1::LanguagesController,
      Language,
      ErrorModel,
      self,
    ].freeze

    def index
      render json: Swagger::Blocks.build_root_json(SWAGGERED_CLASSES)
    end
end

Here is V1::LanguagesController code:

module V1
  class LanguagesController < ApplicationController
    include Swagger::Blocks

    before_action :find_language, only: :show

    swagger_path '/languages' do
      operation :get do
        key :summary, 'All Language tags'
        key :description, 'Returns all language ISO tags from the system that the user has access to'
        key :produces, [
          'application/json'
        ]
        key :tags, [
          'language'
        ]
        response 200 do
          key :description, 'Languages response'
          schema do
            key :type, :array
            items do
              key :'$ref', :Language
            end
          end
        end

        response :default do
          key :description, 'unexpected error'
          schema do
            key :'$ref', :ErrorModel
          end
        end
      end
    end

    def index
      @languages = Language.all
      json_response @languages, :ok
    end
...

What am I missing ?
Rails 5.2. (API-mode)
ruby 2.5.0

You cat find swagger.json content in this gist.

@belgoros belgoros changed the title Fail to import into Swagger Editor - extra comma in generated JSON file Fails to import into Swagger Editor - extra comma in generated JSON file Dec 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant