DTDL - How to create object for location (lat,long)? - azure-digital-twins

I have DTDL model similar to below. I can use Json as string and store lat,long values. But,
How I can store lat,long array of locations using objects.
{
"#id": "dtmi:DigitalTwins:BasicInfra;2",
"#type": "Interface",
"displayName": "BasicInfra interface model",
"#context": "dtmi:dtdl:context;2",
"contents": [
{
"#type": "Property",
"name": "name",
"schema": "string"
},
{
"#type": "Property",
"name": "location",
"description": "Polygon/PolyLine Format Location",
"schema": {
"#type": "Object",
"fields": [
{
"name": "x",
"schema": "double"
},
{
"name": "y",
"schema": "double"
}
]
}
},
{
"#type": "Relationship",
"name": "contains"
}
]
}

Thanks for posting this question.
We got a response from Microsoft's Product Team.
At the moment, we don't support arrays in properties.
Please follow Azure Digital Twins updates, blogs, and announcements to get latest information on upcoming features. Also Product Updates page.

Related

How to Create a 3 level graph using NEO4J using JSON Array of Objects

I want to create a graph using neo4j which gives me a graph of the terms in the "JavaScript" array of the following JSON data, along with relationships pointing to unique "relatedTerms" nodes.
Here is my JSON data:
{
"JavaScript": [
{
"termName": "asm.js",
"link": "/terms/javascript/asmjs",
"info": "A subset of JavaScript. Effectively describes a safe virtual machine for memory-unsafe languages like C or C++. It can be used as a low-level, efficient target language for compilers.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
},
{
"name": "C",
"link": "/terms/go_to_term/470"
},
{
"name": "C++",
"link": "/terms/go_to_term/860"
},
{
"name": "compilers",
"link": "/terms/go_to_term/390"
}
],
"category": "JavaScript"
},
{
"termName": "Cycle.js",
"link": "/terms/javascript/cyclejs",
"info": "JavaScript framework for a predictable code. Builds on functional and reactive streams. Describes an app as a simple function taking an event stream as input and outputting an event stream.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
}
],
"category": "JavaScript"
},
{
"termName": "Derby",
"link": "/terms/javascript/derby",
"info": "Server component which is written on top of Node.js. It's is a server-side application with rich real-time data synchronization technology such used in google docs.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
},
{
"termName": "Express.js",
"link": "/terms/javascript/expressjs",
"info": "Lightweight, efficient middleware and routing framework. Express.js is best known as another quarter of the MEAN (MongoDB, Express, AngularJS and Node) software stack, and is the most popular Node.js framework.",
"relatedTerms": [
{
"name": "MEAN",
"link": "/terms/go_to_term/361"
},
{
"name": "MongoDB",
"link": "/terms/go_to_term/868"
},
{
"name": "AngularJS",
"link": "/terms/go_to_term/47"
},
{
"name": "Node",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
},
{
"termName": "Flow",
"link": "/terms/javascript/flow",
"info": "A static type checker for JavaScript. Integrates with the code editor by checking changes and analyzing correctness of the code. Provides context as to what is wrong with the code.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
}
],
"category": "JavaScript"
},
{
"termName": "Hapi",
"link": "/terms/javascript/hapi",
"info": "Web framework for building web applications, APIs and services. Hapi was created around the idea that configuration is better than code, that business logic must be isolated from the transport layer.",
"relatedTerms": [
{
"name": "APIs",
"link": "/terms/go_to_term/206"
}
],
"category": "JavaScript"
},
{
"termName": "Koa",
"link": "/terms/javascript/koa",
"info": "Callback-less, lightweight middleware framework for Node.js to build efficient web applications and APIs. Koa.js efficiently uses generators to deal with callbacks and increase error-handling capabilities.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
},
{
"name": "API",
"link": "/terms/go_to_term/206"
}
],
"category": "JavaScript"
},
{
"termName": "MEAN",
"link": "/terms/javascript/mean",
"info": "A full stack JavaScript solution that refers to the first letters of the four components of a solution for building dynamic websites: MongoDB, a NoSQL database; Express.js, a web applications framework; Angular.js, a JavaScript MVC framework for web apps; Node.js, a software platform for scalable server-side and networking applications.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
},
{
"name": "MongoDB",
"link": "/terms/go_to_term/868"
},
{
"name": "NoSQL",
"link": "/terms/go_to_term/951"
},
{
"name": "Express.js",
"link": "/terms/go_to_term/392"
},
{
"name": "Angular.js",
"link": "/terms/go_to_term/47"
},
{
"name": "MVC",
"link": "/terms/go_to_term/201"
},
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
},
{
"termName": "Meteor",
"link": "/terms/javascript/meteor",
"info": "JavaScript framework built on top of Node.js with MongoDB as its database driver. With Node.js and Meteor, you’re using JavaScript everywhere, and data is synced through the use of WebSockets, a protocol that allows an interactive communication between server and browser.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
},
{
"name": "MongoDB",
"link": "/terms/go_to_term/868"
},
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
},
{
"name": "WebSockets",
"link": "/terms/go_to_term/1046"
}
],
"category": "JavaScript"
},
{
"termName": "Node.js",
"link": "/terms/javascript/nodejs",
"info": "One of the most popular JavaScript frameworks which eases the work of building web applications. By far the fastest growing language in use. Runs on Windows, Linux, and Mac OS. The use of Node.js is mainly for full stack, front-end and back-end.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
},
{
"name": "Windows",
"link": "/terms/go_to_term/1373"
},
{
"name": "Linux",
"link": "/terms/go_to_term/558"
},
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
},
{
"termName": "Oracle JET",
"link": "/terms/javascript/oracle_jet",
"info": "Oracle JavaScript Extension Toolkit. A modular toolkit based on modern JavaScript, CSS3 and HTML5 design and development principles. Created for developers who work on applications that consume and interact with Oracle products and services.",
"relatedTerms": [
],
"category": "JavaScript"
},
{
"termName": "Restify",
"link": "/terms/javascript/restify",
"info": "A Node.js module built specifically to enable to build correct REST web services. It borrows heavily from express as that is more or less the de facto API for writing web applications on top of Node.js.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
},
{
"name": "REST",
"link": "/terms/go_to_term/524"
},
{
"name": "API",
"link": "/terms/go_to_term/206"
}
],
"category": "JavaScript"
},
{
"termName": "Sails",
"link": "/terms/javascript/sails",
"info": "Sails.js wraps express and provides another higher level for doing things like connecting to the DB, auto-generating input pages, etc. Especially suitable for creating chat apps or multiplayer games.",
"relatedTerms": [
{
"name": "DB",
"link": "/terms/go_to_term/415"
}
],
"category": "JavaScript"
},
{
"termName": "Seneca",
"link": "/terms/javascript/seneca",
"info": "Microservices toolkit for Node.js. Helps to write an organized code that can be scaled and deployed at any time. Organizes the business logic of an app.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
}
]
}
My Expected Result looks like:
The following is my Query:
CALL apoc.load.json("file:///js.json") YIELD value
UNWIND value.JavaScript AS item
FOREACH(js IN item |
CREATE(cat:Category{name:js.termName})
FOREACH(rt in item.relatedTerms|
CREATE(rtt:RelatedTerms{name:rt.name})
MERGE (cat)-[r:RELATESTO]->(rtt)))
And here is my Actual Result:
Try switching the CREATE statements for MERGE statements. In Cypher, MERGE will check to see if a pattern exists and create it if it does not. CREATE will create a new pattern every time, even if a pattern like it already exists in the graph.
CALL apoc.load.json("file:///js.json") YIELD value
UNWIND value.JavaScript AS item
MERGE (cat:Category {name:item.termName})
WITH cat, item
UNWIND item.relatedTerms AS subitem
MERGE (rt:RelatedTerm {name:subitem.name})
MERGE (cat)-[:RELATES_TO]->(rt)
RETURN *

Powerapps difficulty accessing JSON in collection

I'm having difficulty accessing data in a collection, via PowerApps.
I create the collection with this:
Collect(coll15,mt.GetAnswers("3b....da","application/json",{question:"eco"}))
Using Developer Tools -> Network tab -> Response body - the following JSON data is returned:
{
"answers": [
{
"answer": "This is the answer",
"questions": [
"Private vehicle eco renewal"
],
"score": 82.901087775826454
}
]
}
The collection is created.
I then add a gallery control to my page - however the only options I have to bind to the labels are: ThisItem.Value
If I try to enter ThisItem.Value.answer I get the error: Invalid use of '.'
If I enter ThisItem.answers.answer I get the error: Invalid name
This is the swagger file:
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "mt",
"description": "mt"
},
"host": "westus.api.cognitive.microsoft.com:443",
"basePath": "/",
"schemes": [
"https"
],
"consumes": [],
"produces": [
"application/json"
],
"paths": {
"/qnamaker/v2.0/knowledgebases/eeeee.....eeeee/generateAnswer": {
"post": {
"summary": "GetAnswers",
"description": "Get answers from qna",
"operationId": "GetAnswers",
"parameters": [
{
"name": "body",
"in": "body",
"schema": {
"type": "object",
"properties": {
"question": {
"type": "string",
"description": "question",
"x-ms-summary": "question",
"title": "question",
"x-ms-visibility": ""
}
},
"default": {
"question": "hi"
},
"required": [
"question"
]
},
"required": true
}
],
"responses": {
"default": {
"description": "default",
"schema": {
"type": "string"
}
}
}
}
}
},
"definitions": {},
"parameters": {},
"responses": {},
"securityDefinitions": {
"api_key": {
"type": "apiKey",
"in": "header",
"name": "Ocp-Apim-Subscription-Key"
}
},
"security": [
{
"oauth2_auth": [
"Offline-Access"
]
}
],
"tags": []
}
Is there any way for me to access the answer text within the collection?
Thanks for any help,
Mark
The problem is that the response type for the operation in the connector definition is string:
"responses": {
"default": {
"description": "default",
"schema": {
"type": "string"
}
}
}
But your response is an object instead. If you update your custom connector to use a typed object instead, you should be able to access the response from the operation. Something along the lines of the schema below:
"responses": {
"default": {
"description": "default",
"schema": {
"type": "object",
"properties": {
"answers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"answer": {
"type": "string"
},
"questions": {
"type": "array",
"items": {
"type": "string"
}
},
"score": {
"type": "number",
"format": "float"
}
}
}
}
}
}
}
},
Notice that in the portal (web.powerapps.com), if you go to your custom connector definition, and select "Edit", you can go to the operation, and select the response you want to edit:
And then use the "Import from sample" option
With that, if you enter an example of a response from the API, it will create the schema for you (which is similar to the one I have above).

JSON API questions. Included vs relationships

I am reading this before building an API endpoints. I read this quote about compound documents:
To reduce the number of HTTP requests, servers MAY allow responses
that include related resources along with the requested primary
resources. Such responses are called "compound documents".
Here is a sample JSON response using the JSON API specification:
{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!"
},
"links": {
"self": "http://example.com/articles/1"
},
"relationships": {
"author": {
"links": {
"self": "http://example.com/articles/1/relationships/author",
"related": "http://example.com/articles/1/author"
},
"data": { "type": "people", "id": "9" }
},
"comments": {
"links": {
"self": "http://example.com/articles/1/relationships/comments",
"related": "http://example.com/articles/1/comments"
},
"data": [
{ "type": "comments", "id": "5" },
{ "type": "comments", "id": "12" }
]
}
}
}],
"included": [{
"type": "people",
"id": "9",
"attributes": {
"first-name": "Dan",
"last-name": "Gebhardt",
"twitter": "dgeb"
},
"links": {
"self": "http://example.com/people/9"
}
}, {
"type": "comments",
"id": "5",
"attributes": {
"body": "First!"
},
"relationships": {
"author": {
"data": { "type": "people", "id": "2" }
}
},
"links": {
"self": "http://example.com/comments/5"
}
}, {
"type": "comments",
"id": "12",
"attributes": {
"body": "I like XML better"
},
"relationships": {
"author": {
"data": { "type": "people", "id": "9" }
}
},
"links": {
"self": "http://example.com/comments/12"
}
}]
}
So from what I can see, the relationships sections give basic/sparse information about the associations between the articles table and other tables. It looks like an article belongs_to an author and has_many comments.
What will the links be used for? Will the API have to use the link in order to receive more detailed JSON about the relationship? Doesn't this require an additional API call? Is this efficient?
The "included" section seems like it contains more detailed information about the relationships/associations?
Are both "included" and "relationships" necessary? What's the intuition behind needing both of these sections?
The idea is that a relationship in a resource simply gives linkage data (that is basic data to uniquely identify the related resource – these data are the id and the type), in order to keep it to a minimum.
On the other hand, the included section is here in case you want to send along detailed information about some related resources (for instance to minimise the number of HTTP requests). Note that the included section is expected to contain only resources that are related to either a primary resource (i.e. within the data section), or an included resource (this constraint is called full linkage in the spec).
To put it simply, the relationships section of a resource tell you which resources are related to a given resource, and the included section tells you what those resources are.
As far as links are concerned, they may come in handy when you have a has_many relationship, for which the linkage data itself might contain several thousands of id/type records, thus making your response document quite big. In case those are not necessarily needed by your client when they request the base resource, you might decide to make them available through a link.

How can I describe complex json model in swagger

I'm trying to use Swagger to describe web-api I'm building.
The problem is that I can't understand how to describe complex json object?
For example, how to describe this objects:
{
name: "Jhon",
address: [
{
type: "home",
line1: "1st street"
},
{
type: "office",
line1: "2nd street"
}
]
}
Okay, so based on the comments above, you want the following schema:
{
"definitions": {
"user": {
"type": "object",
"required": [ "name" ],
"properties": {
"name": {
"type": "string"
},
"address": {
"type": "array",
"items": {
"$ref": "#/definitions/address"
}
}
}
},
"address": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [ "home", "office" ]
},
"line1": {
"type": "string"
}
}
}
}
}
I've made a few assumptions to make the sample a bit more complicated, to help in the future.
For the "user" object, I've declared that the "name" field is mandatory. If, for example, you also need the address to be mandatory, you can change the definition to "required": [ "name", "address" ].
We basically use a subset of json-schema to describe the models. Of course not everyone knows it, but it's fairly simple to learn and use.
For the address type you can see I also set the limit to two options - either home or office. You can add anything to that list, or remove the "enum" entirely to remove that constraint.
When the "type" of a property is "array", you need to accompany it with "items" which declares the internal type of the array. In this case, I referenced another definition, but that definition could have been inline as well. It's normally easier to maintain that way, especially if you need the "address" definition alone or within other models.
As requested, the inline version:
{
"definitions": {
"user": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
},
"address": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"home",
"office"
]
},
"line1": {
"type": "string"
}
}
}
}
}
}
}
}

How do I use the swagger models section?

Inside the Swagger API Documentation there is inside the json beside the apis array a model object entry but no documentation about it. How can I use this "models" part?
{
apiVersion: "0.2",
swaggerVersion: "1.1",
basePath: "http://petstore.swagger.wordnik.com/api",
resourcePath: "/pet.{format}"
...
apis: [...]
models: {...}
}
Models are nothing but like your POJO classes in java which have variables and properties. In models section you can define your own custom class and you can refer it as data type.
If you see below
{
"path": "/pet.{format}",
"description": "Operations about pets",
"operations": [
{
"httpMethod": "POST",
"summary": "Add a new pet to the store",
"responseClass": "void",
"nickname": "addPet",
"parameters": [
{
"description": "Pet object that needs to be added to the store",
"paramType": "body",
"required": true,
"allowMultiple": false,
"dataType": "Pet"
}
],
"errorResponses": [
{
"code": 405,
"reason": "Invalid input"
}
]
}
Here in parameter section it have one parameter who's dataType is Pet and pet is defined in models as below
{
"models": {
"Pet": {
"id": "Pet",
"properties": {
"id": {
"type": "long"
},
"status": {
"allowableValues": {
"valueType": "LIST",
"values": [
"available",
"pending",
"sold"
]
},
"description": "pet status in the store",
"type": "string"
},
"name": {
"type": "string"
},
"photoUrls": {
"items": {
"type": "string"
},
"type": "Array"
}
}
}
}}
You can have nested models , for more information see Swagger PetStore example
So models are nothing but like classes.

Resources