How to define an example request body containing an array of complex objects in Swagger? - express

I am trying to write the Swagger spec for a service that posts an array of objects as request body. I would like the user to be able to test the service with a specific set of multiple different complex objects in the array as the default sample inputs.
So far I have the following code defining the service and complex object:
paths:
/myService
post:
summary: test 123
description: test 123
parameters:
- name: bodyParamsObject
description: 'Object containing any / all params in the body'
in: body
required: true
schema:
properties:
data:
$ref: '#/definitions/myInputArray'
responses:
200:
description: OK
schema: myOutputArray
definitions:
myInputArray:
type: array
items:
$ref: '#/definitions/myComplexObject'
myOutputArray:
type: array
items:
$ref: '#/definitions/myComplexObject'
myComplexObject:
type: object
properties:
description:
type: string
example: 'Example Item'
size:
example: 552
type: integer
format: int32
hasAdditionalProperties:
type: boolean
example: true
The output array is coming back correctly, but there is only one item in the model schema.
How can I make the sample request body contain multiple different items in the array?

I was able to solve this by using the example property on the object definition and filling it with the array in json.
definitions:
myInputArray:
type: array
items:
$ref: '#/definitions/myComplexObject'
example: [
{
"description": "Example Item 1",
"hasAdditionalProperties": true,
"size": 750,
},
{
"description": "Another example",
"hasAdditionalProperties": false,
"size": -22,
},
{
"description": "Last one",
"hasAdditionalProperties": true,
"size": 0,
}
]
myComplexObject:
type: object
properties:
description:
type: string
example: 'Example Item'
size:
example: 552
type: integer
format: int32
hasAdditionalProperties:
type: boolean
example: true

Related

How to describe a collection of thing as a vocabulary property in ALPS descriptor?

To describe REST APIs in an application-centric matter, I am trying out the ALPS descriptor and its toolings.
Say I have an object "Artwork", an artwork has the following properties: headline, artform, authors, etc.
How should I describe the property "authors"? In OpenAPI spec it is easy, simply say "type: Array", then specify reference under "items". What is the equivalent way of describe a collection in ALPS?
I am using YAML format to describe the API.
My current descriptors looks like this:
descriptors:
# vocabulary properties
- id: "identifier"
type: "semantic"
text: "Unique identifier within Alpha Org. This is not the serial number of the item. This identifier is automatically generated when a new artwork item is created in the system."
ref: "https://schema.org/identifier"
- id: "headline"
type: "semantic"
text: "Title of the artwork"
ref: "https://schema.org/headline"
- id: "artform"
type: "semantic"
text: "Form of the artwork: painting? photograph? sculpture? others?"
ref: "https://schema.org/artform"
- id: "authors"
type: "semantic"
text: "Authors of this artwork"
ref: "https://schema.org/author"
- id: "serialNumber"
type: "semantic"
text: "Serial number of the artwork. If the artwork does not have a serial number, such as an original painting from an artist, then this number is simply the examplar number, usually 1."
ref: "https://schema.org/serialNumber"
- id: "description"
type: "semantic"
text: "Description of the artwork"
ref: "https://schema.org/description"
- id: "obtainDate"
type: "semantic"
text: "Date on which Alpha Org obtained the ownership of this artwork."
ref: "https://schema.org/Date"
- id: "itemLocation"
type: "semantic"
text: "Location of the storage of the artwork item"
ref: "https://schema.org/itemLocation"
- id: "images"
type: "semantic"
text: "Images of the artwork"
ref: "https://schema.org/image"
ALPS descriptions don't make distinctions between single items and collections. From the model POV anything could be a collection, from the implementation POV, each service implementing that ALPS description makes their own decisions.
as a common practice, i typically use the IANA link-rel values when it is important
rel: item and rel: collection
there's a small utility (ALPS UNIFIED) that shows how to convert ALPS descriptions into OpenAPI definitions:
https://github.com/mamund/alps-unified

How can I retrieve nested values in Keystone 5 for my list

I'm adding a list called 'tourlocation' to my Keystone 5 project. In my mongo database my tourlocations collection has an object called 'coordinates', with two values: 'lat' and 'long'. Example:
"coordinates" : {
"lat" : 53.343761,
"long" : -6.24953
},
In the previous version of keystone, I could define my tourlocation list coordinates object like this:
coordinates: {
lat: {
type: Number,
noedit: true
},
long: {
type: Number,
noedit: true
}
Now unfortunately, when I try to define the list this way it gives the error: The 'tourlocation.coordinates' field doesn't specify a valid type. (tourlocation.coordinates.type is undefined)'
Is there any way to represent objects in keystone 5?
#Alex Hughes I believe your error says "type" which you may need to add it like this
keystone.createList('User', {
fields: {
name: { type: Text }, // Look at the type "Text" even in the MongoDB you can choose the type but it will be better to choose it here from the beginning.
email: { type: Text },
},
});
Note that noedit: true is not supported in version 5 of KeystoneJS.
For more info look at this page https://www.keystonejs.com/blog/field-types#core-field-types

Validate the json Array with Either one field required in Mule 4

Request Json Looks like the below :-
{
"eNumber": 8506493,
"details": [
{
"id":12345,
"name": xyz123
}
]
}
As part of requirement, I need to check the "details" array that either "id" or "name" field must present. if "id" field is present, "name" is non-mandatory. if "name" field is present, "id" is non-mandatory. Throws error if not met.
I tried few options using filter the details array and check the size of the filtered array in the validation component. It does not seems to be working well. if anyone has got better solutions.please share it here.
This example code will return true or false if it passes your condition
%dw 2.0
import * from dw::core::Arrays
output application/json
---
payload.details every ((item) -> item.id? or item.name?)
The function I'm using is every that checks that all elements in an array passes the given criteria.
Later you can use a choice and a use the raise error or you can use the fail dw function with an if else.
You can restrict it at RAML level.
Sample RAML -
#%RAML 1.0
title: api
types:
test1:
type: object
properties:
id:
type: string
example: 123a
test2:
type: object
properties:
name:
type: string
example: xyz124
test3:
type: object
properties:
enumber:
type: string
example: 8506493a
details :
type: [test1 | test2]
/test:
post:
body:
application/json:
type: test3

How to format a DELETE method in openapi 3.0.2?

I am having trouble figuring out a way to create a DELETE method for the POST method I just created in my API design. The post takes in a requestBody of the GlobalOrderSetupInfo, within that object there is another object that will be an array of different sessions that I want to add the GlobalOrderSetupInfo info to, in the delete method I need that same info deleted but you cannot have a delete method with a requestBody. How do I go about creating it?
Here is my post method:
'/api/globalorderdays':
post:
tags:
- Setup Global Order Days
summary: Allows user to add orderdays to multiple sessions
requestBody:
required: true
description: put text here
content:
application/json:
schema:
type: object
items:
$ref: '#/components/schemas/GlobalOrderSetupInfo'
responses:
'201':
description: Created
'400':
description: Bad request
'401':
description: Unauthorized
components:
schemas:
GlobalOrderSetupInfo:
description: 'Put Text Here'
type: object
properties:
Id:
type: integer
AvailableHolidayList:
type: string
SelectedOrderHolidays:
type: string
example: "New Year's Day, President's Day, Memorial Day, Labor Day, Veterans Day, Thanksgiving Day, Chistmas Day"
SelectedHolidays:
type: string
example: "New Year's Day, President's Day, Memorial Day, Labor Day, Veterans Day, Thanksgiving Day, Chistmas Day"
OrderDays:
type: string
example: "01/01/2000"
NoOrderDays:
type: string
example: "01/01/2000"
AllSessionList:
uniqueItems: false
type: array
items:
$ref: '#/components/schemas/SessionInfoList'
SessionIdString:
type: string
example: "15"
SessionInfoList:
description: 'Put Text Here'
type: object
properties:
Id:
type: integer
SessionID:
type: integer
Name:
type: string
example: "Harbor"
Type:
type: string
GroupName:
type: string
example: "PHACTS"
IsChecked:
type: boolean
default: false
example: true/false
SetupID:
type: string
Typically your POST method creates a new entity, and returns the id of that entity. Then you might have additional routes to GET that entity by ID, update (PATCH) it, or DELETE it.
So in your example, the entry for DELETE might look like:
'/api/globalorderdays/{id}':
parameters:
- in: path
name: id
required: true
schema:
type: integer
get:
summary: Get orderdays by id
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/GlobalOrderSetupInfo'
delete:
summary: Delete orderdays by id
responses:
'204':
description: Deleted
'404':
description: id not found
'401':
description: Unauthorized

Can't get the elements of the sencha store

So I have a store
Ext.define('APN.store.BackupShow', {
extend: 'Ext.data.Store',
requires: [
'APN.model.ScheduledShow'
],
config: {
model: 'APN.model.ScheduledShow',
proxy: {
type: 'ajax',
url: '',
reader: {
type: 'xml',
record: 'item',
rootProperty: 'xml'
}
}
},
getShow: function () {
if (this.getData().length greater 1) # by some reason stackoverflow didn't allow me to put greater sign in here;
return null;
// Copy field data across as wrong field is popped.
this.getAt(0).set("listimage", this.getAt(0).get("onairimage"));
this.getAt(0).set("isbackup", "true");
return this.getAt(0);
}
});
And when I'm trying to call the first element of the store I get undefined, however the element exists in the store:
(0) console.log(backupShowStore);
(1) console.log(backupShowStore.data);
(2) console.log(backupShowStore.getData().all);
(3) console.log(backupShowStore.getData().all.length);
(4) console.log(backupShowStore.getData().all.getAt(0));
I got back:
(1)
Class
_data: Class
_model: function () {
_modelDefaults: objectClass
_proxy: Class
_remoteFilter: false
_remoteSort: false
_storeId: "backupShow"
_totalCount: null
config: objectClass
data: Class
_autoFilter: true
_autoSort: true
_filterRoot: "data"
_sortRoot: "data"
all: Array[1]
0: Class
_data: Object
data: Object
bufferingProgress: null
contentlink: null
description: null
facebooklink: "http://www.facebook.com/mixmelbourne"
id: "ext-record-45"
isbackup: null
listimage: null
onairimage: "http://arntrnassets.mediaspanonline.com/radio/mxm/53808/on-air-default_v3.png"
showbody: "Melbourne's widest variety from 2K to today, Mix101.1 with Chrissie & Jane waking up Melbourne weekdays from 6am."
showbyline: "The widest variety from 2K to today"
showcontentxml: null
showemail: null
showname: "Mix 101.1"
showschedule: null
smallimage: null
title: null
twittername: "mixmelbourne"
__proto__: Object
id: "ext-record-45"
internalId: "ext-record-45"
modified: Object
phantom: true
raw: item
stores: Array[1]
__proto__: TemplateClass
length: 1
__proto__: Array[0]
(2)
_autoFilter: true
_autoSort: true
_filterRoot: "data"
_sortRoot: "data"
all: Array[1]
config: objectClass
dirtyIndices: true
getKey: function (record) {
indices: Object
initConfig: function (){}
initialConfig: Object
items: Array[1]
keys: Array[1]
length: 1
map: Object
__proto__: TemplateClass
(3)
Array[1]
0: Class
length: 1
__proto__: Array[0]
(4)
0
(5)
Uncaught TypeError: Object [object Array] has no method 'getAt'
Which is understandable for (5) as array doesn't have method getAt, however the store doesn't have any items and that is indicated by (4) where the array of getData elements equals to 0...
Am very confused at this point of time with Sencha Touch Framework and how to get the first element of an array of elements
Why not just use the Ext.data.Store.first() method.
I have found I am typically a happier developer when I use the methods provided by the api. On the rare occasion that I need something not provided I will navigate the Sencha Objects myself but I really try not to.
Let me know if and why that solution might not work and I'll try to find something else for you.