Add new column in responses(Swagger-ui) - json

I am using Swagger-ui for the api documentation, when i come to responses i want to add a new column of any name in every response, screen shot is attached, highlighted text is ok, i want to add a new column at place of the circle.
My response JSON is
"responses" : {
"400" : {
"description" : "Invalid ID Supplied"
},
"404" : {
"description" : "Order not found"
}
}
how to add new column in it?
Is there any way type of Intellisense provided for Swagger-ui JSON?

You can extend the API Response objects coming off of your API endpoints only as far as the specification goes. In order to display that in the UI, though, you would have to fork the UI project and do as you please. Currently the UI does not seem to be extensible at that point (look for the table headers in the file).

Related

Using JSON to store template driven form data in Angular

I need to use JSON to store the form data, but I'm not sure how to go about it. I know I need to store all of the data that is gathered from text fields and radio buttons and then I need to make a form that displays the data. Can anyone point me to good resources for this? Or know how I can do this? I also need to know how I can access the data for another page since this is an application with two pages. One is for gathering data and the other is for displaying.
So basically to store form datas to JSON is simply create a JSON object and assign the form value to specified property inside that object.
my method is simple like this, on submit i add new object
let newValue = {
inputValue : this.form.value.input,
selectValue : this.form.value.select,
}
thats just for an example, assignin form value to the property of our new object. then to push the data to api simply like this
pushToAPIFunc(newValue);
and the result will be like this
{
"newValue" :{
"inputValue" : "inputValue",
"selectValue" : "selectValue"
}
}
to display that data, for example u have an edit page, u can use patchValue() of that JSON to your form, or assigning that data manually to each formControlName

Rendering to another html page [duplicate]

This question already has answers here:
How can I display a JavaScript object?
(40 answers)
Closed 7 years ago.
I have an object of objects and I want to iterate through the objects and show them in the browser; I have the following code, but it just shows me [object Object][object Object][object Object]; how can I show the actual objects?
my my_obj looks like:
{
"User": {
"description": "A user."
},
"Media": {
"description": "A media ."
}
}
var output = "";
for (var key in my_obj) {
output += my_obj[key];
}
response.send(output);
Thanks
It looks like this question is essentially a duplicate of yours.
The accepted answer for that question uses the console object to print the contents of the object to the JavaScript debugging console in the browser's developer tools (usually accessible with F12). You can typically interact with the object, expanding and collapsing its properties, in the logged output in the console.
console.log(my_obj);
However, this doesn't provide an easy way to print the contents of the object to the webpage. For that, you can follow the above-linked question's highest-voted answer, which uses the JSON object, specifically it's stringify method.
var my_obj_str = JSON.stringify(my_obj);
This method returns a stringified version of your object (i.e. it will appear like an object literal), which can then either be logged to the console like above (although it would be a string, not an interactive object!), or put into the webpage in whatever manner you like putting strings into webpage content.
You might need to use JSON.stringify() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

React - Rending JSON as UI objects and allowing any user changes to these UI objects to update the JSON

We have an internal tooling system that uses JSON to specify various actions, tasks etc. I'm making a single page web application to visualise this information. The web application contains a text area for editing/pasting JSON and another area which renders the JSON into UI elements.
So I want to take JSON from the text area and visualize it. But also, I want the user to be able to interact with this render visualization, making changes/configuring options and have it update the JSON immediately. I guess one could call that two-way binding.
While going from JSON -> HTML DOM elements is easy, I'm not sure how to do the reverse and go DOM -> JSON. Let's say we have some JSON
{"task1" : {
"canFail" : true,
"autoRestart" : false,
"connectionPropertys" : {
... }
}
}
I would visualize task1 as some UI element with check boxes for canFail and autoRestart. I want the user to be able to both
edit the JSON "canFail" value to 'true' or 'false' and have that
immediately render (this is easy - just re-render the entire JSON)
check or uncheck the canFail checkbox and have the JSON be
automatically updated (hard part - where I'm stuck)
In React we pass state/properties down the the children, so the component rending the checkbox(es) would only know about canFail or autoRestart... it might not know about "task1". If the checkbox is changed, sure I can have some handler function fire, but it doesn't actually know what key/value in the JSON this corresponds to (e.g. it knows nothing of task1 and there could be multiple task1s).
Interested to know what a good approach would be here to tackle this.
Thanks :)

Hangouts Chat Bot image card not refreshing

I am building a bot for Hangouts Chat. My bot will display a random image from a free image api. The api's URL is the same URL on each call but will get a new image. Unfortunately, my bot will not update the image. It just repost the same image on each call. I am using Google's App Script to deploy the bot. My image code is as follows:
function buildImageCard(url) {
return {
cards: [
{
sections: [
{
widgets: [
{
image: {
imageUrl: url
}
}
]
}
]
}
]
};
}
The random image shows up just like it should. The only issue is when I wan to call it again, it shows the same image. I can't seem to find a way to refresh the card. I have seen this method:
actionResponse: {type: shouldUpdate ? 'UPDATE_MESSAGE' : 'NEW_MESSAGE'},
Then pass shouldUpdate to buildImageCard. Although, nothing happens if shouldUpdate is true. What am I missing?
It seems that the problem is related with cache. Hangouts Chat is caching images so it doesn't need to download them everytime. You can try it by clearing the browser cache and updating the card with the chatbot. You should see the new image.
One thing you can do is to include a cachebreaker at the end of the url:
widgets: [
{
image: {
imageUrl: url + new Date().getTime()
}
}
]
As it's suggested here.
Also, in the same post, someone commented that this is not a good practice "as it will swamp caches (both local and upstream)". And they recommend a better solution, but in this case we cannot control Cache-Control headers.
I don't know how Hangouts Chat is managing the cache, but I guess they are taking care of it in case a bot uploads tons of different images. For example, in your case, it would be the same if you generate a new URL everytime you want to update it in the card, so I believe the cachebreaker could work for you.
I hope it helps!

Show NoData message on HighStock graph

I'm looking for a native way to display a message over an Highstock graph when there is no data to display or when an error occurs. In fact, I knew that the noData solution already exists for the Highchart library but it seems that it is not yet implemented in Highstock...
So, does anybody knows how to achieve this other than showing a message in a different div?
Thank you in advance for your time!
Keven
You can develop your own solution, based on extracting series object from highcharts. Then you check data length and show div or not.
if(series[0].data.length === 0) {
$('#nodata').show();
}
$('#container').highcharts({
chart: {},
series: series
});
Example: http://jsfiddle.net/3Bh7b/125/
Ok, after few days on UserVoice an administrator told me that the noData functionality is also available under Highstock (this functionality is not currently described in the API documentation).
This is the link of the admin reply (including a jsfiddle demo) :
https://highcharts.uservoice.com/forums/55896-highcharts-javascript-api/suggestions/8547274-highstock-display-a-message-when-nodata-is-avail
This is the link of the API reference (Highchart references) :
http://api.highcharts.com/highcharts#noData