RAML 0.8 multiples responses

#1

I am trying to convert and OpenAPI spec to RAML 0.8.

The definition in OpenAPI is as follows

'200':
            description: Ok
            content:
              application/json:
                schema:
                  anyOf:
                    - $ref: '#/components/schemas/schemaA'
                    - $ref: '#/components/schemas/schemaB'

How would I define it in the RAML?
I have tried:
1.
> responses:

      200:
        description: Ok
        body:
          application/json:
            schema: schemaA | schemaB
responses:
      200:
        description: Ok
        body:
          application/json:
            schema: schemaA
         application/json+B:
            schame: schemaB

In case of 2, the schema is valid, but would Mule understand a custom json type?

0 Likes

#2

Why not use RAML 1.0 instead? In that case the union (1.) would work.

If you REALLY insist on using RAML 0.8, you can move your anyOf: to a separate JSON Schema that either $refers to or includes both schemaA and schemaB and then you would refer to it with an !include. I.e. schema: !include JSONSchemaWithAnyOf.json.

Hope this helps!

0 Likes

#3

Thanks @jstoiko. Can’t really move to 1.0 yet; its a constrain I have. Your suggestion also work, but I wanted to know if there was any other alternative.

0 Likes

#4

@jstoiko, sorry to bother you, am getting an warning after trying to modify the file.

{
	"$schema": "http://json-schema.org/draft-04/schema#",
	"type": "object",
	"required": ["response"],
	"properties": {
		"response": {
			"type": "object",
			"oneOf": [
        {
					"$ref": "schemaA.json"
				},
				{
					"$ref": "schemaB.json"
				}
			]
		}
	}
}

Error is:
‘Can not parse JSON example: Unexpected end of JSON input’

Any idea what is wrong?

0 Likes

#5

“Unexpected end of JSON input” indicates a JSON formatting error. You may want to check the syntax.

0 Likes

#6

Thanks, @jstoiko. Solved the problem last evening just forgot to update it here.

Solution looks like

{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"required": ["response"],
"properties": {
	"response": {
		"type": "object",
		"oneOf": [
    {
				"$ref": "./schemaA.json"
			},
			{
				"$ref": "./schemaB.json"
			}
		]
	}
}

}

0 Likes

#7

Hi, My requirement is, in POST method, i can expect multiple XML file.
Can you please help me, how can i declare multiple schema file in RAML file.

/icimscccnh:
post:
securedBy: [basic]
body:
application/xml:
schema: !include Request1.xsd
schema: !include Request2.xsd

0 Likes

#8

@biswa_tripathy, what is your use case. I don’t think there is ever a scenario when you can respond with 2 schemas unless you have a condition!

0 Likes

#9

Thanks a lot for your reply Vivek.

My API POST method should be able to accept two different XML structure.
Can you please help me, how can i define two schema file, so that any XML will come, it should take anyOf the schema .

0 Likes

#10

Have a look at the documentation

https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/

0 Likes

#11

Thanks a lot Vivek, Can we achieve the same using RAML ?

0 Likes

#12

Absolutely, have a look at a response for my question i posted a couple of weeks ago

0 Likes