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.
Related
I have a simple model class from which I need to generate the schema on Mongo DB Atlas. But I'm having troubles when it comes to defining RealmList<String> inside a JSON schema. If I insert "array" as a bsonType, I get an error. What should I write instead?
Model class:
class Note : RealmObject {
#PrimaryKey
var _id: ObjectId = ObjectId.create()
var title: String = ""
var description: String = ""
var images: RealmList<String> = realmListOf()
var date: RealmInstant = RealmInstant.from(System.currentTimeMillis(),0)
}
Current Schema:
{
"bsonType": "object",
"properties": {
"_id": {
"bsonType": "objectId"
},
"title": {
"bsonType": "string"
},
"description": {
"bsonType": "string"
},
"images": {
"bsonType": "array"
},
"date": {
"bsonType": "date"
}
},
"required": [
"_id",
"title",
"description",
"images",
"date"
],
"title": "Note"
}
I am not sure which mode you're using but if you're in development mode, when you add an object in the SDK, the server will automatically generate a matching object, as long as the changes are additive, like adding a new object or property
In the queston, the 'images' bson definition looks incomplete
"images": {
"bsonType": "array"
},
While it is an array, it's an array of strings so I believe it should look more like this
"images": {
"bsonType": "array",
"items": {
"bsonType": "string"
}
}
Where the type of items is defined as a string
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.
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.
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.
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.