Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean #1

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error"
/things:
/items:
get:
responses:
"200":
Expand All @@ -43,7 +43,7 @@ paths:
schema:
items:
$ref: "#/components/schemas/Item"
/things/{id}:
/items/{id}:
get:
parameters:
- $ref: "#/components/parameters/id"
Expand All @@ -54,7 +54,7 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Item"
/things/first5{format}:
/items/first5{format}:
get:
parameters:
- name: format
Expand Down
6 changes: 2 additions & 4 deletions examples/rails_app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ source "https://rubygems.org"
gem "rails"
gem "rspec"
gem "rspec-rails"
# gem "skooma", (ENV["CI"] == "1") ? {path: File.join(__dir__, "..", "..")} : {}
gem "skooma", {path: File.join(__dir__, "..", "..")}
gem "sinatra"
gem "puma"
gem "skooma", (ENV["CI"] == "1") ? {path: File.join(__dir__, "..", "..")} : {}
gem "sinatra"
3 changes: 1 addition & 2 deletions examples/rails_app/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

require_relative "app"

run Rails.application
# Rails.application.load_server
run Rails.application
50 changes: 48 additions & 2 deletions examples/rails_app/docs/bar_openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,44 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error"

/items:
get:
responses:
"200":
description: OK
content:
application/json:
schema:
items:
$ref: "#/components/schemas/Item"
/items/{id}:
get:
parameters:
- $ref: "#/components/parameters/id"
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Item"
/items/first5{format}:
get:
parameters:
- name: format
in: path
required: false
schema:
type: string
pattern: '.(xml|json)'
responses:
"200":
description: OK
content:
application/json:
schema:
items:
$ref: "#/components/schemas/Item"
components:
schemas:
Item:
Expand All @@ -43,11 +80,20 @@ components:
properties:
foo:
type: string
enum: [bar, baz, qux, quux, corge, grault, garply, waldo, fred, plugh, xyzzy, thud]
enum: [bar, qux, quux, corge, grault, garply, waldo, fred, plugh, xyzzy, thud]
Error:
type: object
unevaluatedProperties: false
required: [message]
properties:
message:
type: string
IntegerString:
type: string
pattern: '\d+'
parameters:
id:
name: id
in: path
schema:
$ref: "#/components/schemas/IntegerString"
50 changes: 48 additions & 2 deletions examples/rails_app/docs/baz_openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,44 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error"

/items:
get:
responses:
"200":
description: OK
content:
application/json:
schema:
items:
$ref: "#/components/schemas/Item"
/items/{id}:
get:
parameters:
- $ref: "#/components/parameters/id"
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Item"
/items/first5{format}:
get:
parameters:
- name: format
in: path
required: false
schema:
type: string
pattern: '.(xml|json)'
responses:
"200":
description: OK
content:
application/json:
schema:
items:
$ref: "#/components/schemas/Item"
components:
schemas:
Item:
Expand All @@ -43,11 +80,20 @@ components:
properties:
foo:
type: string
enum: [bar, baz, qux, quux, corge, grault, garply, waldo, fred, plugh, xyzzy, thud]
enum: [baz, qux, quux, corge, grault, garply, waldo, fred, plugh, xyzzy, thud]
Error:
type: object
unevaluatedProperties: false
required: [message]
properties:
message:
type: string
IntegerString:
type: string
pattern: '\d+'
parameters:
id:
name: id
in: path
schema:
$ref: "#/components/schemas/IntegerString"
91 changes: 0 additions & 91 deletions examples/rails_app/docs/parent.rb

This file was deleted.

6 changes: 2 additions & 4 deletions examples/rails_app/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
end
config.shared_context_metadata_behavior = :apply_to_host_groups

# bar_openapi = File.join(__dir__, "..", "docs", "bar_openapi.yml")
bar_openapi = File.join(__dir__, "..", "..", "openapi.yml")
# baz_openapi = File.join(__dir__, "..", "docs", "baz_openapi.yml")
baz_openapi = File.join(__dir__, "..", "..", "openapi.yml")
bar_openapi = File.join(__dir__, "..", "docs", "bar_openapi.yml")
baz_openapi = File.join(__dir__, "..", "docs", "baz_openapi.yml")

# You can use different RSpec filters if you want to test different API descriptions.
# Check RSpec's config.define_derived_metadata for better UX.
Expand Down
22 changes: 11 additions & 11 deletions examples/rails_app/spec/requests/bar/bar_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

describe "Bar API", :bar_api, type: :request do
xdescribe "GET /bar" do
describe "GET /bar" do
subject { get "/bar" }

it { is_expected.to conform_schema(200) }
Expand All @@ -12,7 +12,7 @@
end
end

xdescribe "POST /bar" do
describe "POST /bar" do
subject { post("/bar", params: body, as: :json) }

let(:body) { {foo: "bar"} }
Expand All @@ -26,35 +26,35 @@
end
end

xdescribe "GET /things" do
subject { get("/bar/things") }
describe "GET /items" do
subject { get("/bar/items") }

it { is_expected.to conform_schema(200) }
end

describe "GET /things/first5" do
xcontext "with .json" do
subject { get("/bar/things/first5.json") }
describe "GET /items/first5" do
context "with .json" do
subject { get("/bar/items/first5.json") }

it { is_expected.to conform_schema(200) }
end

context "without .json" do
subject { get("/bar/things/first5") }
subject { get("/bar/items/first5") }

it { is_expected.to conform_schema(200) }
end
end

xdescribe "GET /things/:id" do
describe "GET /items/:id" do
context "with valid params" do
subject { get("/bar/things/1") }
subject { get("/bar/items/1") }

it { is_expected.to conform_schema(200) }
end

context "with valid params outside of the range" do
subject { get("/bar/things/33") }
subject { get("/bar/items/33") }

it { is_expected.to conform_schema(200) }
end
Expand Down
17 changes: 8 additions & 9 deletions examples/test_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

module TestApp
def self.[](value)
things = [
{"foo" => "bar"},
{"foo" => "baz"},
items = [
{"foo" => value},
{"foo" => "qux"},
{"foo" => "quux"},
{"foo" => "corge"},
Expand Down Expand Up @@ -38,20 +37,20 @@ def self.[](value)
end
end

get "/things" do
get "/items" do
content_type :json
JSON.generate(things)
JSON.generate(items)
end

get /\/things\/(\d+)/ do |id|
get /\/items\/(\d+)/ do |id|
content_type :json
JSON.generate(things[id.to_i])
JSON.generate(items[id.to_i])
end

get /\/things\/first5((\.(xml|json))?)/ do
get /\/items\/first5((\.(xml|json))?)/ do
format = params['captures']
content_type :json
JSON.generate(things[0..4])
JSON.generate(items[0..4])
end
end
end
Expand Down
Loading