How to Export Swagger.Json- OpenAPI without tools

Export SwaggerJson Export Swagger json yaml

Today in this article, we will see How to Export Swagger.Json without tools using existing available API endpoint URLs

What is Swagger.JSON

Swagger is the entire schema definition of your API. Swagger JSON contains the entire schema with details on the endpoint, request, and response object supported by your API.

Swagger or OpenAPI describes the standards and specifications for the RESTFul API description. These specifications are an attempt to create a universal and language agnostic description for describing the REST API and its capability.

If you are already following recent OpenAPI V3.0 specifications which are guidelines and specifications around how the API documentation should be then you will inbuilt capability on generating the API documentation by using the Swagger UI feature.

This swagger UI feature is supported in all types of languages including .NET, Java, Python, etc.

Example using.NET Core

The below example demonstrates the ASP.NET Core API example.

How to Export SwaggerJson

The above swagger document will be available in the path swagger/v1/swagger.JSON.

Export SwaggerJson

If using Javascript or Python or other languages

If you are using any Javascript or Python or other languages, please make sure you enable Swagger UI with the route details.

Example 1 – Node Js and Express

const specs = swaggerJsondoc(options);
app.use("/docs", swaggerUi.serve);
 
 
app.get(
  "/docs",
  swaggerUi.setup(specs, {
    explorer: true
  })
);

For more details visit the below article,

Example 2

var SwaggerUIBundle = require('swagger-ui-dist').SwaggerUIBundle
const ui = SwaggerUIBundle({
    url: "https://petstore.swagger.io/v2/swagger.json",
    dom_id: '#swagger-ui',
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIBundle.SwaggerUIStandalonePreset
    ]
  })

Alternate Approach – Works in any language

If Swagger UI does not have a link to the API definition as above then please follow the below steps,

  • Open the browser Dev tools-> Click on the Network. – Inspect -> Shift+Ctrl+I,
  • Next refresh the page.
  • Search for the API definition file like swagger.jsonswagger.yamlapi-docs etc. in the requests.
  • Filter by All or XHR as needed.

In the example below under the response tab, you are set to get the Swagger.Json file.

swaggerjson swaggeryaml api docs or similar among HTTP requests

Do you have any comments or ideas or any better suggestions to share?

Please sound off your comments below.

Happy Coding !!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



Leave a Reply

Your email address will not be published. Required fields are marked *