Refactor to make more use of schema refs, and regenerate swagger file

This commit is contained in:
Matt-Yorkley
2021-12-12 20:56:38 +00:00
committed by Maikel Linke
parent d87e1805af
commit 2e59812bc1
3 changed files with 163 additions and 491 deletions

View File

@@ -19,7 +19,7 @@ describe "Customers", type: :request do
response "200", "Customers list" do
param(:enterprise_id) { enterprise1.id }
schema CustomerSchema.collection(require_all: true)
schema "$ref": "#/components/schemas/resources/customers_collection"
run_test!
end
@@ -73,14 +73,14 @@ describe "Customers", type: :request do
enterprise_id: enterprise1.id.to_s
}
end
schema CustomerSchema.schema(require_all: true)
schema "$ref": "#/components/schemas/resources/customer"
run_test!
end
response "422", "Unprocessable entity" do
param(:customer) { {} }
schema ErrorsSchema.schema
schema "$ref": "#/components/schemas/error_response"
run_test!
end
@@ -95,14 +95,14 @@ describe "Customers", type: :request do
response "200", "Customer" do
param(:id) { customer1.id }
schema CustomerSchema.schema(require_all: true)
schema "$ref": "#/components/schemas/resources/customer"
run_test!
end
response "404", "Not found" do
param(:id) { 0 }
schema ErrorsSchema.schema
schema "$ref": "#/components/schemas/error_response"
run_test! do
expect(json_error_detail).to eq "The resource you were looking for could not be found."
@@ -114,7 +114,7 @@ describe "Customers", type: :request do
response "401", "Unauthorized" do
param(:id) { customer1.id }
schema ErrorsSchema.schema
schema "$ref": "#/components/schemas/error_response"
run_test! do
expect(json_error_detail).to eq "You are not authorized to perform that action."
@@ -161,7 +161,7 @@ describe "Customers", type: :request do
enterprise_id: enterprise1.id.to_s
}
end
schema CustomerSchema.schema(require_all: true)
schema "$ref": "#/components/schemas/resources/customer"
run_test!
end
@@ -169,7 +169,7 @@ describe "Customers", type: :request do
response "422", "Unprocessable entity" do
param(:id) { customer1.id }
param(:customer) { {} }
schema ErrorsSchema.schema
schema "$ref": "#/components/schemas/error_response"
run_test!
end
@@ -182,7 +182,7 @@ describe "Customers", type: :request do
response "200", "Customer deleted" do
param(:id) { customer1.id }
schema CustomerSchema.schema(require_all: true)
schema "$ref": "#/components/schemas/resources/customer"
run_test!
end
@@ -197,7 +197,7 @@ describe "Customers", type: :request do
response "200", "Customers list" do
param(:enterprise_id) { enterprise1.id }
schema CustomerSchema.collection(require_all: true)
schema "$ref": "#/components/schemas/resources/customers_collection"
run_test!
end

View File

@@ -27,7 +27,10 @@ RSpec.configure do |config|
components: {
schemas: {
error_response: ErrorsSchema.schema,
customer: CustomerSchema.schema
resources: {
customer: CustomerSchema.schema(require_all: true),
customers_collection: CustomerSchema.collection(require_all: true)
}
},
securitySchemas: {
api_key_header: {

View File

@@ -23,53 +23,150 @@ components:
- detail
required:
- errors
customer:
type: object
properties:
data:
type: object
properties:
id:
type: string
example: '1'
type:
type: string
example: customer
attributes:
resources:
customer:
type: object
properties:
data:
type: object
properties:
id:
type: string
example: '1'
type:
type: string
example: customer
attributes:
type: object
properties:
id:
type: integer
example: 1
enterprise_id:
type: integer
example: 2
first_name:
type: string
nullable: true
example: Alice
last_name:
type: string
nullable: true
example: Springs
code:
type: string
nullable: true
example: BUYER1
email:
type: string
example: alice@example.com
required:
- id
- enterprise_id
- first_name
- last_name
- code
- email
relationships:
type: object
properties:
enterprise:
"$ref": "#/components/schemas/relationship"
meta:
type: object
links:
type: object
required:
- data
customers_collection:
type: object
properties:
data:
type: array
items:
type: object
properties:
id:
type: integer
example: 1
enterprise_id:
type: integer
example: 2
first_name:
type: string
nullable: true
example: Alice
last_name:
example: '1'
type:
type: string
nullable: true
example: Springs
code:
type: string
nullable: true
example: BUYER1
email:
type: string
example: alice@example.com
required:
- enterprise_id
- email
relationships:
type: object
meta:
type: object
links:
type: object
required:
- data
example: customer
attributes:
type: object
properties:
id:
type: integer
example: 1
enterprise_id:
type: integer
example: 2
first_name:
type: string
nullable: true
example: Alice
last_name:
type: string
nullable: true
example: Springs
code:
type: string
nullable: true
example: BUYER1
email:
type: string
example: alice@example.com
required:
- id
- enterprise_id
- first_name
- last_name
- code
- email
relationships:
type: object
properties:
enterprise:
"$ref": "#/components/schemas/relationship"
meta:
type: object
properties:
pagination:
type: object
properties:
results:
type: integer
example: 250
pages:
type: integer
example: 5
page:
type: integer
example: 2
per_page:
type: integer
example: 50
required:
- pagination
links:
type: object
properties:
self:
type: string
first:
type: string
prev:
type: string
nullable: true
next:
type: string
nullable: true
last:
type: string
required:
- data
- meta
- links
securitySchemas:
api_key_header:
type: apiKey
@@ -103,91 +200,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
type: object
properties:
id:
type: string
example: '1'
type:
type: string
example: customer
attributes:
type: object
properties:
id:
type: integer
example: 1
enterprise_id:
type: integer
example: 2
first_name:
type: string
nullable: true
example: Alice
last_name:
type: string
nullable: true
example: Springs
code:
type: string
nullable: true
example: BUYER1
email:
type: string
example: alice@example.com
required:
- id
- enterprise_id
- first_name
- last_name
- code
- email
relationships:
type: object
meta:
type: object
properties:
pagination:
type: object
properties:
results:
type: integer
example: 250
pages:
type: integer
example: 5
page:
type: integer
example: 2
per_page:
type: integer
example: 50
required:
- pagination
links:
type: object
properties:
self:
type: string
first:
type: string
prev:
type: string
nullable: true
next:
type: string
nullable: true
last:
type: string
required:
- data
- meta
- links
"$ref": "#/components/schemas/resources/customers_collection"
post:
summary: Create customer
tags:
@@ -199,78 +212,13 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: object
properties:
id:
type: string
example: '1'
type:
type: string
example: customer
attributes:
type: object
properties:
id:
type: integer
example: 1
enterprise_id:
type: integer
example: 2
first_name:
type: string
nullable: true
example: Alice
last_name:
type: string
nullable: true
example: Springs
code:
type: string
nullable: true
example: BUYER1
email:
type: string
example: alice@example.com
required:
- id
- enterprise_id
- first_name
- last_name
- code
- email
relationships:
type: object
meta:
type: object
links:
type: object
required:
- data
"$ref": "#/components/schemas/resources/customer"
'422':
description: Unprocessable entity
content:
application/json:
schema:
type: object
properties:
errors:
type: array
items:
type: object
properties:
title:
type: string
detail:
type: string
source:
type: object
required:
- detail
required:
- errors
"$ref": "#/components/schemas/error_response"
requestBody:
content:
application/json:
@@ -315,100 +263,19 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: object
properties:
id:
type: string
example: '1'
type:
type: string
example: customer
attributes:
type: object
properties:
id:
type: integer
example: 1
enterprise_id:
type: integer
example: 2
first_name:
type: string
nullable: true
example: Alice
last_name:
type: string
nullable: true
example: Springs
code:
type: string
nullable: true
example: BUYER1
email:
type: string
example: alice@example.com
required:
- id
- enterprise_id
- first_name
- last_name
- code
- email
relationships:
type: object
meta:
type: object
links:
type: object
required:
- data
"$ref": "#/components/schemas/resources/customer"
'404':
description: Not found
content:
application/json:
schema:
type: object
properties:
errors:
type: array
items:
type: object
properties:
title:
type: string
detail:
type: string
source:
type: object
required:
- detail
required:
- errors
"$ref": "#/components/schemas/error_response"
'401':
description: Unauthorized
content:
application/json:
schema:
type: object
properties:
errors:
type: array
items:
type: object
properties:
title:
type: string
detail:
type: string
source:
type: object
required:
- detail
required:
- errors
"$ref": "#/components/schemas/error_response"
put:
summary: Update customer
tags:
@@ -425,78 +292,13 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: object
properties:
id:
type: string
example: '1'
type:
type: string
example: customer
attributes:
type: object
properties:
id:
type: integer
example: 1
enterprise_id:
type: integer
example: 2
first_name:
type: string
nullable: true
example: Alice
last_name:
type: string
nullable: true
example: Springs
code:
type: string
nullable: true
example: BUYER1
email:
type: string
example: alice@example.com
required:
- id
- enterprise_id
- first_name
- last_name
- code
- email
relationships:
type: object
meta:
type: object
links:
type: object
required:
- data
"$ref": "#/components/schemas/resources/customer"
'422':
description: Unprocessable entity
content:
application/json:
schema:
type: object
properties:
errors:
type: array
items:
type: object
properties:
title:
type: string
detail:
type: string
source:
type: object
required:
- detail
required:
- errors
"$ref": "#/components/schemas/error_response"
requestBody:
content:
application/json:
@@ -543,56 +345,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: object
properties:
id:
type: string
example: '1'
type:
type: string
example: customer
attributes:
type: object
properties:
id:
type: integer
example: 1
enterprise_id:
type: integer
example: 2
first_name:
type: string
nullable: true
example: Alice
last_name:
type: string
nullable: true
example: Springs
code:
type: string
nullable: true
example: BUYER1
email:
type: string
example: alice@example.com
required:
- id
- enterprise_id
- first_name
- last_name
- code
- email
relationships:
type: object
meta:
type: object
links:
type: object
required:
- data
"$ref": "#/components/schemas/resources/customer"
"/api/v1/enterprises/{enterprise_id}/customers":
get:
summary: List customers of an enterprise
@@ -611,90 +364,6 @@ paths:
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
type: object
properties:
id:
type: string
example: '1'
type:
type: string
example: customer
attributes:
type: object
properties:
id:
type: integer
example: 1
enterprise_id:
type: integer
example: 2
first_name:
type: string
nullable: true
example: Alice
last_name:
type: string
nullable: true
example: Springs
code:
type: string
nullable: true
example: BUYER1
email:
type: string
example: alice@example.com
required:
- id
- enterprise_id
- first_name
- last_name
- code
- email
relationships:
type: object
meta:
type: object
properties:
pagination:
type: object
properties:
results:
type: integer
example: 250
pages:
type: integer
example: 5
page:
type: integer
example: 2
per_page:
type: integer
example: 50
required:
- pagination
links:
type: object
properties:
self:
type: string
first:
type: string
prev:
type: string
nullable: true
next:
type: string
nullable: true
last:
type: string
required:
- data
- meta
- links
"$ref": "#/components/schemas/resources/customers_collection"
servers:
- url: "/"