Kendo DataSource and nested Json - json

I'm having trouble finding any documentation that accurately describes what to do in a situation like this.
I have the following schema for my DataSource:
schema: {
model: {
id: "Id",
fields: {
BuyerProfile: [
{
Id: { type: "number" },
Name: { type: "string" },
City: { type: "string" },
State: { type: "string" },
Description: { type: "string" },
BuyerType: [
{
Id: { type: "number" },
Name: { type: "string" }
}
]
}
]
}
}
}
My JSON is formatted fine and I don't get any errors. But when I try to print any of the items out in my kendo template I just get undefined printed.
For example:
<script type="text/x-kendo-tmpl" id="profileTemplate">
<p> #:BuyerProfile.Name# </p>
</script>
The above example is literally just printing out undefined inside of the p tags. No JavaScript errors or anything though.
I might be wrong but I thought I read somewhere that this is how you go about using nested JSON objects with Kendo. However, it's clearly not since it's not working or I'm missing something.

Answer you are looking is probably here or here. Basically you either need to parse your schema or just make you schema flat without any nested properties.

Related

Is it possible to put multiple unnamed nested objects inside of an array in an openAPI YAML file?

I am writing a openapi specification in YAML and I want to have this JSON code as a YAML file for a openAPI specification:
{
"example": [
{
"example1":
{
"type": "string"
} ,
"example2":
{
"type":"string"
}
},
{
"example1":
{
"type": "string"
},
"example2":
{
"type": "string"
},
}
]
}
I tried:
schema:
type: object
properties:
example:
type: array
items:
type: object
properties:
example1:
type: string
example2:
type: string
type: object
properties:
example1:
type: string
example2:
type: string
But you cannot have properties again because every map key has to be unique.

How to create a Json object from the Schema definitions of swagger

I am failing to to remove the outer array from the json request body that I want swagger to generate from the schema definitions.
I want to generate this object:
{
"name":
{
"value": "test04"
},
"mail": {
"value": "test04#gmail.com"
}
}
But swagger is giving me this:
[
{
"name": {
"value": "string"
},
"mail": {
"value": "string"
}
}
]
This is my definition section:
definitions:
user:
type: "object"
properties:
name:
type: object
properties:
value:
type: string
mail:
type: object
properties:
value:
type: string
May you kindly assist. I am new to swagger. I am using version 2.0
Your User schema is correct, so this means there's an extra type: array somewhere in the parameter, request body, or response where this schema is used.

How to prevent nested models with OpenAPI Codegen?

Input JSON
I have huge JSON. This is an excerpt of it.
{
"base.get.v1.Input": {
"properties": {
"request": {
"$ref": "#/components/schemas/base.get.v1.Input.Request"
},
"id": {
"maxLength": 128,
"type": "string"
}
},
"required": ["id"],
"type": "object"
}
}
Output interface
Using OpenApi-generator-cli-3.0.0.jar i get the following typescript file (relative to che part of JSON showed before):
import { BaseGetV1InputRequest } from './baseGetV1InputRequest';
export interface BaseGetV1Input {
request?: BaseGetV1InputRequest;
trid: string;
}
Desired result
Is there a way to have the request object (and subsequent objects) be expanded (solver or exploded, whatever term you prefer). I would like the final interface to be like that:
import { BaseGetV1InputRequest } from './baseGetV1InputRequest';
export interface BaseGetV1Input {
request?: {
entity?: {
code?: 0,
id?: string
},
procedure?: string,
search?: {
type?: "starts" | "contains",
value?: string
}
},
trid: string
}
Tested solutions that don't work
I have tried to solve the $ref myself using json-schema-ref-parser but i think the codegen creates a sub-model when it finds properties inside of the input JSON.
I have also tried w/ and w/o mustache templates (that someone else got me). But the output didn't change.
I'm fairly new to OpenAPI, hope you can help me.

How can I describe this complex json model in swagger

I'm trying to use swagger to describe a rest api I added to some code.
This is one of my simple returns.
Saw a couple good examples but didn't have any luck trying to make sense how to apply it to my problem.
The different API calls will contain different content.
If I know what this one should look like I aught to be able to figure the others out.
Can anyone tell me what this description should look like?
{
"result" : {
"content" : {
"UNTAINTED_HOST" : "www.google.com",
"DATA" : [
"216.58.217.36"
],
"IP_or_NAME" : "NAME",
"RC" : "true",
"FAULT_MSG" : "No Faults"
},
"detail" : "Sucessfully terminated your request",
"short" : "Done" }
}
Or this even simpler one:
{
"result" : {
"short" : "Done",
"detail" : "Sucessfully terminated your request",
"content" : "Running"
}
}
Think it would look like -
{
"definitions": {
"result": {
"type": "object",
"required": [
"short", "detail", "content"
],
"properties": {
"type": "array",
"items": {
"type": "object",
"properties": {
"content": {
"type": "string"
},
"detail": {
"type": "string"
},
"short": {
"type": "string"
},
}
}
}
}
}
}
Tried this in the swagger editor... seems I missed something.
definitions:
results:
type: object
required: [ result ]
properties:
result:
type: array
items:
$ref: #/definitions/result
result:
type: object
properties:
short:
type: string
detail:
type: string
content:
type: string
This seemed to work:
results:
type: object
required: [ result ]
properties:
result:
type: array
items:
type: object
required: [ short, detail, content ]
properties:
short:
type: string
detail:
type: string
content:
type: string
Thanks
This worked for me:
definitions:
result:
type: object
properties:
short:
type: string
detail:
type: string
content:
type: string
results:
type: object
required: [result]
properties:
result:
type: array
items:
$ref: '#/definitions/result'
Notice the single quotes around the value of $ref. I didn't see those in your original post. However, you didn't mention the error you are seeing. If this answer doesn't help, please update your question with more details.

Mongoose - How can I make this data more usable?

I have the following data strucutre outputting form my Schema in a node/express app. I'd like to have the feeds array simply an array of name:key pairs. I don't like the sort of weird numbered object structure going on between "feeds" and the actual feeds data. But i can't figure out how to manually define that in mongoose. any help would be awesome. thanks!
outputted JSON
{
"title": "Testing",
"created_at": "2011-10-05T16:23:26.217Z",
"feeds": [{
"0": {
"name": "twitter",
"key": "person1"
},
"1": {
"name": "twitter",
"key": "person2"
},
"_id": "4e8c847e02edc10035000003"
}]
}
i want this:
{
"title": "Testing",
"created_at": "2011-10-05T16:23:26.217Z",
"feeds": [
{
"name": "twitter",
"key": "person1"
},
{
"name": "twitter",
"key": "person2"
}
],
"_id": "4e8c847e02edc10035000003"
}
this is my schema:
var Feed = new Schema({
name : { type: String }
, key : { type: String }
});
var Page = new Schema({
title : { type: String, required: true, index: { unique: true } }
, feeds : [Feed]
, created_at : { type: Date, required: true, default: Date.now }
});
Ok, a colleague was able to answer this for me. My bad for not posting the relevant code, I didn't realize where the problem actually was. But for those who may encounter this problem:
If you push your embedded docs into the model when saving, you may need to do a forEach loop rather than pushing the embedded docs (in this case Feeds) together. Using forEach, the database saved the feeds directly to the feeds array rather than creating those weird groupings.
This pushed the feeds in properly:
req.body.feed.forEach(function(feed){
page.feeds.push(feed);
});
Let me know if you have the same problem and need more explanation.