RAML Unknown facet 'types' - anypoint-studio

I am receiving an issue with a datatype .raml file that I am attempting to create. For some reason, it is stating that I am 'Specifying unknown facet 'types' as an error.
What is the proper way to go about defining an object in RAML?
#%RAML 1.0 DataType
types:
Account:
type: object
displayName: Account
description: Salesforce Account Object
properties:
id:
type: string
description: Id of the Salesforce Account
ns_id:
type: string
description: Id of NetSuite Customer
name:
type: string
description: Name of Salesforce Account
phone:
type: string
description: Phone Number of Salesforce Account
website:
type: string
description: Website of the Salesforce Account
owner:
type: string # This probably needs to be of type Owner
description: Owner of Account
active_cmrr:
type: number
description: Active CMRR of Account
billing_address:
type: string
description: Billing Address of Account
subscription_start_date:
type: date-only
description: Salesforce Account Subscription Start Date
subscription_end_date:
type: date-only
description: Salesforce Account Subscription End Date
#Sometype of Opportunity list
#opportunities:
# type: Opportunity[]
# description: List of Account Opportunities

You are currently using a so called RAML fragment which focuses on a single definition only. In your case a single type definition.
You start defining multiple type definitions usually using types either in a root RAML file (indicated with #%RAML 1.0) or in a library (indicated with #%RAML 1.0 Library). So depending on what you try to achieve you either modify your data type fragment to only contain the definition of the Account type or you change #%RAML 1.0 DataType to #%RAML 1.0 Library so you can package multiple type definition into one; or you use both for max reusability.
Let me show you how to use both:
account.raml
#%RAML 1.0 DataType
type: object
displayName: Account
description: Salesforce Account Object
properties:
id:
type: string
description: Id of the Salesforce Account
ns_id:
type: string
description: Id of NetSuite Customer
name:
type: string
description: Name of Salesforce Account
phone:
type: string
description: Phone Number of Salesforce Account
website:
type: string
description: Website of the Salesforce Account
owner:
type: string # This probably needs to be of type Owner
description: Owner of Account
active_cmrr:
type: number
description: Active CMRR of Account
billing_address:
type: string
description: Billing Address of Account
subscription_start_date:
type: date-only
description: Salesforce Account Subscription Start Date
subscription_end_date:
type: date-only
description: Salesforce Account Subscription End Date
#Sometype of Opportunity list
#opportunities:
# type: Opportunity[]
# description: List of Account Opportunities
types.raml
#%RAML 1.0 Library
types:
Account: !include account.raml
In other type definition you could then use the library to reference to the account type. For example:
bank.raml
#%RAML 1.0 DataType
uses:
types: types.raml
type: object
properties:
branch: string
accounts:
type: array
items: types.Account
Hope that helps you! Let me know if you have any further questions.

Related

YAML code not well formed for S3 Bucket Encryption

Can someone tell me what i am doing wrong here. I am trying to enforce the S3 bucket to use the KMS key, which i am referencing, but the YAML format is incorrect. Can you advice. Thanks
TrailBucket:
Condition: InternalBucket
Type: 'AWS::S3::Bucket'
Properties: {
BucketEncryption:
ServerSideEncryptionConfiguration: *********
- ServerSideEncryptionByDefault:
SSEAlgorithm: !Ref Key
}
TrailBucketPolicy:
Condition: InternalBucket
Type: 'AWS::S3::BucketPolicy'
Properties:
Bucket: !Ref TrailBucket
PolicyDocument:
If i remove the brackets {}, then i get the following error message in cloud-formation
The XML you provided was not well-formed or did not validate against our published schema (Service: Amazon S3; Status Code: 400; Error Code: MalformedXML; Request ID:
Try removing the brackets and asterisks

Binary API documentation via swagger

I'm building an API that's able to upload multiple files at once. I need to document it through swagger, but I have no experience with it at all.
My schema for the API is as follows:
The http request body is an octet-stream that looks like this. The first 4 bytes represents the number of packages, let the number of packages be n. The next 4*n bytes represents the sizes of the packages, where the first 4 bytes is the size of the first package, the next 4 is the size of the second package, etc. The end of the request simply consists of the packages.
An example would be: The packages \xDE\xAD\xBE\xEF and \xFE\xED\xFA\xCE\xCA\xFE\xBE\xEF, would compose the request:
\x00\x00\x00\x02||\x00\x00\x00\x04\x00\x00\x00\x08||\xDE\xAD\xBE\xEF\xFE\xED\xFA\xCE\xCA\xFE\xBE\xEF
I've tried documenting this in swagger like this:
Batch:
type: object
properties:
header:
description: The number of packages represented in binary (big endian).
type: string
format: binary
maxLength: 8
minLength: 8
example: \x00\x00\x00\x02
subheader:
description: The size of each package, where the size of the first package is represented by the first 4 bytes, the second by the next 4 bytes, etc (big endnian).
type: string
format: binary
maxLength: 4294967295
minLength: 0
example: \x00\x00\x00\x04\x00\x00\x00\x04
data:
description: The data block for encryption/decryption
type: string
format: binary
maxLength: 18446744073709551616
minLength: 0
example: \xDE\xAD\xBE\xEF\xDE\xAD\xBE\xEF
But it shows the request body as a json object (due to type: object).
Any ideas on how to do this properly?
Octet-stream request body is defined as a single binary string. There's no way to define the contents/format of specific fragments of the octet-stream. minLength and maxLength can be used to limit the size of the entire stream.
Also note that this is OpenAPI 3.0. OpenAPI 2.0 does not support application/octet-stream payloads (it only supports multipart/form-data).
openapi: 3.0.2
paths:
/something:
post:
requestBody:
required: true
content:
application/octet-stream:
schema:
type: string
format: binary
maxLength: 12345

including multiple example files for a same resource in RAML 0.8?

[enter image description here][1]I know my syntax is wrong in the image here . But just want to let you know what I'm trying to achieve.I'm using RAML 0.8. I want to include multiple requests and responses for a single resource. Can this be achieved in RAML 0.8? Your response is much appreciated. Thank you!
You can have multiple responses in RAML 0.8, for example one for the 200 status code, one for the 404 status code, etc.
An example of this is:
/media/popular:
displayName: Most Popular Media
get:
description: |
Get a list of what media is most popular at the moment.
responses:
200:
body:
application/json:
schema: !include instagram-v1-media-popular.schema.json
503:
description: |
The service is currently unavailable or you exceeded the maximum requests
per hour allowed to your application.
body:
application/json:
schema: !include instagram-v1-meta-error.schema.json
You can specify several requests, but each for a different media type.
For example:
/jobs:
post:
description: Create a Job
body:
text/xml: !!null
application/json: !!null
You cannot have multiple examples in 0.8.
(In RAML 1 you can have multiple examples)

RAML Code understanding

I have below requirement for designing simple RAML. I’m newbie in RAML coding so would like to know if my code is according to requirement or not
Requirement:
Has at least 1 endpoint with a GET and POST method.
Includes description attribute of the API
Includes description attribute of the method
The GET request takes a query parameter of "mulesoft"
Define the response with an object that contains least a string and
integer data type
Includes an example for a 200 response code that matches the
definition’s response object from above
My code:
#%RAML 1.0
title: Coding_Champions
version: 1.0.development
baseUri: http://localhost:8004/api
description: This API displays and adds Organisation with details
types:
Org:
type: object
properties:
name: string
address: string
pincode: integer
/details:
displayName: Company Details
description: Coding challenge which takes query parameter of "mulesoft"
get:
description: Retrieve a list of all the Orgs
queryParameters:
mulesoft:
description: Specify the Org name that you want to retrieve
type: boolean
required: true
responses:
200:
body:
application/json:
type: Org
examples:
MuleSoft:
name: MuleSoft
address: 77 Geary Street, Suite 400
pincode: 94108
post:
description: Add a Org to list
body:
application/json:
type: Org
examples:
Cognizant:
name: Cognizant
address: DLF
pincode: 9771
responses:
201:
body:
application/json:
example: |
{
"message":"New Org updated but not really"
}
I’m more of concerned with one of point in the requirement
"The GET request takes a query parameter of “mulesoft”
Does it mean I should give mulesoft as parameter dynamically in my url, If yes then other than mulesoft is passed as parameter then it should throw an error ?
(or)
Does it mean i need to hard code “mulesoft” in my RAML code as I have done now ?
Can you please clear me on this ?
Does it mean I need to hard code “mulesoft” in my RAML code as I have
done now ?
Yes.You should define that in RAML as you are doing right now.Since its required parameter,its presence could be validated in implementation.

IdentityPool Creation with CloudFormation

I'm attempting to follow along with a tutorial located at http://serverless-stack.com/chapters/create-a-cognito-identity-pool.html for identity pool creation and document the creation by using cloudformation so that I can easily undo everything when I am done. However, I am having trouble finding any examples that show how to effectively do this using the template syntax. What I currently have is the following
ScratchUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: notes-user-pool
ScratchUserPoolClient:
Type: AWS::Cognito::UserPoolClient
Properties:
ClientName: notes-client
ExplicitAuthFlows: [ADMIN_NO_SRP_AUTH]
UserPoolId:
Ref: ScratchUserPool
ScratchIdentityPool:
Type: AWS::Cognito::IdentityPool
Properties:
IdentityPoolName: ScratchIdentityPool
AllowUnauthenticatedIdentities: false
CognitoIdentityProviders:
- ClientId:
Ref: ScratchUserPoolClient
ProviderName:
Ref: ScratchUserPool
The deployment step is failing when it attempts to create the ScratchIdentityPool. I get an error stating that:
An error occurred while provisioning your stack: ScratchIdentityPool -
Invalid Cognito Identity Provider (Service: AmazonCognitoIdentity;
Status Code: 400; Error Code: InvalidParameterException; Request ID:
bc058020-663b-11e7-9f2a-XXXXXXXXXX)
Am I not referencing the Client or Provider name correctly?
Almost immediately after I posted my question, I think I was able to answer it. The problem with my identity pool is that I needed to reference the provider name in the following way:
ScratchIdentityPool:
Type: AWS::Cognito::IdentityPool
Properties:
IdentityPoolName: ScratchIdentityPool
AllowUnauthenticatedIdentities: false
CognitoIdentityProviders:
- ClientId:
Ref: ScratchUserPoolClient
ProviderName:
Fn::GetAtt: [ScratchUserPool, ProviderName]
I needed to use the special amazon function Fn::GetAtt in order for this to work.