Are there custom properties in openapi 3? - swagger

We have php-swagger which generates developer documentation in open api 3.0 format.
There was a task - to make OTHER documentation based on the generated api-docs.json, for clients with a limited number of routes, static (without the ability to send requests). Just make a stripped down new openapi 3.0 format json file
It turns out that you need to somehow mark the annotations in the code that these are annotations for OTHER documentation. And create a new json file.
The problem is that I don’t know how to mark the routes at the annotation level in the php code, so that there would be some FEATURE in the description of the route, thanks to which I could parse api-docs.json and extract routes with this feature from it.

You could use vendor extensions https://zircote.github.io/swagger-php/guide/common-techniques.html#vendor-extensions
These are part of the standard but ignored so you can use them in whatever way you like.

Related

Customization And Localization Of abp.io Default Validation Error Messages

How can I Customize And Localize Of abp.io Default Validation Error Messages ?
I would add translated message for another language, instead of "The {fieldName} field is required."
How to do it in abp.io ?
You should see the Extending Existing Resource section here. AbpValidationResource is the resource type. You can find all the localization keys here.
I suggest you to fully read and understand the Localization document. Then you can make it easily. You will create translation JSON files in your application, make the files "embedded" then extend the resource.
If you want to add a new language and contribute to the ABP Framework, you can also see the Resource Localization section of the contribution guide.

Can the swagger editor online take a YAML url as input through the address bar?

I want to access https://editor.swagger.io/ but need the YAML file to be preloaded based on a URL parameter.
So if I want to view https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/petstore.yaml, I should be able to provide this as an input to swagger editor accessible over the internet.
Is this possible?
Yes, Swagger Editor supports the url parameter:
https://editor.swagger.io/?url=https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
Note that to load OpenAPI files from GitHub/GitLab/Bitbucket/etc., you need to specify the "raw" file link.
Also, for this to work, the server where the YAML/JSON file is hosted must use HTTPS and support CORS (i.e. allow cross-domain calls from editor.swagger.io).

How to export swagger.json (or yaml)

How can I export a Swagger definition file? It should be a JSON or YAML file, e.g. swagger.json or swagger.yaml.
Let's say I have an endpoint looking like http://example.com//swagger/ui/index#!:
The version is api version: v1.
There is no "Export" button that I can see. So how do I export it?
The URL of the API definiton is displayed in the top bar of Swagger UI – in your example it's
/v2/api-docs?group=full-petstore-api
So the full URL appears to be
http://localhost:8080/v2/api-docs?group=full-petstore-api
In newer versions of Swagger UI, the link to the API definition is often displayed below the API title, so you can right-click the link and Save As.
If your Swagger UI does not have a visible link to the API definition, view the page source and look for the url parameter, such as:
const ui = SwaggerUIBundle({
url: "https://petstore.swagger.io/v2/swagger.json", // <-------
dom_id: '#swagger-ui',
If you don't see the url or if url is a code expression, open the browser dev tools, switch to the Network tab and disable caching. Then refresh the page and search for the API definition file (swagger.json, swagger.yaml, api-docs or similar) among HTTP requests. You can filter by XHR to narrow down the list.
Another way to find the actual url is to use the browser console and evaluate one of the following values, depending on your UI version:
Swagger UI 3.x:
ui.getConfigs().url
Swagger UI 2.x:
swaggerUi.api.url
Sometimes the OpenAPI definition may be embedded within a .js file – in this case take this file and strip out the extra parts.
Though it's already been answered and it's the correct one, I thought I shall post the much detailed version of it.. Hope this helps,
If you do have the swagger json file which you feed to the swagger UI, then to generate .yaml file just click on the below link copy-paste your json in the editor and download the yaml file. This is a straight forward method
link : https://editor.swagger.io/#
Now the second way where you don't have any swagger json file then the following steps should help,
Open the swagger ui, inspect (Shift+Ctrl+i), refresh the page and you will get the tabs like below
Choose XHR or All tab under Network tab, check for the file api-doc?group=* and click subtab response. *Now copy the content of ap-doc?group.** file and use the same editor link to convert to yaml file
link : https://editor.swagger.io/#
The JSON may also be inlined in the document, specifically for Swagger version 2.0. If you haven't found anything after walking through #Helen's answer give this a try:
View Page Source
Search for "swagger" or "spec"
If you see a <script type="application/json"> tag with something similar to the following in it, this is effectively your swagger.json content. Copy everything inside of the <script> tags and save into a file named swagger.json and you should be good to go.
<script id="swagger-data" type="application/json">
{"spec":{"definitions":{},"info":{},"paths":{},"schemes":[],"swagger":"2.0"}}
</script>
I'm using Django Rest Framework (so pip package django-rest-swagger==2.2.0) and the above answers weren't really sufficient. There were two options:
1) View the page source with developer tools. When I hit my http://localhost:8000/docs/ endpoint, I see:
The docs/ endpoint was configured in Django, so it may be different for you. When digging into the details of that, I can go to the Response tab (in Chrome) and scroll down to find the actual JSON. It's the value in window.drsSpec
2) The alternative (and perhaps easier) approach is to add ?format=openapi to my endpoint, as suggested in https://github.com/marcgibbons/django-rest-swagger/issues/590
This will directly spit out the JSON you need. I imported it into Postman by changing the swagger field to openapi which seems a little hacky but it worked πŸ€·πŸ»β€β™‚οΈ
for
Swashbuckel.aspnet.core(5.5.0)
try
services.AddControllers()
.AddJsonOptions(options =>
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
I tried this for a Web API core Project
you have to be using
System.Text.Json.Serialization;
Visit http://localhost:49846/swagger/docs/v1
The above URL will return JSON. Save the JSON as swagger.json
Please replace the port number with your port number.
This could be achieved using JUnit test case in compile time, follow https://github.com/springfox/springfox/issues/1959 for more details.

Choose a tools to documents REST API

I actually use Doxygen to document my php REST application and I just discover Apiary & Swagger witch seem to be good tools to document API...I want to know if there is a way to generate documentation automatically using one of this tools (apiary or swagger ) based on the code comments?
Using swagger-php you can generate the documentation automatically from a collection of php scripts documented using annotations.
Swagger-PHP is decently documented here: http://zircote.com/swagger-php/
A working example can be found on github: https://github.com/zircote/swagger-php/tree/master/Examples/Petstore
Regarding the generation of the json file containing the documentation check my answer here: https://stackoverflow.com/a/31178997/2853903

Resources for learning to output xml from rails?

I would like to use rails to output xml on a request from a client (Android device). I have gleaned from web searches that .builder.xml files are the way to go for this, but I cannot find a single tutorial or guide to get me started that is newer that 2006.. does anyone know of a good resource for xml and rails?
It's probably best to look at the official XML Builder homepage and follow/try the examples there: http://builder.rubyforge.org/
You can use XML Builder in both your controller or in your views, the code is the same. However, inside an .builder view you already have access to a builder instance via the "xml" variable. See: http://danengle.us/2009/05/generating-custom-xml-for-your-rails-app/
Take a look at this article about XML Builder.
I also highly recommend you to use Nokogiri to generate XML.

Resources