API Kit Router schema validation - mule

Is there a way to have the API Kit Router validate incoming schema? I have the following in my RAML file but it does not validate the incoming schema.
- emails: |
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type" : "object",
"properties" : {
"email" : {
"type" : "string"
},
"name" : {
"type" : "string"
},
"emailOrigin" : {
"type" : "string"
}
}
}
resourceTypes:
- postbase:
post:
responses:
200:
body:
application/json:
500:
body:
application/json:
- putBase:
put:
responses:
200:
body:
application/json:
500:
body:
application/json:
/emails:
type: postbase
post:
description: |
Recieve emails captured from various parts of the site.
body:
schema: emails

The following references help you further
http://forums.raml.org/t/examples-validations-in-raml-parsers/80
Further Example as below: employeeDetailsSchema.json
{
"type": "object",
"$schema": "http://json-schema.org/draft-03/schema",
"id": "http://jsonschema.net",
"required": true,
"properties": {
"employeeID": {
"type": "string", -------> Validates the Data type
"required": true -------> Validates whether data is present or not
},
"employeeFirstName": {
"type": "string",
"required": true
},
"employeeLastName": {
"type": "string",
"required": true
},
"employeeDOB": {
"type": "string",
"required": true
}
}
}
Schema file used in my RAML
#%RAML 0.8
title: ManageEmployees
version: 1.0
baseUri: http://api.acme.com/
mediaType: application/json
/newEmployee:
post:
description: Create new employees
body:
schema: !include com/ww/schema/employeeDetailsSchema.json
put:
description: Update employees details
body:
schema: !include com/ww/schema/employeeDetailsSchema.json
responses:
200:
body:
example: !include com/ww/schema/employeeExample.json

As far as I can see, any body will be valid for that schema.
All the fields are string, not required, not any specific format.
Try putting some of the fields as required and see what happens
Cheers!

Related

Forge - The category 'rfaFile' in '$(rfaFile)' is unrecognized

We are getting an error while executing a WorkItem in Forge's Design Automation API.
The error is this:
Error: The category 'rfaFile' in '$(rfaFile)' is unrecognized. Valid values are args, settings, appbundles, engine, engines.
And it happens right after the 'Start preparing script and command line parameters.' in the report.txt. We are not really sure why's this happening. It looks like the error is thrown in the activity. The activity looks like this:
function publishActivity() {
return $.ajax({
url: "/api/forge/design_automation/activities",
headers: {
"X-CSRF-Token": csrfToken,
"Forge-Token": forgeToken
},
method: "POST",
contentType: "application/json",
data: JSON.stringify({
activity: {
"id": "DeleteWallsActivity",
"commandLine": [ "$(engine.path)\\\\revitcoreconsole.exe /i \"$(args[rfaFile].path)\" /al \"$(appbundles[TestAppId].path)\"" ],
"parameters": {
"rfaFile": {
"zip": false,
"ondemand": false,
"verb": "get",
"description": "Input Revit model",
"required": true,
"localName": "$(rfaFile)"
},
"result": {
"zip": false,
"ondemand": false,
"verb": "put",
"description": "Results",
"required": true,
"localName": "result.rfa"
},
"inputJson": {
"verb": "get",
"description": "input json",
"localName": "params.json",
"ondemand": false,
"required": false,
"zip": false
}
},
"engine": "Autodesk.Revit+2021",
"appbundles": [ "petar3db.TestAppId+test" ],
"description": "Deletes walls from Revit file."
}
})
}).done(function(data) {
console.log("Activity created");
bundleUploadData = data["uploadParameters"];
}).fail(function(jqXHR, textStatus) {
console.log("Failed to create activity", jqXHR.responseJSON);
console.log(jqXHR, textStatus);
});
}
and it looks like the "localName": "$(rfaFile)" is causing the trouble.
Let's take a look at our WorkItem code which we execute via websockets:
{
"headers": {
"Authorization" : "Bearer <token here>"
},
"action": "post-workitem",
"data": {
"activityId": "petar3db.DeleteWallsActivity+test",
"arguments": {
"rfaFile": {"url": "https://developer.api.autodesk.com/oss/v2/signedresources/da992c60-a3d7-469d-8c3e-d0f089e2e509?region=US", "pathInZip": "emptyfam.rfa"},
"result": {"verb": "put", "url": "https://developer.api.autodesk.com/oss/v2/signedresources/b78151c1-93aa-495f-96c8-183bca26e071?region=US"},
"inputJson": {"localName": "params.json", "url": "the url to the file"}
}
}
}
the really strange part is that this process worked just fine and started throwing this error when we added "inputJson" into the activity and workItem. (We want to send some JSON data to the AppBundle with the WorkItem)
What can be the issue? Are missing something?
As for "localName": "$(rfaFile)", to be noted that if the local name is defined like this, Design Automation will come up a valid name for this argument by its own logic. If you want to fully control the input file, such as accessing it in the addin(Appbundles)'s code, it is recommended to define a "real" localName instead, e.g. "localName": "input.rfa"
In your case above, you may need to:
Remove /i \"$(args[rfaFile].path)\" from commandLine in the Activity
Define "localName": "inputRFA", so the input will be downloaded, unzipped as a folder named as inputRFA. emptyfam.rfa should be under this folder.
Call OpenDocumentFile in the addin to open a Revit file, get document
Call document.LoadFamily(".\inputRFA\emptyfam.rfa", out family); in the adding to open/load rfa file. See this Revit API
There is a mismatch in parameter name in activity with the argument name in workitem. Correct way to post the workitem should be:
{
"headers": {
"Authorization" : "Bearer <token here>"
},
"action": "post-workitem",
"data": {
"activityId": "petar3db.DeleteWallsActivity+test",
"arguments": {
"rfaFile": {"url": "https://developer.api.autodesk.com/oss/v2/signedresources/da992c60-a3d7-469d-8c3e-d0f089e2e509?region=US", "pathInZip": "emptyfam.rfa"},
"result": {"verb": "put", "url": "https://developer.api.autodesk.com/oss/v2/signedresources/b78151c1-93aa-495f-96c8-183bca26e071?region=US"},
"inputJson": {"localName": "params.json", "url": "the url to the file"}
}
}
}
Change the argument field rvtFile to rfaFile.

Unable to create epic using postman

URL: http://localhost:8080/rest/api/2/issue
body:
{
"fields":
{
"project":
{
"key": "DEMO"
},
"Epic Name": "Epic Name 01",
"summary": "REST EXAMPLE1",
"description":"Creating an Epic via REST",
"issuetype":
{
"name": "Epic"
}
}
}
Jira will return 415 Unsupported Media Type if Content-type wasn't specified.
Add to your header:
Content-Type: application/json
I tried this and it worked:
{
"fields": {
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"customfield_10104": "Epic Name 01",
"issuetype": {
"name": "Epic"
},
"project":
{
"key": "JIRA"
}
}
}
If you'd like to create an issue with "Epic Name" you should refernce it using it's customfield ID.
To get "Epic Name" customfield id: use the following rest:
http://localhost:2990/jira/rest/api/2/customFields?search=Name%20of%20Epic

Unable to resolve raml file errors

I have been given the attached RAML file to use in Mule but I am having problems working out how to clean up the errors in the file and not even sure this raml file conforms to standards. The errors I am getting are for missing {} and another is missing block entry when I remove the version. Can't figure out how to resolve them.
Below is a cut down version of the RAML:
#%RAML 0.8
---
title: Databox
version: v1
protocols: [HTTPS]
baseUri: https://databox/v1/{version}
mediaType: application/json
traits:
- http-data: !include http-data.raml
resourceTypes: !include types.raml
documentation:
- title: Home
content: |
Databox 1st draft
/stores:
type:
store:
description: Stores
dataSchema: !include stores.json
The traits (http-data.raml):
responses:
200:
description: |
Success
The resourceType (types.raml):
- store:
head:
description: Retrieve data for <<description>>.
is: [ http-data ]
get:
description: Retrieve data for <<description>>.
responses:
200:
body:
application/json:
schema: |
{
"type": "object",
"properties": {
"meta": {
"title": "Data",
"type": "object",
"properties": {
"createdOn": {
"type": "string",
"format": "date-time"
}
},
"required": [
"createdOn"
]
},
"data": {
"type": "array",
"items": <<dataSchema>>
}
},
"required": [
"data"
]
}
description: |
Success. Returns a JSON object containing all <<description>>.
The schema (stores.json):
{
"id": "http://localhost:8000/stores.json#",
"$schema": "http://json-schema.org/draft-04/schema",
"title": "Databox Store Schema",
"type": "object",
"properties": {
"storeId": {
"type": "string"
},
"storeDescription": {
"type": "string"
},
},
"required": [
"storeId"
],
"additionalProperties": false
}
Thanks
RAML is valid except for that <<dataSchema>> parameter used in the json schema, not sure if that's a valid use of parameters.
I would start by replacing that <<dataSchema>> for the json in stores.json and try again.
Let me know if that works or what errors you get.
UPDATE:
Mulesoft's anypoint portal validates your RAML with just that single change, you can see it here

Anypoint plateform mock throwing error for json Schema

I have created a raml in anypoint platform below is my RAML file
#%RAML 0.8
title: es-be-crm-dev
version: 001-dev
#baseUri: http://localhost:8081/api
baseUri: https://mocksvc.mulesoft.com/mocks/44267573-73b2-4369-8e2d- 3a6abbf20e34/api
traits:
- rate-limited:
queryParameters:
client_id:
type: string
client_secret:
type: string
schemas:
- api-request-schema: !include schemas/api-request-schema.json
/teams/{teamId}/teamMembers:
post:
description: Delete Team Member(s) from specified Team
headers:
Accept:
displayName: Accepted response format
description: Caller accepted response content Type
type: string
example: application/json
required: true
default: application/json
Content-Type:
displayName: body Mime Type
description: Caller accepted response content Type
type: string
example: application/json
required: true
default: application/json
body:
application/json:
schema: api-request-schema
example: !include examples/api-request-example.json
responses:
201:
description: Returned when the entity has been successfully created
headers:
ETag:
displayName: Entity Tag
description: Hash of the previously requested resource
type: string
example: asd8asd98hlk209u098asdfmoiun4023
required: false
401:
description: Returned when the user is not authorized to add a member
delete:
description: Adds Team Member(s) in specified Team
headers:
Accept:
displayName: Accepted response format
description: Caller accepted response content Type
type: string
example: application/json
required: true
default: application/json
Content-Type:
displayName: body Mime Type
description: Caller accepted response content Type
type: string
example: application/json
required: true
default: application/json
body:
application/json:
schema: api-request-schema
example: !include examples/api-request-example.json
responses:
201:
description: Returned when the entity has been successfully created
headers:
ETag:
displayName: Entity Tag
description: Hash of the previously requested resource
type: string
example: asd8asd98hlk209u098asdfmoiun4023
required: false
401:
description: Returned when the user is not authorized to delete a member
below is api-request-example.json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"teamMembers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"teamMember": {
"type": "object",
"properties": {
"empID": {
"type": "string"
},
"sourceSystemId": {
"type": "string"
},
"sourceSystemObjectId": {
"type": "string"
}
},
"required": [
"empID",
"sourceSystemId",
"sourceSystemObjectId"
]
}
},
"required": [
"teamMember"
]
}
}
},
"required": [
"teamMembers"
]
}
below is Example file
{
"teamMembers": [{
"teamMember": {
"empID": "d3193f53-5f07-e611-80e3-a45d36fc4f90",
"sourceSystemId": "abc",
"sourceSystemObjectId": "abc"
}
}]
}
whenever i try to mock my api in it throws an error with status code 400
{
"error": "schema did not parse: Unexpected token a"
}
is there anything that i am missing here ???
Has the error message says mule is not able to parse your schema and this is probably because the ApiKit version you are using does not support aliases.
That's way he says can't parse a.
Change it with a direct include
schema: !include api-request-schema.json
I know is not ideal but is just a little more to write.

How to describe response object in swagger, using yaml?

We have following json response for /papers/15
{
"data": [
{
"id": 1,
"title": "foo"
},
{
"id": 2,
"title": "bar"
}
],
"meta": {
"total": 15
}
}
Does anyone know how to describe it swagger yaml file?
Ok, I just figured out how to do this, in case somebody will need id.
Beside dedicated model definitions section ("definitions") it is possible to do inline model descriptions. Code above will looks like:
responses:
"200":
description: Matched Objects
schema:
type: object
properties:
data:
type: object
properties:
authors:
type: array
items:
$ref: "#/definitions/object_with_id_and_title"