Overview
Store schemas in the Schema service and use them in the documents you create in the Document service. You can also store mixins that you can use to extend your data models. Schemas define these extendable data models for each tenant. For more information about mixins, see the Operate on Mixins topic in the Document service section.
When a schema is created, the system generates a URL that you can use to access and use the schema. Because schemas and mixins are stored in a tenant-aware manner, the format of the generated URL is https://api.beta.yaas.io/hybris/schema/v1/{tenant}/{schema}
, in which:
{tenant}
is the Identifier of your project.{schema}
is the name of your schema file with the version and.json
extension
This is an example of a schema URL: https://api.beta.yaas.io/hybris/schema/v1/hybris/comicSchema.v2.json
.
Tags
You can also create tags for your schemas. Use tags to navigate easily through your repository. For example, if you create two schemas for similar services that provide different parameters, you can add tags naming those parameters. You can then filter your repository by the tag names.
Metadata
You can manage your own metadata for schemas in the form of simple key-value pairs (where values are strings) using the /{tenant}/{schema}/metadata
endpoint. For example, you can add a title and a description to your schema using that endpoint.
The Schema service also allows you to search for schemas using metadata. Let's assume you have a grocery shop where users can order your products online. You have ten online sales assistants, all responsible for updating online offers. To keep the data displayed for your grocery products on the site organized and consistent, make sure that each product description:
- Contains at least name, short description, price, unit of measure and long description.
- Is always structured consistently, with all fields named exactly the same for each grocery product.
- Is expendable.
Create a structure
The schema provides an immutable structure, to serve as a template for your data. When you create a schema for your grocery products, you can define the required product detail display fields with attributes such as name, short description, price, unit of measure, and long description. Define the fields you want to appear in each and every new product document.
Implementation
When you build any service or website that retrieves data from a set of documents or a database, implement one solution for all of your products that ensures the properties you need for each item are identically-named and ordered, with identical structures and immutable schemas.
Immutability versus changes: Tags are here to help
While schema immutability ensures data consistency, changes in the market are unavoidable and can require changes to your product parameters. For example, as ecologically-friendly products become more important to consumers, an additional parameter is required to designate whether your dairy products come from ecologically-friendly sources or not.
Assume you already have a schema called milk that includes a parameter for variable milk fat content. Because the existing schema is immutable and you cannot change it, create a new schema that includes the new ecologically-friendly parameter. You can call the schema milk version 2.
Add a tag called version 2 and a tag called ecological to the new schema. You can use the extended milk schema by filtering by, and calling the new tags.
{schema}
: https://api.beta.yaas.io/hybris/schema/v1/{tenant}/{schema}
. For example, if your schema file name is testSchema.v1.json
, the URL for that schema is https://api.beta.yaas.io/hybris/schema/v1/mycomicsshop/testschema.v1.json
.API Reference
/{tenant}
/{tenant}
Returns a list, that contains the IDs of the schemas, their tags and metadata. It can be limited by a query on tags or metadata. The 'q' query parameter enables you to specify the conditions. Two types of operators are supported for tags:
- IN - Checks if a tag contains any of the provided values, such as branch:in(apparel, food)
- ALL - The tag must contain all values from the condition, such as branch:all(sport, food)
There is also possibility to filter schema by metadata. In this case the only operator is EQUAL. Values should be quoted!
Security / Access Control:
To access this method, an access token must be issued for the tenant with the hybris.schema_view scope to manage this resource.
Deletes all schemas for a given tenant.
Security / Access Control:
To access this method, an access token must be issued for the tenant with the hybris.schema_admin scope to manage this resource.
/{tenant}/{schema}
/{tenant}/{schema}
Gets the schema file.
Security / Access Control:
Does not require access token.
Creates a new schema file.
Security / Access Control:
To access this method, access token must be issued for tenant and have hybris.schema_manage scope to manage this resource.
/{tenant}/{schema}/metadata
/{tenant}/{schema}/metadata
Returns the metadata of a given schema.
Security / Access Control:
To access this method, an access token must be issued for the tenant with the hybris.schema_view scope to manage this resource.
Updates metadata stored along with the schema by replacing it. The metadata format is simple key-value pairs. Both keys and values must be strings and keys cannot contain any special characters like "." or "$".
Security / Access Control:
To access this method, access token must be issued for tenant and have hybris.schema_manage scope to manage this resource.
/{tenant}/{schema}/tags
/{tenant}/{schema}/tags
/{tenant}/{schema}/tags/{tag}
/{tenant}/{schema}/tags/{tag}
/{tenant}/all/tagvalues
/{tenant}/all/tagvalues
Returns a list of all tags with their distinct values. The result is based on all tenant's schemas and it is eventually consistent, which means it may be outdated as aggregation does not run on every GET request.
Security / Access Control:
To access this method, access token must be issued for tenant and have hybris.schema_view scope to manage this resource.
/{tenant}/all/tagvalues/{tag}
/{tenant}/all/tagvalues/{tag}
Return distinct values for the given tag from all schemas. The result is eventually consistent, which means it may be outdated because the aggregation does not run on every GET request.
Security / Access Control:
To access this method, an access token must be issued for the tenant with the hybris.schema_view scope to manage this resource.
Metadata
Managing metadata is a very useful mechanism if you want to store additional information about your schema JSON format.
The Schema service enables you to:
- Create metadata using the
/{tenant}/{schemaId}/metadata
endpoint. - Update (fully replace) metadata using the
/{tenant}/{schemaId}/metadata
endpoint. - Read single metadata using the
/{tenant}/{schemaId}/metadata
endpoint. - Filter schemas using metadata via the
/{tenant}
endpoint with paging and sorting the results.
Building a filter and sort query
To filter schemas using metadata, use the /{tenant}
endpoint with a query in the following format: ?q=field:"value" secondField:"custom value" thirdField:"100"&sort=field:asc
.
A query is built according to the following rules:
- It consists of key:value pairs, which correspond the fields and their values in your JSON metadata. The Schema service stores schema metadata string values.
- You must use quotation marks (
""
) for values. For example a querydescription:Am I wrong?
is wrong, since there are no quotation marks around the value (Am I wrong?
). It should be changed todescription:"Am I wrong?"
. - If you want to filter including more than one metadata field, separate key:value pairs by spaces. For example a query like
title:"comics" description:"This schema represents comics..."
will filter metadata wheretitle
is equal tocomics
ANDdescription
is equal toThis schema represents comics...
. - You can also sort the results using optional query parameter
sort
. The key should be the field you want to sort by, and its value should be whether it is ascending (asc
) or descending (desc
).
Filter example
A sample query /{tenant}?q=title:"comics" description:"This schema represents comics..." timestamp:"1455012175"&sort=type:asc
will filter metadata where:
- title is equal to
comics
- description is equal to
This schema represents comics...
- timestamp is equal to
1455012175
Metadata that fulfills those constraints could look like this:
{
"title": "comics",
"description": "This schema represents comics...",
"timestamp": "1455012175",
"type": "A"
}
Paging
While filtering results, the Schema service uses paging by default, even if the request does not specify it. To support paging, the Schema service uses a Link HTTP header to provide links to the:
- Current page:
rel=self
- Previous page:
rel=prev
(not present if the current page is the first page) - Next page:
rel=next
(not present if the current page is the last page)
You can also use the pageSize parameter to specify how many results you want to receive on one page and the pageNumber parameter to point to a specific page of the returned results.
Sorting
You can sort the results using the optional sort
query parameter.
A sample query /{tenant}?q=title:"comics" description:"This schema represents comics..." timestamp:"1455012175"&sort=type:asc
will filter metadata sorted by title in ascending order:
[
{ "id": "comics.v1.json",
"metadata": {
"title": "comics",
"description": "This schema represents comics...",
"timestamp": "1455012175",
"type": "A"
},
"tags": {}
},
{ "id": "comics.v1.json",
"metadata": {
"title": "comics",
"description": "This schema represents comics...",
"timestamp": "1455012179",
"type": "B"
},
"tags": {}
},
{ "id": "comics.v1.json",
"metadata": {
"title": "comics",
"description": "This schema represents comics...",
"timestamp": "1455012199",
"type": "C"
},
"tags": {}
}
]
Tags
Operations on tags
The operations you can perform on tags include creating tags, listing schemas with tags and tag values, filtering schemas using tags, returning tags and tag values, and removing tag arrays for specific schema.
Create tags for a specific schema
To create tags for a specific schema, use the /{tenant}/{schema}/tags/{tag}
endpoint, where the schema is a schema ID, and tag is the name of the tag array. Tag values must be provided using a tags parameter.
List schemas with tags and tag values
To list all your schemas with assigned tags and tags values, use the GET method on thee /{tenant}
endpoint.
Filter schemas using tags
To filter schemas using tag values, use the /{tenant}
endpoint with a query in the following form: ?q=tagAttribute1:all(value1,value2)+tagAttribute2:in(value1,value2)
. A query is built according to the following rules:
tagAttribute
is a name of an array of tags. It reflects{tag}
in the/{tenant}/{schema}/tags/{tag}
resource.- Values in parentheses are comma-separated tag values.
in
enables you to filter schemas where the tag attribute contains any of the values in parentheses.all
enables you to filter schemas where the tag attribute contains all of the values in parentheses.- The plus sign (
+
) is included because of URL encoding rules and takes the place of a space character that separates query conditions.
Return tags and tag values
To list tags and all of their distinct values, perform a GET method on:
/{tenant}/all/tagvalues
endpoint to retrieve a list of all tags with all distinct values assigned to those tags.{tenant}/{schema}/tags
to retrieve a list of all tags with all distinct values assigned to those tags for a given schema./{tenant}/all/tagvalues/{tag}
to retrieve a list of all distinct values assigned to the particular tag.
Remove a specific tag array for a specific schema
To remove tag values from an array for a specific schema, use the /{tenant}/{schema}/tags/{tag}
endpoint, where the schema is a schema ID, and tag is the name of the tag array. Tag values must be provided using a tags parameter.
true
and remove all tag values as in the previous examples. If removeEmpty is set to false
when all tag values are deleted, tag attribute will remain empty.Introduction
In the Schema service tutorials, you explore the Schema service in detail. You learn to do the following:
- Create and retrieve schemas.
- Manage schema metadata.
- Operate on tags.
The tutorials are based on the following scenario:
- You have a shop that sells comics.
- You want to have predefined schemas for your comic books.
- You create schemas for books of a different type.
The Schema service requires the hybris.schema_manage scope for POST, PUT and DELETE operations and a separate hybris.schema_admin scope for DELETE operations on the /{tenant}
endpoint (for tests only). You can access a single schema with the GET method without a scope. The hybris.schema_view scope is required whenever you want to:
- Get a list of a tenant's schemas.
- List distinct tag values across different schemas.
- List all tags with associated values.
- Filter schemas using metadata.
These scopes should be granted in an access token received from the OAuth 2.0 service. For more information about scopes and access tokens, see Authorization and OAuth 2.0.
Create and Retrieve Schema
Get all your variables in one place
The following variables are used within this tutorial:
tenant = {{projectId}};
client = {{clientName}};
access_token = {{token}};
Create API client for Schema service
API.createClient('schemaService',
'/services/schema/v1/api.raml');
You can use JSON schemas to standardize pieces of information when creating documents in the Document service. These schemas are stored in the Schema service. This example shows how to create and retrieve schemas in the Schema service.
Create a new schema in the Schema service
Request
- Method: POST
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}/{schema}
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header.
- schema: Name of the schema stored for the given tenant.
- Required:
- Response:
- Status code:
201
- Status code:
schema_obj = schemaService.tenant(tenant).schema('comicSchema.v1.json').post({
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"original_release": {
"type": "date"
},
"title": {
"$ref": "https://pattern.yaas.io/v1/schema-localized.json"
},
"available": {
"type": "object",
"properties": {
"published": {
"type": "date"
},
"title": {
"$ref": "https://pattern.yaas.io/v1/schema-localized.json"
}
}
}
}
}, {
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-type' : 'application/json'
}
}
)
schema_obj.body
Retrieve a schema created in the Schema service
Request
- Method: GET
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}/{schema}
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header.
- schema: Name of the schema stored for the given tenant.
- Required:
- Response:
- Status code:
200
get_obj = schemaService.tenant(tenant).schema('comicSchema.v1.json').get(null, {
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-type' : 'application/json'
}
})
get_obj.body
More about schemas and mixins
To learn more about how to use schemas and mixins, see the Document service documentation:
Operate on Tags
Get all your variables in one place
The following variables are used within this tutorial:
tenant = {{projectId}};
client = {{clientName}};
access_token = {{token}};
Create API client for Schema service
API.createClient('schemaService',
'/services/schema/v1/api.raml');
Prerequisites
To complete this tutorial, you must first create a schema as described in the Create and Retrieve Schema tutorial. The below snippet provides you with the code to do so:
schema_obj = schemaService.tenant(tenant).schema('comicSchema.v1.json').post({
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"original_release": {
"type": "date"
},
"title": {
"$ref": "https://pattern.yaas.io/v1/schema-localized.json"
},
"available": {
"type": "object",
"properties": {
"published": {
"type": "date"
},
"title": {
"$ref": "https://pattern.yaas.io/v1/schema-localized.json"
}
}
}
}
}, {
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-type' : 'application/json'
}
}
)
schema_obj.body
Create tags for the schema
Request
- Method: POST
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}/{schema}/tags/{tag}
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header.
- schema: Name of the schema stored for the given tenant.
- tag: Name of the tag array.
- Required:
- Query parameters:
- tags:
reprint,standard
- tags:
- Response:
- Status code:
200
- Status code:
schema_obj = schemaService.tenant(tenant).schema('comicSchema.v1.json').tags.tag('comictags').post(null, {
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-type' : 'application/json'
},
query: {
'tags': 'reprint, standard'
}
})
schema_obj.body
Filter schemas using tags
- Method: GET
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header. In this example, the tenant is
mycomicsshop
.
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header. In this example, the tenant is
- Required:
- Query Parameters:
- Optional:
- q: The query parameter, such as:
q=comictags:all(reprint)
- q: The query parameter, such as:
- Optional:
- Response:
- Status code:
200
- Status code:
get_obj = schemaService.tenant(tenant).get(null, {
headers: {
'Authorization': 'Bearer ' + access_token
},
query: {
'q': 'comictags:all(reprint)'
}
})
get_obj.body
Count with query
The schemas returned by query are paged by default. To get the number of all schemas fulfilling the query use totalCount header.
- Method: GET
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header. In this example, the tenant is
mycomicsshop
.
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header. In this example, the tenant is
- Required:
- Query Parameters:
- Optional:
- q: The query parameter, such as:
q=comictags:all(reprint)
- totalCount: Boolean parameter for counting all results.
- q: The query parameter, such as:
- Optional:
- Response:
- Status code:
200
- Status code:
get_obj = schemaService.tenant(tenant).get(null, {
headers: {
'Authorization': 'Bearer ' + access_token
},
query: {
'q': 'comictags:all(reprint)',
'totalCount' : true
}
})
get_obj.body
List all schemas along with tags and tag values
- Method: GET
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header. In this example, the tenant is
mycomicsshop
.
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header. In this example, the tenant is
- Required:
- Response:
- Status code:
200
get_obj = schemaService.tenant(tenant).get(null, {
headers: {
'Authorization': 'Bearer ' + access_token
}
})
get_obj.body
List all tags with all distinct values
To retrieve a list of all tags with all distinct values assigned to those tags, you can perform a GET request on the /{tenant}/all/tagvalues
endpoint. To perform this operation, you need a valid access token with the hybris.schema_view scope.
Request
- Method: GET
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}/all/tagvalues
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header.
- Required:
- Response:
- Status code:
200
- Status code:
get_obj = schemaService.tenant(tenant).all.tagvalues.get(null, {
headers: {
'Authorization': 'Bearer ' + access_token
}
})
get_obj.body
List all tags with all distinct values for a particular schema
To retrieve a list of all tags with all distinct values assigned to those tags for a given schema, you can perform a GET request on the /{tenant}/{schema}/tags
endpoint. To perform this operation, you need a valid access token with the hybris.schema_view scope.
Request
- Method: GET
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}/{schema}/tags
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header.
- schema: Name of the schema stored for the given tenant.
- Required:
- Response:
- Status code:
200
- Status code:
get_obj = schemaService.tenant(tenant).schema('comicSchema.v1.json').tags.get(null, {
headers: {
'Authorization': 'Bearer ' + access_token
}
})
get_obj.body
List all distinct values of a given tag from all schemas
To retrieve a list of all distinct values assigned to the particular tag, you can perform a GET request on the /{tenant}/all/tagvalues/{tag}
endpoint. To perform this operation, you need a valid access token with the hybris.schema_view scope.
- Method: GET
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}/all/tagvalues/{tag}
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header. In this example, the tenant is
mycomicsshop
. - tag: Name of the tag value which values you want to retrieve. In this example, it is
comictags
.
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header. In this example, the tenant is
- Required:
- Response:
- Status code:
200
- Status code:
get_obj = schemaService.tenant(tenant).all.tagvalues.tag('comictags').get(null, {
headers: {
'Authorization': 'Bearer ' + access_token
}
})
get_obj.body
Remove tags
- Method: DELETE
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}/{schema}/tags/{tag}
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header. In this example, the tenant is
mycomicsshop
. - schema: Name of the schema stored for the given tenant. In this example, it is
comicSchema.v2.json
. - tag: Name of the tag array. In this example it is
comictags
.
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header. In this example, the tenant is
- Required:
- Query parameters:
- tags:
reprint
- tags:
- Response:
- Status code:
204
- Status code:
remove = schemaService.tenant(tenant).schema('comicSchema.v1.json').tags.tag('comictags').delete(null, {
headers: {
'Authorization': 'Bearer ' + access_token
},
'query' : {
'tags' : 'reprint'}
})
Manage metadata
Get all your variables in one place
The following variables are used within this tutorial:
tenant = {{projectId}};
client = {{clientName}};
access_token = {{token}};
Create API client for Schema service
API.createClient('schemaService',
'/services/schema/v1/api.raml');
Prerequisites
To complete this tutorial, you must first create a schema as described in the Create and Retrieve Schema tutorial. The below snippet provides you with the code to do so:
schema_obj = schemaService.tenant(tenant).schema('comicSchema.v1.json').post({
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"original_release": {
"type": "date"
},
"title": {
"$ref": "https://pattern.yaas.io/v1/schema-localized.json"
},
"available": {
"type": "object",
"properties": {
"published": {
"type": "date"
},
"title": {
"$ref": "https://pattern.yaas.io/v1/schema-localized.json"
}
}
}
}
}, {
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-type' : 'application/json'
}
}
)
schema_obj.body
Create or update metadata for the schema
To create or update metadata for a specific schema, use the /{tenant}/{schema}/metadata
endpoint and make a PUT request.
Request
- Method: PUT
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}/{schema}/metadata
- Headers:
- Required:
- Content-Type: Must be set to
application/json
. - Authorization: An access token with the hybris.schema_manage scope.
- Content-Type: Must be set to
- Required:
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header.
- schema: Name of the schema stored for the given tenant.
- Required:
- Response:
- Status code:
200
- Status code:
schema_obj = schemaService.tenant(tenant).schema('comicSchema.v1.json').metadata.put({
"title": "comics",
"description": "Simple comics schema."
}, {
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-type' : 'application/json'
}
})
schema_obj.body
Get metadata for the schema
In this example, you will get metadata for a specific schema. This time, you will make a GET request on the /{tenant}/{schema}/metadata
endpoint.
Request
- Method: GET
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}/{schema}/metadata
- Headers:
- Required:
- Authorization: An access token with the
hybris.schema_view
scope.
- Authorization: An access token with the
- Required:
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header.
- schema: Name of the schema stored for the given tenant.
- Required:
- Response:
- Status code:
200
- Status code:
get_obj = schemaService.tenant(tenant).schema('comicSchema.v1.json').metadata.get(null, {
headers: {
'Authorization': 'Bearer ' + access_token
}
})
get_obj.body
Filter schemas using metadata
In this example, you will filter schemas using metadata. This time, you will use the /{tenant}
endpoint with a proper query. To show this in action, you will create three schemas and add metadata to them.
Create bookSchemaA.v1.json:
schema_objA = schemaService.tenant(tenant).schema('bookSchemaA.v1.json').post({
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"name": {
"id": "http://jsonschema.net/name",
"type" : "string"
},
"price": {
"id": "http://jsonschema.net/name",
"type" : "number"
},
}
}, {
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-type' : 'application/json'
}
}
)
schema_objA.body
And now add the following metadata to it:
schema_objA = schemaService.tenant(tenant).schema('bookSchemaA.v1.json').metadata.put({
"title": "book",
"description": "This schema represents a book of type A.",
"type" : "A"
}, {
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-type' : 'application/json'
}
})
schema_objA.body
Create bookSchemaB.v1.json:
schema_objB = schemaService.tenant(tenant).schema('bookSchemaB.v1.json').post({
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"name": {
"id": "http://jsonschema.net/name",
"type" : "string"
},
"price": {
"id": "http://jsonschema.net/name",
"type" : "number"
},
}
}, {
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-type' : 'application/json'
}
}
)
schema_objB.body
And now let's add the following metadata to it:
schema_objB = schemaService.tenant(tenant).schema('bookSchemaB.v1.json').metadata.put({
"title": "book",
"description": "This schema represents a book of type B.",
"type" : "B"
}, {
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-type' : 'application/json'
}
})
schema_objB.body
Create bookSchemaC.v1.json:
schema_objC = schemaService.tenant(tenant).schema('bookSchemaC.v1.json').post({
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"name": {
"id": "http://jsonschema.net/name",
"type" : "string"
},
"price": {
"id": "http://jsonschema.net/name",
"type" : "number"
},
}
}, {
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-type' : 'application/json'
}
}
)
schema_objC.body
And now let's add the following metadata to it:
schema_objC = schemaService.tenant(tenant).schema('bookSchemaC.v1.json').metadata.put({
"title": "book",
"description": "This schema represents a book of type C.",
"type" : "C"
}, {
headers: {
'Authorization': 'Bearer ' + access_token,
'Content-type' : 'application/json'
}
})
schema_objC.body
Now, after adding a few books with metadata, let's filter them to find only those with type equal to C
.
Request
- Method: GET
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}
- Headers:
- Required:
- Authorization: An access token with the
hybris.schema_view
scope.
- Authorization: An access token with the
- Required:
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header.
- Required:
- Query Parameters:
- Optional:
- q: The query parameter, such as:
q=field:"value"
- q: The query parameter, such as:
- Optional:
- Response:
- Status code:
200
- Status code:
get_obj = schemaService.tenant(tenant).get(null, {
headers: {
'Authorization': 'Bearer ' + access_token
},
query: {
'q' : 'type:"C"'
}
})
get_obj.body
Filter schemas with metadata with sorting
You can also sort while filtering schemas using metadata. Likewise, you must use the /{tenant} endpoint with a proper query. In this example you will base on the schemas and metadata created in the previous step and filter them to find only those with title equal to book
sorted by type descending.
Request
- Method: GET
- Request URL:
https://api.beta.yaas.io/hybris/schema/v1/{tenant}
- Headers:
- Required:
- Authorization: An access token with the
hybris.schema_view
scope.
- Authorization: An access token with the
- Required:
- URI parameters:
- Required:
- tenant: The project that requests this resource. Must match the project that is associated with the access token in the Authorization header.
- Required:
- Query Parameters:
- Optional:
- q: The query parameter, such as:
q=field:"value"&sort=field:asc
- q: The query parameter, such as:
- Optional:
- Response:
- Status code:
200
- Status code:
get_obj = schemaService.tenant(tenant).get(null, {
headers: {
'Authorization': 'Bearer ' + access_token
},
query: {
'q' : 'title:"book"',
'sort' : 'type:desc'
}
})
get_obj.body
Security
The Schema service stores data in a generic way. For example, schemas do not contain any personal data. Furthermore, the Schema service does not process or store personal data. Therefore, the service does not respond to requests and events that the Transparency and Deletion services publish.
Glossary
Term | Description |
---|---|
document | A data object created in a database that contains a set of information which may be defined by a JSON schema. It"s identified by ID. |
schema | A human- and machine-readable description of a JSON document expressed in terms of constraints on the fields and structure. |
If you find any information that is unclear or incorrect, please let us know so that we can improve the Dev Portal content.
Use our private help channel. Receive updates over email and contact our specialists directly.
If you need more information about this topic, visit hybris Experts to post your own question and interact with our community and experts.