2022-11-07 12:23:54 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
# Specify a root folder where Swagger JSON files are generated
|
|
|
|
# NOTE: If you're using the rswag-api to serve API descriptions, you'll need
|
|
|
|
# to ensure that it's configured to serve Swagger from the same folder
|
|
|
|
config.swagger_root = Rails.root.join('swagger').to_s
|
|
|
|
|
|
|
|
# Define one or more Swagger documents and provide global metadata for each one
|
|
|
|
# When you run the 'rswag:specs:swaggerize' rake task, the complete Swagger will
|
|
|
|
# be generated at the provided relative path under swagger_root
|
|
|
|
# By default, the operations defined in spec files are added to the first
|
|
|
|
# document below. You can override this behavior by adding a swagger_doc tag to the
|
|
|
|
# the root example_group in your specs, e.g. describe '...', swagger_doc: 'v2/swagger.json'
|
|
|
|
config.swagger_docs = {
|
|
|
|
'v1/swagger.yaml' => {
|
2022-11-21 15:54:47 +01:00
|
|
|
openapi: '3.0.3',
|
2022-11-07 12:23:54 +01:00
|
|
|
info: {
|
|
|
|
title: 'API V1',
|
|
|
|
version: 'v1'
|
|
|
|
},
|
|
|
|
paths: {},
|
|
|
|
components: {
|
2022-11-21 12:49:53 +01:00
|
|
|
schemas: {
|
2022-11-28 17:30:20 +01:00
|
|
|
pagination: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
recordCount: { type: :integer },
|
|
|
|
pageCount: { type: :integer },
|
|
|
|
currentPage: { type: :integer },
|
|
|
|
pageSize: { type: :integer }
|
|
|
|
},
|
|
|
|
required: %w(recordCount pageCount currentPage pageSize)
|
|
|
|
},
|
2022-12-01 18:45:18 +01:00
|
|
|
Order: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: :string,
|
|
|
|
description: "name of the order's supplier (or stock)"
|
|
|
|
},
|
|
|
|
starts: {
|
|
|
|
type: :string,
|
|
|
|
format: 'date-time',
|
|
|
|
description: 'when the order was opened'
|
|
|
|
},
|
|
|
|
ends: {
|
2022-12-12 12:18:04 +01:00
|
|
|
type: :string,
|
|
|
|
nullable: true,
|
2022-12-01 18:45:18 +01:00
|
|
|
format: 'date-time',
|
|
|
|
description: 'when the order will close or was closed'
|
|
|
|
},
|
|
|
|
boxfill: {
|
2022-12-12 12:18:04 +01:00
|
|
|
type: :string,
|
|
|
|
nullable: true,
|
2022-12-01 18:45:18 +01:00
|
|
|
format: 'date-time',
|
|
|
|
description: 'when the order will enter or entered the boxfill phase'
|
|
|
|
},
|
|
|
|
pickup: {
|
2022-12-12 12:18:04 +01:00
|
|
|
type: :string,
|
|
|
|
nullable: true,
|
2022-12-01 18:45:18 +01:00
|
|
|
format: :date,
|
|
|
|
description: 'pickup date'
|
|
|
|
},
|
|
|
|
is_open: {
|
|
|
|
type: :boolean,
|
|
|
|
description: 'if the order is currently open or not'
|
|
|
|
},
|
|
|
|
is_boxfill: {
|
|
|
|
type: :boolean,
|
|
|
|
description: 'if the order is currently in the boxfill phase or not'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-11-28 17:30:20 +01:00
|
|
|
Article: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: :string
|
|
|
|
},
|
|
|
|
supplier_id: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'id of supplier, or 0 for stock articles'
|
|
|
|
},
|
|
|
|
supplier_name: {
|
2022-12-12 12:18:04 +01:00
|
|
|
type: :string,
|
|
|
|
nullable: true,
|
2022-11-28 17:30:20 +01:00
|
|
|
description: 'name of the supplier, or null for stock articles'
|
|
|
|
},
|
|
|
|
unit: {
|
|
|
|
type: :string,
|
|
|
|
description: 'amount of each unit, e.g. "100 g" or "kg"'
|
|
|
|
},
|
|
|
|
unit_quantity: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'units can only be ordered from the supplier in multiples of unit_quantity'
|
|
|
|
},
|
|
|
|
note: {
|
2022-12-12 12:18:04 +01:00
|
|
|
type: :string,
|
|
|
|
nullable: true,
|
2022-11-28 17:30:20 +01:00
|
|
|
description: 'generic note'
|
|
|
|
},
|
|
|
|
manufacturer: {
|
2022-12-12 12:18:04 +01:00
|
|
|
type: :string,
|
|
|
|
nullable: true,
|
2022-11-28 17:30:20 +01:00
|
|
|
description: 'manufacturer'
|
|
|
|
},
|
|
|
|
origin: {
|
2022-12-12 12:18:04 +01:00
|
|
|
type: :string,
|
|
|
|
nullable: true,
|
2022-11-28 17:30:20 +01:00
|
|
|
description: 'origin, preferably (starting with a) 2-letter ISO country code'
|
|
|
|
},
|
|
|
|
article_category_id: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'id of article category'
|
|
|
|
},
|
|
|
|
quantity_available: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'number of units available (only present on stock articles)'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
required: %w[id name supplier_id supplier_name unit unit_quantity note manufacturer origin article_category_id]
|
|
|
|
},
|
|
|
|
OrderArticle: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer
|
|
|
|
},
|
|
|
|
order_id: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'id of order this order article belongs to'
|
|
|
|
},
|
|
|
|
price: {
|
2022-12-01 17:57:02 +01:00
|
|
|
type: :number,
|
|
|
|
format: :float,
|
2022-11-28 17:30:20 +01:00
|
|
|
description: 'foodcoop price'
|
|
|
|
},
|
|
|
|
quantity: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'number of units ordered by members'
|
|
|
|
},
|
|
|
|
tolerance: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'number of extra units that members are willing to buy to fill a box'
|
|
|
|
},
|
|
|
|
units_to_order: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'number of units to order from the supplier'
|
|
|
|
},
|
|
|
|
article: {
|
|
|
|
'$ref': '#/components/schemas/Article'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-11-21 17:06:51 +01:00
|
|
|
ArticleCategory: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: :string
|
|
|
|
}
|
|
|
|
},
|
|
|
|
required: %w[id name]
|
|
|
|
},
|
2022-11-28 13:19:50 +01:00
|
|
|
FinancialTransaction: {
|
2022-12-12 13:30:32 +01:00
|
|
|
allOf: [
|
|
|
|
{ '$ref': '#/components/schemas/FinancialTransactionForCreate' },
|
2022-11-29 21:37:45 +01:00
|
|
|
{
|
2022-12-12 13:30:32 +01:00
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer
|
|
|
|
},
|
|
|
|
amount: {
|
2022-12-12 16:33:17 +01:00
|
|
|
type: :number,
|
|
|
|
format: :float,
|
2022-12-12 13:30:32 +01:00
|
|
|
description: 'amount credited (negative for a debit transaction)'
|
|
|
|
},
|
2022-12-12 16:02:43 +01:00
|
|
|
financial_transaction_type_id: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'id of the type of the transaction'
|
|
|
|
},
|
2022-12-12 13:30:32 +01:00
|
|
|
note: {
|
|
|
|
type: :string,
|
|
|
|
description: 'note entered with the transaction'
|
|
|
|
},
|
|
|
|
user_id: {
|
|
|
|
type: :integer,
|
|
|
|
nullable: true,
|
|
|
|
description: 'id of user who entered the transaction (may be <tt>null</tt> for deleted users or 0 for a system user)'
|
|
|
|
},
|
|
|
|
user_name: {
|
|
|
|
type: :string,
|
|
|
|
nullable: true,
|
|
|
|
description: 'name of user who entered the transaction (may be <tt>null</tt> or empty string for deleted users or system users)'
|
|
|
|
},
|
|
|
|
financial_transaction_type_name: {
|
|
|
|
type: :string,
|
|
|
|
description: 'name of the type of the transaction'
|
|
|
|
},
|
|
|
|
created_at: {
|
|
|
|
type: :string,
|
|
|
|
format: 'date-time',
|
|
|
|
description: 'when the transaction was entered'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
required: %w[id user_id user_name financial_transaction_type_name created_at]
|
2022-11-29 21:37:45 +01:00
|
|
|
}
|
2022-12-12 13:30:32 +01:00
|
|
|
]
|
2022-11-29 21:37:45 +01:00
|
|
|
},
|
|
|
|
FinancialTransactionForCreate: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
amount: {
|
2022-12-12 16:33:17 +01:00
|
|
|
type: :number,
|
|
|
|
format: :float,
|
2022-11-29 21:37:45 +01:00
|
|
|
description: 'amount credited (negative for a debit transaction)'
|
|
|
|
},
|
|
|
|
financial_transaction_type_id:
|
|
|
|
{
|
|
|
|
type: :integer,
|
|
|
|
description: 'id of the type of the transaction'
|
|
|
|
},
|
|
|
|
note: {
|
|
|
|
type: :string,
|
|
|
|
description: 'note entered with the transaction'
|
2022-11-28 13:19:50 +01:00
|
|
|
}
|
|
|
|
},
|
2022-11-29 18:55:45 +01:00
|
|
|
required: %w[amount note user_id]
|
2022-11-28 13:19:50 +01:00
|
|
|
},
|
2022-11-25 14:52:02 +01:00
|
|
|
FinancialTransactionClass: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: :string
|
|
|
|
}
|
|
|
|
},
|
|
|
|
required: %w[id name]
|
|
|
|
},
|
2022-11-28 13:19:50 +01:00
|
|
|
FinancialTransactionType: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: :string
|
2022-12-12 12:18:04 +01:00
|
|
|
},
|
|
|
|
name_short: {
|
|
|
|
type: :string,
|
|
|
|
nullable: true,
|
|
|
|
description: 'short name (used for bank transfers)'
|
|
|
|
},
|
|
|
|
bank_account_id: {
|
|
|
|
type: :integer,
|
|
|
|
nullable: true,
|
|
|
|
description: 'id of the bank account used for this transaction type'
|
|
|
|
},
|
|
|
|
bank_account_name: {
|
|
|
|
type: :string,
|
|
|
|
nullable: true,
|
|
|
|
description: 'name of the bank account used for this transaction type'
|
|
|
|
},
|
|
|
|
bank_account_iban: {
|
|
|
|
type: :string,
|
|
|
|
nullable: true,
|
|
|
|
description: 'IBAN of the bank account used for this transaction type'
|
|
|
|
},
|
|
|
|
financial_transaction_class_id: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'id of the class of the transaction'
|
|
|
|
},
|
|
|
|
financial_transaction_class_name: {
|
|
|
|
type: :string,
|
|
|
|
description: 'name of the class of the transaction'
|
2022-11-28 13:19:50 +01:00
|
|
|
}
|
|
|
|
},
|
2022-12-12 12:18:04 +01:00
|
|
|
required: %w[id name financial_transaction_class_id financial_transaction_class_name]
|
2022-11-28 13:19:50 +01:00
|
|
|
},
|
2022-12-02 16:37:54 +01:00
|
|
|
GroupOrderArticleForUpdate: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
quantity:
|
|
|
|
{
|
|
|
|
type: :integer,
|
|
|
|
description: 'number of units ordered by the users ordergroup'
|
|
|
|
},
|
|
|
|
tolerance:
|
|
|
|
{
|
|
|
|
type: :integer,
|
|
|
|
description: 'number of extra units the users ordergroup is willing to buy for filling a box'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
GroupOrderArticleForCreate: {
|
2022-12-12 16:33:17 +01:00
|
|
|
allOf: [
|
|
|
|
{ '$ref': '#/components/schemas/GroupOrderArticleForUpdate' },
|
2022-12-02 16:37:54 +01:00
|
|
|
{
|
2022-12-12 16:33:17 +01:00
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
order_article_id:
|
|
|
|
{
|
|
|
|
type: :integer,
|
|
|
|
description: 'id of order article'
|
|
|
|
}
|
|
|
|
}
|
2022-12-02 16:37:54 +01:00
|
|
|
}
|
2022-12-12 16:33:17 +01:00
|
|
|
]
|
2022-12-02 16:37:54 +01:00
|
|
|
},
|
|
|
|
GroupOrderArticle: {
|
2022-12-12 16:33:17 +01:00
|
|
|
allOf: [
|
|
|
|
{ '$ref': '#/components/schemas/GroupOrderArticleForCreate' },
|
2022-12-02 16:37:54 +01:00
|
|
|
{
|
2022-12-12 16:33:17 +01:00
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
type: :integer
|
|
|
|
},
|
|
|
|
result: {
|
|
|
|
type: :number,
|
|
|
|
format: :float,
|
|
|
|
description: 'number of units the users ordergroup will receive or has received'
|
|
|
|
},
|
|
|
|
total_price:
|
|
|
|
{
|
|
|
|
type: :number,
|
|
|
|
format: :float,
|
|
|
|
description: 'total price of this group order article'
|
|
|
|
},
|
|
|
|
order_article_id:
|
|
|
|
{
|
|
|
|
type: :integer,
|
|
|
|
description: 'id of order article'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
required: %w[order_article_id]
|
2022-12-02 16:37:54 +01:00
|
|
|
}
|
2022-12-12 16:33:17 +01:00
|
|
|
]
|
2022-12-02 16:37:54 +01:00
|
|
|
},
|
2022-12-12 16:59:17 +01:00
|
|
|
q_ordered: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
ordered: {
|
|
|
|
type: :string,
|
|
|
|
enum: %w[member all supplier]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-11-21 17:06:51 +01:00
|
|
|
Meta: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
page: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'page number of the returned collection'
|
|
|
|
},
|
|
|
|
per_page: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'number of items per page'
|
|
|
|
},
|
|
|
|
total_pages: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'total number of pages'
|
|
|
|
},
|
|
|
|
total_count: {
|
|
|
|
type: :integer,
|
|
|
|
description: 'total number of items in the collection'
|
2022-12-01 17:57:02 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
required: %w[page per_page total_pages total_count]
|
2022-11-21 17:06:51 +01:00
|
|
|
},
|
2022-11-21 15:54:47 +01:00
|
|
|
Navigation: {
|
|
|
|
type: :array,
|
|
|
|
items: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
name: {
|
|
|
|
type: :string,
|
|
|
|
description: 'title'
|
|
|
|
},
|
|
|
|
url: {
|
|
|
|
type: :string,
|
|
|
|
description: 'link'
|
|
|
|
},
|
|
|
|
items: {
|
|
|
|
'$ref': "#/components/schemas/Navigation"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
required: ['name'],
|
|
|
|
minProperties: 2 # name+url or name+items
|
|
|
|
}
|
|
|
|
},
|
2022-11-21 12:49:53 +01:00
|
|
|
Error: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
error: {
|
|
|
|
type: :string,
|
|
|
|
description: 'error code'
|
|
|
|
},
|
|
|
|
error_description: {
|
|
|
|
type: :string,
|
|
|
|
description: 'human-readable error message (localized)'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Error401: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
error: {
|
|
|
|
type: :string,
|
|
|
|
description: '<tt>unauthorized</tt>'
|
|
|
|
},
|
|
|
|
error_description: {
|
|
|
|
'$ref': '#/components/schemas/Error/properties/error_description'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Error403: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
error: {
|
|
|
|
type: :string,
|
|
|
|
description: '<tt>forbidden</tt> or <tt>invalid_scope</tt>'
|
|
|
|
},
|
|
|
|
error_description: {
|
|
|
|
'$ref': '#/components/schemas/Error/properties/error_description'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Error404: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
error: {
|
|
|
|
type: :string,
|
|
|
|
description: '<tt>not_found</tt>'
|
|
|
|
},
|
|
|
|
error_description: {
|
|
|
|
'$ref': '#/components/schemas/Error/properties/error_description'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Error422: {
|
|
|
|
type: :object,
|
|
|
|
properties: {
|
|
|
|
error: {
|
|
|
|
type: :string,
|
2022-12-02 16:37:54 +01:00
|
|
|
description: '<tt>unprocessable entity</tt>'
|
2022-11-21 12:49:53 +01:00
|
|
|
},
|
|
|
|
error_description: {
|
|
|
|
'$ref': '#/components/schemas/Error/properties/error_description'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-11-07 12:23:54 +01:00
|
|
|
securitySchemes: {
|
|
|
|
oauth2: {
|
|
|
|
type: :oauth2,
|
|
|
|
flows: {
|
|
|
|
implicit: {
|
|
|
|
authorizationUrl: 'http://localhost:3000/f/oauth/authorize',
|
|
|
|
scopes: {
|
|
|
|
'config:user': 'reading Foodsoft configuration for regular users',
|
|
|
|
'config:read': 'reading Foodsoft configuration values',
|
|
|
|
'config:write': 'reading and updating Foodsoft configuration values',
|
|
|
|
'finance:user': 'accessing your own financial transactions',
|
|
|
|
'finance:read': 'reading all financial transactions',
|
|
|
|
'finance:write': 'reading and creating financial transactions',
|
|
|
|
'user:read': 'reading your own user profile',
|
|
|
|
'user:write': 'reading and updating your own user profile',
|
2022-11-21 13:17:14 +01:00
|
|
|
offline_access: 'retain access after user has logged out'
|
2022-11-07 12:23:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
servers: [
|
|
|
|
{
|
|
|
|
url: 'http://{defaultHost}/f/api/v1',
|
|
|
|
variables: {
|
|
|
|
defaultHost: {
|
|
|
|
default: 'localhost:3000'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
security: [
|
|
|
|
oauth2: [
|
2022-11-21 13:17:14 +01:00
|
|
|
'user:read'
|
|
|
|
]
|
|
|
|
]
|
2022-11-07 12:23:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Specify the format of the output Swagger file when running 'rswag:specs:swaggerize'.
|
|
|
|
# The swagger_docs configuration option has the filename including format in
|
|
|
|
# the key, this may want to be changed to avoid putting yaml in json files.
|
|
|
|
# Defaults to json. Accepts ':json' and ':yaml'.
|
|
|
|
config.swagger_format = :yaml
|
|
|
|
end
|