Logo: Relish

  1. Sign in

Project: Lurker 0.5.5

controller schema scaffolding

When you prefer to test controller not in a unit-test fashion,
but including render_views - you can add :lurker metadata
to get a json schema for your api-documented endpoint

Scenarios
scaffold a json schema for a "users/show" in controller spec
Given
a file named "spec/controllers/api/v1/users_controller_spec.rb" with:
require "spec_helper"

describe Api::V1::UsersController, :lurker do
  render_views

  let!(:user) do
    User.where(name: 'razum2um').first_or_create!
  end

  it "shows user" do
    get :show, id: user.id
    expect(response).to be_success
  end
end
When
I run bin/rspec spec/controllers/api/v1/users_controller_spec.rb
Then
the example should pass
Then
a file named "lurker/api/v1/users/__id-GET.json.yml" should exist
Then
the file "lurker/api/v1/users/__id-GET.json.yml" should contain exactly:
---
description: user
prefix: users management
requestParameters:
  properties:
    id:
      description: ''
      type: integer
      example: 1
  required: []
responseCodes:
- status: 200
  successful: true
  description: ''
responseParameters:
  properties:
    id:
      description: ''
      type: integer
      example: 1
    name:
      description: ''
      type: string
      example: razum2um
  required: []
extensions:
  method: GET
  path_info: "/api/v1/users/1"
  path_params:
    action: show
    controller: api/v1/users
    id: '1'
  suffix: ''

Last published over 3 years ago by razum2um.