Moustache template for Swagger codegen static documentation - responseMessages - json

I am trying to use swagger-codegen to generate static-docs.
The docs are generated based on Moustache templates that are included in the project.
When I run it with the sample JSON from wordnik Swagger api-docs, it generates everything perfectly (every api has it's own .file like Pet.html, User.html), but when I try to run it with similar JSON of mine, it generates only 1 operations file containing all the methods of my REST api.
Wordnik JSON reponse can be found at worndik JSON api
Mine API response looks like this:
{"apiVersion":"1.0","swaggerVersion":"1.2","apis":[{"path":"/default/countries","description":"Operations about countries"},{"path":"/default/gateways","description":"Operations on payment gateways"},{"path":"/default/location","description":"Operations about locations"},{"path":"/default/mccs","description":"Operations about MCCs"},{"path":"/default/merchants","description":"Operations about merchants"},{"path":"/default/partners","description":"Operations about partners"},{"path":"/default/payments","description":"Operations about payments"},{"path":"/default/resources","description":"Operations about resources"},{"path":"/default/terminals","description":"Operations about terminals"},{"path":"/default/terminalsubsetdefaultresourceset","description":"Operations about terminalSubsetDefaultResourceSet"},{"path":"/default/users","description":"Operations about users"}],"info":{"title":"my API","description":"","termsOfServiceUrl":"","contact":"","license":"","licenseUrl":""}}
Also, I would like to extract ReponseMessage Codes in every operation that has them in JSON. I tried to add
{{#ResponseMessages}}
<h3 class="responseMessages">{{message}}</h3>
{{/ResponseMessages}}
to operations.model, but It doesn't work (not with myApi, nor with Wordnik) (I have similar JSON like this:JSON with responseCodes

You should be able to use the following (at least it works for me), based on the current version of Codegen.scala
{{#errorList}}
{{code}} {{reason}} {{responseModel}}
{{/errorList}}

Related

Render HAL formatted links in openapi3 json with SpringDoc

I'm running a Spring Boot REST application with Spring HATEOAS support and generating OpenAPIv3 docs with the Springdoc Maven plugin. However when I call my REST endpoints I get links the in HAL formatted JSON ("_links"). But the generated OpenAPIv3 documentation is giving me a different format for the links ("links").
How can I get the generated OpenAPIv3 docs to match the HAL formatted links?
The only resource I've found is this link: https://github.com/springdoc/springdoc-openapi/issues/446
However, the solution given there involves using spring-data-rest which I am not using (do I need to?)
I've also tried adding #EnableHyperMediaSupport which says it configures the JSON rendering, but that had no effect on the OpenAPIv3 docs.
The answer was simple enough, I needed to pull in the springdoc-openapi-hateoas dependency (https://springdoc.org/#spring-hateoas-support). After pulling this in the JSON documentation was generated correctly with no additional configuration (I did not need #EnableHypermediaSupport or spring-data-rest).
However, if you are using the Swagger UI be aware that it will automatically generate bogus 'additionalProperty' links as an example for the resource schema. This is only in the Swagger UI, if you look at the generated openapiv3 json the structure is correct (cf: https://github.com/springdoc/springdoc-openapi/issues/237). To remedy this you can provide your own example of the resource schema.

WP REST API v2 JSON endpoints appear difficult to read

I found WP REST API very interesting in making custom functionalities in WordPress websites. However, I find it hard to read my JSON endpoints' results.
The normal output of JSON endpoint is wrapped in html and pre tags. T result appears in one long line of compressed string.
I need to integrate my website to a mobile app to be done by another developer and I would like to display the API endpoints (e.g. link) to appear as a regular JSON Object like:
I'm trying to find a workaround like a hook or a filter to make the JSON results appear as I desired. Or equivalent AJAX related code would be nice.
I use a Chrome extension of JSON Formatter to view the results which prints out with readability in mind.
https://github.com/callumlocke/json-formatter

How does a .json file work in a API call?

I've been doing research in order to write an API for a school project, and when referencing the API documentation of YouTube and Twitter, I see API URLs like this
https://api.twitter.com/1.1/account/settings.json
My understanding was that you execute a method on the backend which will return information to the caller, but I thought those files had to be of extension type .py or .java or whatever language you're using, and JSON was just the return type. I've been unable to find any information on how a .json file works in this example. Is there code in settings.json that is being executed?
JSON is just a format of your data, that you can then use, for example in JavaScript.
It is back-end language independent. By this I mean, that front-end of the application does not care who produced .json file.
Maybe it was Java application, maybe it was Python, or PHP application it does not matter. It can be also static file, with fixed content which just has json format.
After you receive such thing in front-end, you can do with it whatever you want. From your perspective it will be probably some kind of nested array.
In example you provided, I get:
{"errors":[{"code":215,"message":"Bad Authentication data."}]}
And it is fine, it's just data you get. It is JSON format - that is true. But you don't care that path has .json in the URL, it could have any extension, what is important is what's inside.
That is a beauty of JSON. You can prepare for yourself static file with mocked data in JSON format, and use it while developing front-end of the application. When you wish, you can have back-end application which will return real data for your app.
You can also see here, how to return json file from PHP:
Returning JSON from a PHP Script
Or here to see how to do it in Python (Django Framework):
Creating a JSON response using Django and Python

Django rest swagger and json definition

I'm pretty new to Django and I'm currently working on a project where Django-rest-framework is used and the documentation is created with Swagger trough the django-rest-swagger package.
I'm trying to find (or generate) a swagger.json definition file, any idea on where it can be found with this package? I would like to use it to generate client side code.
Thanks
The swagger schema definition can be generated with https://github.com/signalfx/fetch-swagger-schema regardless the api implementation.
You can append ?format=openapi to the end of your docs URL and it will return the raw JSON text instead of the UI.
see here

How can I get the json object which represents a Yahoo! pipe

It seems that Yahoo pipes are represented using JSON. I want to download these JSON objects for some research purpose. Usually a Yahoo pipe is rendered in a browser editor thru a url like this: http://pipes.yahoo.com/pipes/pipe.edit?_id=XgRo96h13BGtJWvS8SvLAg, but you can't get the corresponding JSON object to this Yahoo pipe. Does anyone know how to get JSON objects representing Yahoo pipes and store them in any persistent form?
It is possible to get hold of a JSON description of a Yahoo Pipe using a URL of the form:
http://pipes.yahoo.com/pipes/pipe.info?_out=json&_id=PIPE_ID
The pipe2py python library demonstrates how to grab the JSON description of a pipe and "compile" it to a Python equivalent that can be run on your own server.
The post Exporting Yahoo Pipe Definitions, Compiling Them to Python, and Running Them in Scraperwiki describes how you can use pipe2py in the Scraperwiki environment to compile and execute pipes on Scraperwiki using pipe definitions imported directly from Yahoo Pipes, or exported from Yahoo Pipes and then stored locally in a Scraperwiki database table.
When I load that page in a browser I can see that it makes an ajax request for:
http://pipes.yahoo.com/pipes/ajax.pipe.load?id=XgRo96h13BGtJWvS8SvLAg&_out=json&modinfo=true&rnd=7560&.crumb=MjvGjpzhPLl
That's your object but I'm not sure if I'm answering your question of how to "get it". If you need to get it through a program you would need a script that loges into pipes and extracts that url.
A quick way, while not automated, is to use an HTTP analyzer. Here's a process for getting the object using HttpFox (I use v0.8.9) for Firefox. With the analyzer running, load the edit page for a pipe, like the one you linked:
http://pipes.yahoo.com/pipes/pipe.edit?_id=XgRo96h13BGtJWvS8SvLAg
Look at the request with a URL that starts with:
http://pipes.yahoo.com/pipes/ajax.pipe.load?id=....
Next, explore the content of the request (there's a 'Content' tab in HttpFox). That's the JSON object representing the pipe structure.
Use pipe.run?[your pipe id here]&_render=json as opposed to pipe.edit
So in your case to get the json it would be - http://pipes.yahoo.com/pipes/pipe.run?_id=XgRo96h13BGtJWvS8SvLAg&_render=json
I guess how you implement the client is dependent on what you like writing in/what other functionality you need.
You could also do it the other way around and use the web service service module to post the data to a script that can extract the json and persist it to a database. You could check out json.org.