calderalabs / rspec_api_blueprint Goto Github PK
View Code? Open in Web Editor NEWAutogeneration of API documentation using the Blueprint format from request specs.
License: MIT License
Autogeneration of API documentation using the Blueprint format from request specs.
License: MIT License
The default rspec request content_type is application/x-www-form-urlencoded
, so the response body is not generated.
# GET /v2/connections{?from,to}
+ Response 200 application/json
I think line 69 should read response.content_type
instead of request.content_type
.
if response.body.present? && response.content_type == 'application/json'
So, we have this idea for the ideal workflow:
There are two things missing to get to this state:
I can imagine the docs would either be in the source file (controller) or spec file. I'd probably go with the spec file as it will keep the information in one place, and also implementation will be easier.
The gem should copy the markdown docs from comments and place them in the generated file.
# Arena represents a combat room.
#
# Attributes:
#
# - `name` - arena name
# - `owner` - user who created the arena
describe 'Arenas Requests' do
# Fetch information about an arena.
describe 'GET /v1/arenas/{id}' do
it 'responds with the requested arena' do
arena = create :arena, foursquare_id: '5104'
get v1_arena_path(arena)
response.status.should eq(200)
end
end
end
Would generate
# Group Arenas
Arena represents a combat room.
Attributes:
- `name` - arena name
- `owner` - user who created the arena
## GET /v1/arenas/{id}
Fetch information about an arena.
+ Response 200 (application/json)
{
"arena": {
"id": "4e9dbbc2-830b-41a9-b7db-9987735a0b2a",
"name": "Clinton St. Baking Co. & Restaurant",
"latitude": 40.721294,
"longitude": -73.983994,
"foursquare_id": "5104"
}
}
The following error occurs when I try to test my JSON API with Rack::Test::Methods
and the last_response
variable:
Failure/Error: Unable to find matching line from backtrace 'example' is not available from within an example (e.g. an 'it' block) or from constructs that run in the scope of an example (e.g. 'before', 'let', etc). It is only available on an example group (e.g. a 'describe' or 'context' block).
Any idea how I can solve this issue?
Hey @matteodepalo, is this gem still maintained? If you're not using it anymore, can you maybe provide someone admin rights so issues/PRs don't stale? There are things from 2013 here.
I need this for my project and I'd love to see this moving forward.
Hi, I'm trying use this gem to generate a blueprint.
When I execute bundle exec rspec, show this error:
undefined local variable or method `last_response' for #RSpec::ExampleGroups::UsersRequests::GETApiUsers:0x007fafa6bde540
I'm using Rails 4.1.4, Rspec 3.0.0
I must be missing something or/but the documentation is poor on this subject.
How do I actually create the output file? and where does it create it at?
cheers
UPDATE
ok I see it creates a folder ./api_docs in the app's root directory, I was using git status
to check for file modifications. Why does this folder not show up in git? my .gitignore has not been modified.
UPDATE
til: git does not track empty folders.
Upon getting the gem to work in Sinatra app, I came across a few issues,
in my app I have a simple around(:each) hook
config.around(:each) do |example|
DB.transaction(:rollback=>:always, :auto_savepoint=>true) { example.run }
end
which when used in conjunction with this gem was rasing the following error:
`example` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). It is only available on an example group (e.g. a `describe` or `context` block).
# ./spec/spec_helper.rb:27:in `block (3 levels) in <top (required)>'
# ./spec/spec_helper.rb:27:in `block (2 levels) in <top (required)>'
spec was trying to call example from within another example.
This is a simple fix.
I have opened a pr that address this issue and a allows this gem to work in a non Rails app, though still needs to be tested with Rack::Test and rspec.
pr #19
Right now sending a web form or any request body not in JSON format raises a parsing exception.
I have model's controller in the path app/controller/v1/models_controller.rb and setup my tests as:
describe "Models Requests" do
describe 'POST /v1/model' do
end
end
When I run bundle exec rspec
I receive a RuntimeError:@controller is nil: make sure you set it in your test's setup method.
For what it's worth I just wanted to let you know that I have finished a gem that converts AST and AST serialization media types into the API Blueprint format โ Matter Compiler.
You can feed it with a JSON, YAML or in your case directly build the AST at runtime and then just call Blueprint.serialize
to get the formatted API Blueprint Markdown.
Using the Matter Compiler
would essentially nullify the need for Rspec Api Blueprint
to understand the API Blueprint syntax, it would only need to build its AST.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.