mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 15:22:56 +00:00
Basic functionality via minitest
This commit is contained in:
@@ -2,4 +2,6 @@ class ApplicationController < ActionController::Base
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
wrap_parameters format: [ :json ]
|
||||
end
|
||||
|
||||
14
spec/dummy/app/controllers/blogs_controller.rb
Normal file
14
spec/dummy/app/controllers/blogs_controller.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class BlogsController < ApplicationController
|
||||
|
||||
def create
|
||||
render json: {}
|
||||
end
|
||||
|
||||
def index
|
||||
render json: {}
|
||||
end
|
||||
|
||||
def show
|
||||
render json: {}
|
||||
end
|
||||
end
|
||||
@@ -6,7 +6,7 @@ require "action_controller/railtie"
|
||||
require "action_mailer/railtie"
|
||||
require "action_view/railtie"
|
||||
require "sprockets/railtie"
|
||||
# require "rails/test_unit/railtie"
|
||||
require "rails/test_unit/railtie"
|
||||
|
||||
Bundler.require(*Rails.groups)
|
||||
require "swagger_rails"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
Rails.application.routes.draw do
|
||||
mount SwaggerRails::Engine => '/api-docs'
|
||||
|
||||
resources :blogs, only: [ :create, :index, :show ]
|
||||
end
|
||||
|
||||
@@ -2,43 +2,117 @@
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"version": "0.0.0",
|
||||
"title": "[Enter a description for your API here]",
|
||||
"description": "The docs below are powered by the default swagger.json that gets installed with swagger_rails. You'll need to update it to describe your API. See here for the complete swagger spec - https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md"
|
||||
"title": "Dummy app for testing swagger_rails"
|
||||
},
|
||||
"paths": {
|
||||
"/a/sample/resource": {
|
||||
"/blogs": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"a/sample/resource"
|
||||
],
|
||||
"description": "Create a new sample resource",
|
||||
"description": "Creates a new Blog",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"name": "X-Forwarded-For",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"default": "client1"
|
||||
},
|
||||
{
|
||||
"name": "blog",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/CreateSampleResource"
|
||||
"$ref": "#/definitions/Blog"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Ok"
|
||||
"description": "Ok",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Blog"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/RequestError"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"get": {
|
||||
"description": "Searches Bloggs",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "published",
|
||||
"in": "query",
|
||||
"type": "boolean",
|
||||
"default": "true"
|
||||
},
|
||||
{
|
||||
"name": "keywords",
|
||||
"in": "query",
|
||||
"type": "string",
|
||||
"default": "Ruby on Rails"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Ok",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Blog"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
"/blogs/{id}": {
|
||||
"get": {
|
||||
"description": "Retrieves a specific Blog by unique ID",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"default": "123"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Ok",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Blog"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"CreateSampleResource": {
|
||||
"Blog": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"date_time": {
|
||||
"content": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
}
|
||||
},
|
||||
"example": {
|
||||
"title": "Test Blog",
|
||||
"content": "Hello World"
|
||||
}
|
||||
},
|
||||
"RequestError": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "array",
|
||||
"item": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"example": {
|
||||
"title": [ "is required" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
spec/dummy/test/integration/v1_contract_test.rb
Normal file
9
spec/dummy/test/integration/v1_contract_test.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
require 'test_helper'
|
||||
require 'swagger_rails/testing/test_helpers'
|
||||
|
||||
class V1ContractTest < ActionDispatch::IntegrationTest
|
||||
include SwaggerRails::TestHelpers
|
||||
|
||||
swagger_doc 'v1/swagger.json'
|
||||
swagger_test_all
|
||||
end
|
||||
7
spec/dummy/test/test_helper.rb
Normal file
7
spec/dummy/test/test_helper.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
ENV["RAILS_ENV"] = "test"
|
||||
require File.expand_path('../../config/environment', __FILE__)
|
||||
require 'rails/test_help'
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
# Add more helper methods to be used by all tests here...
|
||||
end
|
||||
Reference in New Issue
Block a user