Using Schema(s) for REST based API


#1

I had my RAML defined as below.

There are 2 URI’s, which are mapped and have there own schema.
The issue is:

  1. Invoked URI: /password/v1/1123
    {
    “new_password”: “12334”,
    “old_password”: “12212221”
    }

Works Fine …

  1. Invoked URI: /securityquestion/v1/1123
    {
    “security_question”:“question”,
    “security_hint_answer”: “answer”
    }

Here validation failed, as it is still trying to validate 2nd request against the 1st Schema for Password.

Any pointers in resolving this will be appreciated.
Sample RAML file as below.

Thanks
Nikk

#Change Password
/password/{version}/{memberId}:
displayName: Update Password for the given MemberId
uriParameters:
version:
displayName: Version of the API
type: string
required: true
memberId:
displayName: MemberId implementing password change
type: integer
required: true
post:
description: Update password for the specific memberId
body:
application/json:
schema: |
{
"$schema": “http://json-schema.org/draft-03/schema”,
“type”: “object”,
“properties”: {
“new_password”: {“type”: “string”, “required”: true},
“old_password”: {“type”: “string”, “required”: true}
}
}
example: |
{
“new_password”: “pass1234”,
“old_password”: “password”
}
responses:
201:
body:
application/json:
schema: |
{
"$schema": “http://json-schema.org/draft-03/schema”,
“type”: “object”,
“properties”: {
“member_id”: {“type”: “string”},
“error_detail”: {“type”: “string”},
“service_response_codes”: {
“properties”: {
“key”: {“type”: “string”},
“value”: {“type”: “string”}
}
}
}
}
example: |
{
“member_id”: “9999”,
“error_detail”: “none”,
“service_response_codes”: { {“600”: "Password Successfully Changed "},{“602”: “Member Not found”}}
}
400:
body:
application/json:
schema: |
{
“type”: “object”,
“properties”: {
“member_id”: {“type”: “string”},
“error_detail”: {“type”: “string”},
“service_response_codes”: {
“properties”: {
“key”: {“type”: “string”},
“value”: {“type”: “string”}
}
}
}
}
example: |
{
“member_id”: “9999”,
“error_detail”: " Bad Request or Invalid Input ",
“service_response_codes”: {{“400”: "Bad Request "} }
}

#Change Security Question
/securityquestion/{version}/{memberId}:
displayName: Update Security Question for the given MemberId
uriParameters:
version:
displayName: Version of the API
type: string
required: true
memberId:
displayName: MemberId implementing Security Question change
type: integer
required: true
post:
description: Update Security Question for the specific memberId
body:
application/json:
schema: |
{
"$schema": “http://json-schema.org/draft-03/schema”,
“type”: “object”,
“properties”: {
“security_question”: {“required”: true, “type”: “string”},
“security_hint_answer”: {“required”: true, “type”: “string” }
}
}
example: |
{
“security_question”: “what is your security question?”,
“security_hint_answer”: “security”
}
responses:
201:
body:
application/json:
schema: |
{
"$schema": “http://json-schema.org/draft-03/schema”,
“type”: “object”,
“properties”: {
“member_id”: {“type”: “string”},
“error_detail”: {“type”: “string”},
“service_response_codes”: {
“properties”: {
“key”: {“type”: “string”},
“value”: {“type”: “string”}
}
}
}
}
example: |
{
“member_id”: “7777”,
“error_detail”: “none”,
“service_response_codes”: { {“600”: "security question Successfully Changed "},{“602”: “Member Not found”}}
}
400:
body:
application/json:
schema: |
{
“type”: “object”,
“properties”: {
“member_id”: {“type”: “string”},
“error_detail”: {“type”: “string”},
“service_response_codes”: {
“properties”: {
“key”: {“type”: “string”},
“value”: {“type”: “string”}
}
}
}
}
example: |
{
“member_id”: “7777”,
“error_detail”: " Bad Request or Invalid Input ",
“service_response_codes”: {{“400”: "Bad Request "} }
}


#2

Hi @simplynikhil
As far as I can read, the behavior you are getting makes no sense.
But it’s hard to tell with the info you have provided. Could you:

  1. Clarify what tool are you using? (I mean, RAML is the definition language, but a tool is using it for making the calls, validate, etc). API Console? APiKit? Osprey?
  2. Even though I was able to read the RAML, I think it would be better if you could include a full example, and since indentation is important, maybe sharing it on a GitHub Gist or some other way?

Looking forward to your answer in order to assist you better.
Best Regards.


#3

Hi @nohorbee

I am using APIKIT to generate the Flows based on the RAML.

The RAML and the Code details can be accessed as per link below
https://gist.github.com/simplynikhil/8fee609f641c4ad47923

Appreciate your help.

Thaks
Nikk


#4

Hi @simplynikhil,
Sorry for the delay. Let me start saying that I couldn’t reproduce the problem.

First:
The RAML that you published had some minor issues:
line 14: oauth_2 is not defined (deleted)
line 49 (originally 50 but moved up when deleted 14): indentation problem (corrected)
line 219 (originally 220 but moved up when deleted 14): indentation problem (corrected)

Here is the updated RAML (the one I used): https://gist.github.com/ceb472717320790f6ced.git

The APIKit generated an application really different from yours: https://gist.github.com/ed80419bf6b6483618db.git

I then started the app, tested from the console and from a Postman, and everything is working as expected (I mean, each operation is being validated by the corresponding schema).

Here is the data of the Studio and Apikit versions I’m using:

  • Anypoint Studio 3.5.0
  • APIKit plugin 1.3.0

Could you compare with yours and let me know? Maybe some other version had some bug, it’s hard to say right now.

Let me know.


#5

Hi nohorbee

Appreciate your help for this issue.
Finally get it resolved.
RAML was fine but the Mule was caching the request (with similar REST url pattern).
Have logged a defect, and the workaround by keeping all unique rest url’s seems to be working.

Thanks
Nikhil