项目作者: funbox

项目描述 :
Coverage API Blueprint, Swagger and OpenAPI with RSpec for easily make high-quality API and documenatiton
高级语言: Ruby
项目地址: git://github.com/funbox/fitting.git
创建时间: 2017-02-06T09:32:39Z
项目社区:https://github.com/funbox/fitting

开源协议:MIT License

下载


Fitting

Fitting avatar: Documents with hangers

Library add improve test log, validate its according to your API documentation, show the documentation coverage with log.

Test log setting supports RSpec test and WebMock stubbing for Ruby On Rails application, API documentation supports API Blueprint and OpenAPI.

This reduces the costs of support, testers and analysts.

Log

  1. FITTING incoming request {"method":"POST","path":"/public/api/v1/inboxes/tEX5JiZyceiwuKMi1oN9Sf8S/contacts","body":{},"response":{"status":200,"content_type":"application/json","body":{"source_id":"00dbf18d-879e-47cb-ac45-e9aece266eb1","pubsub_token":"ktn6YwPus57JDf4e59eFPom5","id":3291,"name":"shy-surf-401","email":null,"phone_number":null}},"title":"./spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb:9","group":"./spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb","host":"www.example.com"}
  2. FITTING outgoing request {"method":"POST","path":"/v1/organizations/org_id/meeting","body":{},"response":{"status":200,"content_type":"application/json","body":{"success":true,"data":{"meeting":{"id":"meeting_id","roomName":"room_name"}}}},"title":"./spec/controllers/api/v1/accounts/integrations/dyte_controller_spec.rb:50","group":"./spec/controllers/api/v1/accounts/integrations/dyte_controller_spec.rb","host":"api.cluster.dyte.in"}

validation

  1. FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.FFF..FFFFFFFFFF....F.......F...FF.....F...F....F..............................FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF..FF.F..FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF..FF........FFF...FFFF......FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF........FFFFFFFFFFF..FFFFFF..FFFFFFFFFFFFFFFFF.......FFFFFF.............FFFFFFFFFFFF....F........FFF.F...FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF............FF........FFF......FFFFFFFFFFFFFFFFFFFFFF....FFFFFF......F............FFFF........FFFFFFFFFFFFFF.....FFFFFFFFFFFFFFFFFFFFFFF..FF.....FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.....FF..........FFFFFFFFFFFFFFFFFF...FFFF...............F.F....FF..FFFFFFFF
  2. 1) Fitting::Doc::NotFound log error:
  3. host: www.example.com
  4. method: POST
  5. path: /public/api/v1/inboxes/{inbox_identifier}/contacts
  6. code: 200
  7. content-type: application/json
  8. json-schema: {
  9. "$schema": "http://json-schema.org/draft-04/schema#",
  10. "type": "object",
  11. "properties": {
  12. "id": {
  13. "type": "integer",
  14. "description": "Id of the contact"
  15. },
  16. "source_id": {
  17. "type": "string",
  18. "description": "The session identifier of the contact"
  19. },
  20. "name": {
  21. "type": "string",
  22. "description": "Name of the contact"
  23. },
  24. "email": {
  25. "type": "string",
  26. "description": "Email of the contact"
  27. },
  28. "pubsub_token": {
  29. "type": "string",
  30. "description": "The token to be used to connect to chatwoot websocket"
  31. }
  32. }
  33. }
  34. body: {
  35. "source_id": "c9e8c31f-06df-49b4-8fb9-4466457ae65b",
  36. "pubsub_token": "Zgc7DEvaj5TkgZ1a4C7AvJXo",
  37. "id": 3293,
  38. "name": "restless-snowflake-670",
  39. "email": null,
  40. "phone_number": null
  41. }
  42. error [
  43. "The property '#/email' of type null did not match the following type: string in schema e56b7e65-d70c-5f7a-a96c-982df5f8f2f7"
  44. ]
  45. ...
  46. 804 examples, 565 failure, 0 pending
  47. Coverage: 65.51%

and cover
exmaple

exmaple

exmaple

exmaple

Installation

Add this line to your application’s Gemfile:

  1. gem 'fitting'

After that execute:

  1. $ bundle

Or install the gem by yourself:

  1. $ gem install fitting

Usage

Log

Firstly, improve test.log.

To your spec_helper.rb:

  1. require 'fitting'
  2. Fitting.logger

Delete all files log/*.log and run rspec

You get more information about incoming and outgoing request in log/fitting*.log.

  1. FITTING incoming request {"method":"POST","path":"/public/api/v1/inboxes/tEX5JiZyceiwuKMi1oN9Sf8S/contacts","body":{},"response":{"status":200,"content_type":"application/json","body":{"source_id":"00dbf18d-879e-47cb-ac45-e9aece266eb1","pubsub_token":"ktn6YwPus57JDf4e59eFPom5","id":3291,"name":"shy-surf-401","email":null,"phone_number":null}},"title":"./spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb:9","group":"./spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb","host":"www.example.com"}
  2. FITTING outgoing request {"method":"POST","path":"/v1/organizations/org_id/meeting","body":{},"response":{"status":200,"content_type":"application/json","body":{"success":true,"data":{"meeting":{"id":"meeting_id","roomName":"room_name"}}}},"title":"./spec/controllers/api/v1/accounts/integrations/dyte_controller_spec.rb:50","group":"./spec/controllers/api/v1/accounts/integrations/dyte_controller_spec.rb","host":"api.cluster.dyte.in"}

Validation

Secondly, validate the log to the documentation.

Add this to your .fitting.yml:

  1. APIs:
  2. - host: www.example.com
  3. type: openapi2
  4. path: swagger/swagger.json

Run

  1. bundle e rake fitting:validate

Console output

  1. FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.FFF..FFFFFFFFFF....F.......F...FF.....F...F....F..............................FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF..FF.F..FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF..FF........FFF...FFFF......FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF........FFFFFFFFFFF..FFFFFF..FFFFFFFFFFFFFFFFF.......FFFFFF.............FFFFFFFFFFFF....F........FFF.F...FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF............FF........FFF......FFFFFFFFFFFFFFFFFFFFFF....FFFFFF......F............FFFF........FFFFFFFFFFFFFF.....FFFFFFFFFFFFFFFFFFFFFFF..FF.....FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.....FF..........FFFFFFFFFFFFFFFFFF...FFFF...............F.F....FF..FFFFFFFF
  2. 1) Fitting::Doc::NotFound log error:
  3. host: www.example.com
  4. method: POST
  5. path: /public/api/v1/inboxes/{inbox_identifier}/contacts
  6. code: 200
  7. content-type: application/json
  8. json-schema: {
  9. "$schema": "http://json-schema.org/draft-04/schema#",
  10. "type": "object",
  11. "properties": {
  12. "id": {
  13. "type": "integer",
  14. "description": "Id of the contact"
  15. },
  16. "source_id": {
  17. "type": "string",
  18. "description": "The session identifier of the contact"
  19. },
  20. "name": {
  21. "type": "string",
  22. "description": "Name of the contact"
  23. },
  24. "email": {
  25. "type": "string",
  26. "description": "Email of the contact"
  27. },
  28. "pubsub_token": {
  29. "type": "string",
  30. "description": "The token to be used to connect to chatwoot websocket"
  31. }
  32. }
  33. }
  34. body: {
  35. "source_id": "c9e8c31f-06df-49b4-8fb9-4466457ae65b",
  36. "pubsub_token": "Zgc7DEvaj5TkgZ1a4C7AvJXo",
  37. "id": 3293,
  38. "name": "restless-snowflake-670",
  39. "email": null,
  40. "phone_number": null
  41. }
  42. error [
  43. "The property '#/email' of type null did not match the following type: string in schema e56b7e65-d70c-5f7a-a96c-982df5f8f2f7"
  44. ]
  45. ...
  46. 804 examples, 565 failure, 0 pending
  47. Coverage: 65.51%

Coverage

And task will create HTML (coverage/fitting.html) reports.

exmaple

exmaple

More information on action coverage

exmaple2

exmaple2

Settings

APIs

type

OpenAPI 2.0

Swagger

  1. APIs:
  2. - host: www.example.com
  3. type: openapi2
  4. path: doc/api.json
OpenAPI 3.0

Also OpenAPI

  1. APIs:
  2. - host: www.example.com
  3. type: openapi3
  4. path: doc/api.json
API Blueprint

First you need to install drafter or crafter.
Works after conversion from API Blueprint to API Elements (in YAML file) with Drafter or Crafter.

That is, I mean that you first need to do this

  1. drafter doc.apib -o doc.yaml

or

  1. node_modules/.bin/crafter doc.apib > doc.yaml

and then

  1. APIs:
  2. - host: www.example.com
  3. type: drafter
  4. path: doc/api.yaml

or

  1. APIs:
  2. - host: www.example.com
  3. type: crafter
  4. path: doc/api.yaml
Tomograph

To use additional features of the pre-converted tomograph

example

  1. bundle exec tomograph -d crafter --exclude-description doc/api.yml doc/api.json

and then

  1. APIs:
  2. - host: www.example.com
  3. type: tomogram
  4. path: doc/api.json

prefix

Setting the prefix name is optional. For example, you can do this:

  1. APIs:
  2. - host: www.example.com
  3. prefix: /api/v3
  4. type: openapi2
  5. path: swagger/swagger.json

SkipValidation

host

It is not necessary to immediately describe each host in detail, you can only specify its name and skip it until you are ready to documented it

  1. SkipValidation:
  2. - host: api.cluster.dyte.in

prefix

If you want to skip a specific prefix in the host

  1. SkipValidation:
  2. - host: api.cluster.dyte.in
  3. prefix: /admin/api

method and path

If you want to skip a specific request in the host

  1. SkipValidation:
  2. - host: api.cluster.dyte.in
  3. method: GET
  4. path: /api/v1/cars

NoCov

It is not necessary to immediately test each doc in detail, you can only specify its name and skip it until you are ready to test it

host

  1. NoCov:
  2. - host: sso.test

method

  1. NoCov:
  2. - host: sso.test
  3. method: GET

path

  1. NoCov:
  2. - host: sso.test
  3. method: GET
  4. path: /users/{userId}

code

  1. NoCov:
  2. - host: sso.test
  3. method: GET
  4. path: /users/{userId}
  5. code: 200

content-type

  1. NoCov:
  2. - host: sso.test
  3. method: GET
  4. path: /users/{userId}
  5. code: 200
  6. content-type: application/json

combination

  1. NoCov:
  2. - host: sso.test
  3. method: GET
  4. path: /users/{userId}
  5. code: 200
  6. content-type: application/json
  7. combination: oneOf.0

combination_next

  1. NoCov:
  2. - host: sso.test
  3. method: GET
  4. path: /users/{userId}
  5. code: 200
  6. content-type: application/json
  7. combination: oneOf.0
  8. combination_next: oneOf.0.required.users

Debug

If you find bug, you can debug it or create task in this github project with new file coverage/fitting.debug.yml

  1. Debug:
  2. - host: www.example.com
  3. method: GET
  4. path: /api/v3/users
  5. code: 200
  6. content-type: application/json

Contributing

Bug reports and pull requests are welcome on GitHub at github.com/funbox/fitting.
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Sponsored by FunBox