How to change resource way , to support multiple future instances in Raml like city and airport? - api

/{ca}/{en}/{v1}:
uriParameters:
ca:
description: Country of users have to specify with two letter country code.
type: string
required: true
minLength: 2
maxLength: 2
en:
description: Language have to specified either English or French.
enum: [en,fr]
type: string
required: true
v1:
description: The version of the API need to be either v1 or v2.
enum: [v1,v2]
type: string
required: true

Related

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

RAML Max length of an item in a String array

I am defining a RAML spec. I have an attribute to hold an array of string. I want to make a rule that a string value in the array can have only maximum 3 charactors only (For example: regions: ["wes","nrh"] is valid. regions: ["lenghthyvalue", "anotherLenghthyvalue"] invalid). How can I handle it in RAML. My current code is as following:
regions:
type: string []
required: true
Available attributes are maxItems only. How to limit the character length of an item ?
I use raml 1.0
First create a string type that has maxLength and minLength attributes. Then you can reference that type in your array type instead of just a string array. Example:
#%RAML 1.0
title: test
version: 1.0
types:
region:
type: string
minLength: 3
maxLength: 3
regions:
type: region []
required: true
/test:
get:
queryParameters:
regions: region

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

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

Make some of the query parameters dependent in RAML

I am writing an api spec with RAML. I have a GET api with three query parameters. One of them is optional. In the case of other two, one of them should be present at least. How do I define this in the api spec
/api
description: api end point
queryParameters:
field1:
description: field1
required: false
type: string
field2:
description: field2
required: false
type: string
field3:
description: field3
required: false
type: string
Here field1 is completely optional. It is ok if we don't have it. But out of the other two, either field2 or field3 should be present.
So the api call should be
/api?field2=value or /api?field3=value
How do I do this in raml?
You can split the query params in two types (one for every combination) and use a union type:
types:
oneParam:
properties:
field1:
description: field1
required: false
type: string
field3:
description: field3
type: string
otherParam:
properties:
field1:
description: field1
required: false
type: string
field2:
description: field2
type: string
/api:
description: api end point
get:
queryParameters:
type: oneParam | otherParam
If you want to force so that the bad request is returned in case of no parameter is passed, then you can try to use minProperties:
{types:
oneParam:
**minProperties: 1**
properties:
field1:
description: field1
required: false
type: string
field3:
description: field3
type: string
otherParam:
**minProperties: 1**
properties:
field1:
description: field1
required: false
type: string
field2:
description: field2
type: string
/api:
description: api end point
get:
queryParameters:
type: oneParam | otherParam
}

How to write "ON UPDATE" using orm file

I am currently working on symfony2 project. I have one entity caller 'User'. For creating entity I am using orm file. I have created 'User' table using the following snippet.
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
email:
type: string
length: '50'
nullable: true
password:
type: text
nullable: true
name:
type: string
length: '50'
sex:
type: boolean
nullable: true
mobile:
type: bigint
nullable: true
landline:
type: bigint
nullable: true
dob:
type: date
nullable: true
Now I want to add two columns "CREATED ON" and "UPDATED ON" which stores the timestamp.
I want something like this
`Created on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Updated on` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP,
Is there any way for doing this in orm.yml file?
You can use the Doctrine Extensions which implement a Timestampable behavior to Doctrine such as explain here:
https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/timestampable.md
But check which version you must use (depend on Doctrine), you can find this info in the README:
https://github.com/Atlantic18/DoctrineExtensions
Use https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/timestampable.md
This would be your additional attributes for the ORM
createdAt:
type: datetime
gedmo:
timestampable:
on: create
column: created_at
updatedAt:
type: datetime
gedmo:
timestampable:
on: update
column: updated_at