Document DFC example body to create a product

This commit is contained in:
Maikel Linke
2023-06-26 15:57:52 +10:00
parent db77d1591c
commit df29eaab98
2 changed files with 39 additions and 17 deletions

View File

@@ -3,7 +3,8 @@
require "swagger_helper"
require DfcProvider::Engine.root.join("spec/spec_helper")
describe "SuppliedProducts", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml", rswag_autodoc: true do
describe "SuppliedProducts", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml",
rswag_autodoc: true do
let!(:user) { create(:oidc_user) }
let!(:enterprise) { create(:distributor_enterprise, owner: user) }
let!(:product) { create(:simple_product, supplier: enterprise ) }
@@ -22,27 +23,33 @@ describe "SuppliedProducts", type: :request, swagger_doc: "dfc-v1.7/swagger.yaml
# This parameter is required but I want to write a spec which doesn't
# supply it. I couldn't do it with rswag when requiring it.
parameter name: :supplied_product, in: :body, schema: {}, required: false
parameter name: :supplied_product, in: :body, required: false, schema: {
example: {
'@context': "http://static.datafoodconsortium.org/ontologies/context.json",
'@id': "http://test.host/api/dfc-v1.7/enterprises/6201/supplied_products/0",
'@type': "dfc-b:SuppliedProduct",
'dfc-b:name': "Apple",
'dfc-b:description': "A delicious heritage apple",
'dfc-b:hasType': "dfc-pt:non-local-vegetable",
'dfc-b:hasQuantity': {
'@type': "dfc-b:QuantitativeValue",
'dfc-b:hasUnit': "dfc-m:Gram",
'dfc-b:value': 3.0
},
'dfc-b:alcoholPercentage': 0.0,
'dfc-b:lifetime': "",
'dfc-b:usageOrStorageCondition': "",
'dfc-b:totalTheoreticalStock': 0.0
}
}
response "400", "bad request" do
run_test!
end
response "204", "success" do
let(:supplied_product) do
{
"@context": "http://static.datafoodconsortium.org/ontologies/context.json",
"@id": "http://test.host/api/dfc-v1.7/enterprises/6201/supplied_products/0",
"@type": "dfc-b:SuppliedProduct",
"dfc-b:name": "Apple",
"dfc-b:description": "A delicious heritage apple",
"dfc-b:hasType":"dfc-pt:non-local-vegetable",
"dfc-b:hasQuantity":{"@type":"dfc-b:QuantitativeValue","dfc-b:hasUnit":"dfc-m:Gram","dfc-b:value":3.0},
"dfc-b:alcoholPercentage":0.0,
"dfc-b:lifetime":"",
"dfc-b:usageOrStorageCondition":"",
"dfc-b:totalTheoreticalStock":0.0
}
let(:supplied_product) do |example|
example.metadata[:operation][:parameters].first[:schema][:example]
end
it "creates a variant" do |example|

View File

@@ -116,7 +116,22 @@ paths:
requestBody:
content:
application/json:
schema: {}
schema:
example:
"@context": http://static.datafoodconsortium.org/ontologies/context.json
"@id": http://test.host/api/dfc-v1.7/enterprises/6201/supplied_products/0
"@type": dfc-b:SuppliedProduct
dfc-b:name: Apple
dfc-b:description: A delicious heritage apple
dfc-b:hasType: dfc-pt:non-local-vegetable
dfc-b:hasQuantity:
"@type": dfc-b:QuantitativeValue
dfc-b:hasUnit: dfc-m:Gram
dfc-b:value: 3.0
dfc-b:alcoholPercentage: 0.0
dfc-b:lifetime: ''
dfc-b:usageOrStorageCondition: ''
dfc-b:totalTheoreticalStock: 0.0
"/api/dfc-v1.7/enterprises/{enterprise_id}/supplied_products/{id}":
parameters:
- name: enterprise_id