Skip to content

Commit

Permalink
Merge pull request #264 from interagent/feature/openapi3_example
Browse files Browse the repository at this point in the history
add openapi3 example
  • Loading branch information
ota42y authored May 9, 2020
2 parents 34190bb + e7e77a1 commit 942c88b
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
*.sw*
tags
Gemfile.lock
!/examples/openapi3/Gemfile.lock
!/examples/json_schema/Gemfile.lock
.DS_Store
/coverage/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions examples/openapi3/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "https://rubygems.org"

gem "committee", path: "../../"
gem "sinatra"
35 changes: 35 additions & 0 deletions examples/openapi3/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
PATH
remote: ../..
specs:
committee (3.3.0)
json_schema (~> 0.14, >= 0.14.3)
openapi_parser (>= 0.6.1)
rack (>= 1.5)

GEM
remote: https://rubygems.org/
specs:
json_schema (0.20.8)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
openapi_parser (0.10.0)
rack (2.2.2)
rack-protection (2.0.8.1)
rack
ruby2_keywords (0.0.2)
sinatra (2.0.8.1)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.8.1)
tilt (~> 2.0)
tilt (2.0.10)

PLATFORMS
ruby

DEPENDENCIES
committee!
sinatra

BUNDLED WITH
1.17.3
30 changes: 30 additions & 0 deletions examples/openapi3/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "committee"
require "json"
require "securerandom"
require "sinatra/base"
require "yaml"

class App < Sinatra::Base
SCHEMA_PATH = File.expand_path("../openapi.yaml", __FILE__)
use Committee::Middleware::RequestValidation, schema_path: SCHEMA_PATH, strict: true, raise: true
use Committee::Middleware::ResponseValidation, schema_path: SCHEMA_PATH

# This handler is called into, but its response is ignored.
get "/apps" do
end

# This handler suppresses the stubbed response and returns its own.
get "/posts" do
content_type :json
status 204
end

post "/dont_allow_additional_parameter" do
content_type :json
status 204
end
end

if __FILE__ == $0
App.run! port: 5000
end
44 changes: 44 additions & 0 deletions examples/openapi3/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
openapi: 3.0.0
info:
title: api-test
version: '1.0'
servers:
- url: 'http://localhost:3000'
description: dev
paths:
/posts:
get:
parameters:
- in: query
name: page
required: true
schema:
type: integer
responses:
'200':
description: No Content
content:
application/json:
schema:
type: object

/dont_allow_additional_parameter:
post:
requestBody:
content:
application/json:
schema:
type: object
additionalProperties: false
required:
- only_param
properties:
only_param:
type: string
responses:
'200':
description: No Content
content:
application/json:
schema:
type: object

0 comments on commit 942c88b

Please sign in to comment.