Creating a JSON-LD Context: Properties missing - jsonschema

I try to create my own Context for a project. However, after using Compact some Properties will be missing. Please see this example:
{
"#context":
{
"myvocab": "http://localhost:8080/schema.json#",
"Information":
{
"#id": "myvocab:Information",
"#type": "#id",
"name": "http://schema.org/name",
"active": "http://schema.org/Boolean"
}
},
"Information": [
{
"#type": "myvocab:Information",
"name": "myCustomName",
"active": "true"
}
]
}
This example can also be found on the JSON-LD Playground.
After Compacting, I cannot see the properties "name" and "active" anymore as they will be removed. This is also the case in the playground. However, I do not get an error in the #context part, so I assume it is correct.
Please help me to understand why that properies go missing and what I could do to see them correctly after parsing.
Thanks in advance!

The nesting of your context is wrong. You mistakenly made name and active attributes of the Information mapping instead of making them term mappings on their own. Here's the fixed example:
{
"#context":
{
"myvocab": "http://localhost:8080/schema.json#",
"Information":
{
"#id": "myvocab:Information",
"#type": "#id"
},
"name": "http://schema.org/name",
"active": "http://schema.org/Boolean"
},
"Information": [
{
"#type": "myvocab:Information",
"name": "myCustomName",
"active": "true"
}
]
}
You might also want to check the mapping of active. You map it to a type instead of mapping it to a property (properties are lowercased in Schema.org, classes/types capitalized).

Related

How to update the status on a Jira issue vis Jira Rest Api

I want to change the status of the project issue on Jira. The status is Open and I want to make it Fixed. My url is PUT https://jiradbg-sandbox.deutsche-boerse.de/rest/api/latest/issue/PID-XX
{
"update": {
"fields":{
"status": [
{
"set": "Fixed"
}
]
}
}
}
and the response is:
{
"errorMessages": ["Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: org.apache.catalina.connector.CoyoteInputStream#5de98556; line: 3, column: 9]
(through reference chain: com.atlassian.jira.rest.v2.issue.IssueUpdateBean[\"update\"])"]
}
There are two problems that you are encountering here.
The first problem is update or fields should be provided separately to Jira's edit issue API, not one inside of the other. They have equivalent functionality so normally only one is used. For example to update the summary field provide either update:
{
"update": {
"summary": [
{
"set": "Updated by update"
}
]
}
}
or fields:
{
"fields": {
"summary": "Summary set by fields"
}
}
However the status field is a special case and can't be updated directly, which is the second problem here. Changing a status in Jira is called a transition. You need to trigger the transition to move the issue into the status you want.
Start by identifying the available transitions by calling the get transitions API:
GET https://example.net/rest/api/latest/issue/PID-XX/transitions
This tells you which transitions are currently available, something like this:
{
"expand": "transitions",
"transitions": [
{
"id": "21",
"name": "Fixed",
"to": {
"self": "https://example.net/rest/api/2/status/10001",
"description": "",
"iconUrl": "https://example.net/images/icons/status_generic.gif",
"name": "Fixed",
"id": "10001",
"statusCategory": {
"self": "https://example.net/rest/api/2/statuscategory/3",
"id": 3,
"key": "done",
"colorName": "green",
"name": "Done"
}
}
}
]
}
Take the id of the transition you want, in this case 21, then post it to the issue transition API:
POST https://example.net/rest/api/latest/issue/PID-XX/transitions
Use a request body like this:
{
"transition": {
"id": 21
}
}
You should get a 204 HTTP response from Jira which indicates the transition was successful.

Schema linking via #id results in "Unnamed item" error

I am trying to add Schema structured data to my website.
I have one page for my app with:
{
"#context": "https://schema.org",
"#type": "MobileApplication",
"#id": "https://example.com/app",
"name": "APP",
"applicationCategory": "HealthApplication",
"operatingSystem": ["iOS", "Android"],
"offers": {
"#type": "Offer",
"price": "0",
"priceCurrency": "USD"
},
"aggregateRating": {
"#type": "AggregateRating",
"ratingValue": "5",
"ratingCount": "100"
}
}
...and another for my company:
{
"#context": "https://schema.org",
"#type": "Corporation",
"#id": "https://example.com/about",
"name": "COMPANY",
"owns": {
"#type": "MobileApplication",
"#id": "https://example.com/app"
}
}
When I test the above with https://search.google.com/test/rich-results, the app page is fine, but the company page gives the following error:
Am I misunderstanding how #id works? I thought Google would then look for the linked resource and get all the missing properties.
reference them by using just the #id keyword, omit the #type keyword:
{
"#context": "https://schema.org",
"#type": "Corporation",
"#id": "https://example.com/about",
"name": "COMPANY",
"owns": {
"#id": "https://example.com/app"
}
}
However, Google doesn't seem to utilize #id keyword in a way that it links snippets on the internet, especially ones that are on different pages, or sites, or at least there are no benefits in SERP
Also, corporation markup could be improved: property owns expects a Product type, and MobileApplication is a subtype of CreativeWork, so it's probably not appropriate, however, there seems to be no straightforward property that connects Organization and CreativeWork, although Google doesn't seem to complain about it

jsonschema dependentSchema not validating

I am trying to learn json schema, but something isn't working out for me.
I'm trying to run the example from http://json-schema.org/understanding-json-schema/reference/conditionals.html#id4 for dependentSchemas, but it just doesn't validate.
I'm using this schema:
check_schema = {"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" },
"credit_card": { "type": "number" }
},
"required": ["name"],
"dependentSchemas": {
"credit_card": {
"properties": {
"billing_address": { "type": "string" }
},
"required": ["billing_address"]
}
}
}
and this json, that should raise an error since it is missing the key billing_address:
check_dict={
"name": "John Doe",
"credit_card": 5555555555555555
}
but when I use jsonschema.validate(dic_check, schema_check) (with python, jsonschema package version 4.2.1), the validation passes with no issues.
What am I doing wrong here?
If you are using an implementation that doesn't support at least draft2019-09 of the specification, dependentSchemas won't be recognized as a keyword. In earlier versions (draft7 and before), that keyword was known as dependencies, with the same syntax (actually, dependencies was split into two, dependentSchemas and dependentRequired).
The details are described on the page you linked, https://json-schema.org/understanding-json-schema/reference/conditionals.html#dependentschemas.
If you still believe that what you have should work, I suggest you open a bug report on the implementation's issue queue.

PUT inventory custom fragment

This is my device inventory with the custom tasks array:
{
...
"c8y_IsDevice": {},
"tasks": [
{
"task_status" : "NEW",
"task_id" : "1",
"task_data" : {
...
}
},
{
"task_status" : "DONE",
"task_id" : "2",
"task_data" : {
...
}
},
...
]
...
}
I want to create a MQTT/SMARTREST PUT template to update a task by id and status.
For example: 800,[task_id],[task_status]
I am not able to find a way for this, especially it's an json array and all my attempts end up in overwriting the complete json array.
Maybe there's sth. like a condition, if task_id = x -> set task_status = y
Thank you.
You can only replace the whole fragment. There is no way to partially modify fragments.
one way to do it is get the whole array, using it for create a new one locally with the changes to want to do and finally put it again into the database. It is not a kind of solution but have been working for me.
Thanks for the info, but I still got a question about updating an array.
Concerning your answers I want to update the whole fragment.
This is my inventory:
"tasks": [
{
"address": {
"street": "Street",
"street_number": "1"
},
"description": "Test Description",
"id": "1",
"status": "NEW"
},
{
"address": {
"street": "Street2",
"street_number": "2"
},
"description": "Test Description 2",
"id": "2",
"status": "DONE"
}
]
My template:
801,<$.tasks.status>,<$.tasks.description>,<$.tasks.address.street>,<$.tasks.address.street_number>
Template screenshot
Now I publish:
//801,SERIAL,status,description,street_name,street_nr
801,SERIAL,NEW,1,2,3,4
Of course, this will overwrite the array and just set a json object tasks.
"tasks": {
"address": {
"street": "2",
"street_number": "3"
},
"description": "1",
"status": "NEW"
}
So I tried tasks[*]/tasks[] in my template (like in response templates), but this won't work too. I don't get it, maybe you can give me a small solution about putting a complete fragment with an array inside.

Dredd (gavel) : Begin a Json Schema with an array (bug ?)

I am using Markdown for Generate documentation (aglio), generate mocks (api-mock) and check the integrity constraints (dredd).
With Dredd, no problem for check an object, no problem for PUT or POST, but I have a problem with lists.
My lists are arrays, but when I write this schema :
{
"title": "Videos List",
"type": "array",
"items": {
"type":"object",
"required":false,
"properties": {
"id": {
"type": "string",
"required": true
}
},
"required": true
}
}
I get same error all the time: body: JSON schema is not valid! invalid type: object (expected [object Object]/array) at path "/items"
I've tried, again and again, 3 hours, but I failed.
Please help!
PS : sorry for my English, I'm french.
Yes, your data is correct again that schema.
It might be a specific problem of the validator your are using (you did not mention which). You can try to enclose your data with {}. I guess it is expecting allways a JSON like this:
{
[
{
"id": "ninon-retrouve-rudy",
"title": "Ninon retrouve Rudy edited"
},
{
"id": "ninon-retrouve-rudy-1",
"title": "Ninon retrouve Rudy"
}
]
}
Be aware also that your are using Draft03 of Json-schema. I suggest you to use Draft04 (your validator might be obsolete).