How to specifiy schema in JSON document - jsonschema

Is there a standardized way to specify this documents schema, i have been looking for one, but i am unsure if using the following is the correct way of doing things.
// My JSON Document
{
"$schema": "http://path.to/my/schema.json",
...
}

The JSON Schema spec has two recommendations for correlating a JSON document with a schema. Both have to do with HTTP headers. JSON Schema does not define a way for JSON documents to be self describing, but it could easily be done in a way similar to the example you gave.
Content-Type
The Content-Type header seems to be the most widely accepted correlation mechanism. It defines a MIME type parameter called profile whose value is a URI to to schema that defines the JSON document.
Content-Type: application/json; profile="/my-hyper-schema#"
Link
The other correlation mechanism is to include a Link header with a URI to the schema that defines the JSON document. This Link should have a rel of describedBy
Link: </my-hyper-schema#>; rel="describedBy"
Reference
http://json-schema.org/latest/json-schema-core.html#anchor33

Related

Is there any way to store array/list as variable/parameter in constructing an API in Postman?

I'm trying to parameterize a url in Postman and loop over that list to call multiple APIs one after another and append the JSON bodies.
For example:
if the url is GET https://location/store/{{user_id}}/date
and
user_id = ['1','3','5','2','6','8']
then how do I store user_idas a variable such that request can loop over each user_idin the url and generate an appended JSON body?
You can use data files. Store the user id values into a csv or JSON file and call that file in to your collection runner. The headers of the csv files can be used as variables names. please see the details of this approach in the below link
https://learning.postman.com/docs/postman/collection-runs/working-with-data-files/

I have created a .json file and want to fetch the data from that json file using rest assured method. How can I achieve this?

I have designed a Rest Assured Framework where I create a separate JSON file that contains all API endpoints. So, now I want to pull the data out of this JSON file using Rest Assured. How can that be achieved?
Sample JSON file :
{
"data": [{
"TestCasesID": "TestCase_1",
"ModuleName": "ABC",
"TestCaseDescription": "Get Special Offer",
"GetURL1": "#v1/my/specialOffers",
"GetURL2": "#v1/my/specialOffers"
}
]
}
you donot need rest-assured to just read values from json. it can not read/parse json files/strings. it need help from other libraries like jackson.
please refer the below answer:-
enter link description here

HTTP Protocol support multiple content types in request headers using HTTParty

It is stated that Content-Type should be of mediaType and mediaType is defined as follows.
media-type = type "/" subtype *( ";" parameter )
But I need subtype to have ability to accept multiple values in the headers like image/jpg,image/jpeg,image/gif,image/png for content types.
Documentation shows an example like Content-Type: text/html; But I need an example which shows how to have multiple media types like image/jpg,image/jpeg,image/gif,image/png.
If an example using HTTParty method can be provided, it will be helpful.
Reference: (http://greenbytes.de/tech/webdav/rfc2616.html#media.types)

RAML: how to export only particular type of XSD

I'm writing a RAML where response is an XML that corresponds to one particular type among many other types defined in an external XSD.
Is there a way to specify the particular type name from the XSD when defining parameter in RAML?
I.e. now I define it something like this:
responses:
200:
body:
application/xml:
schema: !include schemas/ManyManyTypesInside.xsd
But I would like to specify a particular type defined in the xsd to be used as a response type.
Note, that I don't wanna extract the type to a new file.
That's not possible with RAML without separating the XSD portion into it's own XSD.
Why can't you separate it for just documentation/RAML purposes?
The answer on the question depends on the RAML version.
Version 0.8 does not support referring to inner elements of XML Schema.
This feature has been added in RAML v1.0 and the format is like this:
schema: !include elements.xsd#Foo
I agree is not in the spec, but you can do exactly that with the RAML Tools for .Net
In the response schema you specify the name of the type.
See https://github.com/mulesoft-labs/raml-dotnet-tools#xml-schemas

RESTful API: How to handle translated textfields in representations?

I am designing a RESTful API for a booking application. There are accommodations that you can request a list or the details. As the application targets a multi-language audience, the descriptions are (sometimes) available in different languages.
Now I'm not sure how to handle these translations in the representation of an accommodation. Without the multiple languages I would make "description" a field or the accommodation object, quite simple.
Any idea how to solve this elegantly?
My current idea: Add a list of descriptions with text<->culture pairs instead of the description field and an additional subressource /descriptions to the accommodation for the creating (POST), updating (PUT) and deleting (DELETE) of new translations.
For retrieving the representations in the appropriate language you simply set the Accept-Language HTTP header.
Request:
GET /Hotel/345
Accept-Language: fr
Response:
<Hotel>
<Description xml:lang='fr'>Ce edifice est magnifique</Description>
</Hotel>
For doing the updates you could just include multiple description elements, assuming you are using xml as your media type format.
Request:
PUT /Hotel/345
<Hotel>
<Description xml:lang='en'>This building is magnificent</Description>
<Description xml:lang='fr'>Ce edifice est magnifique</Description>
</Hotel>