<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nukul Sharma on Medium]]></title>
        <description><![CDATA[Stories by Nukul Sharma on Medium]]></description>
        <link>https://medium.com/@nukulsharma?source=rss-bec283b39289------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*PnmbIPKDHoJPg_UD</url>
            <title>Stories by Nukul Sharma on Medium</title>
            <link>https://medium.com/@nukulsharma?source=rss-bec283b39289------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 22:11:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nukulsharma/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[RESTful API documentation with Swagger]]></title>
            <link>https://medium.com/@nukulsharma/restful-api-documentation-with-swagger-d85c73ef3524?source=rss-bec283b39289------2</link>
            <guid isPermaLink="false">https://medium.com/p/d85c73ef3524</guid>
            <category><![CDATA[swagger]]></category>
            <category><![CDATA[swagger-ui]]></category>
            <dc:creator><![CDATA[Nukul Sharma]]></dc:creator>
            <pubDate>Thu, 23 Aug 2018 17:12:08 GMT</pubDate>
            <atom:updated>2018-08-24T03:21:58.685Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gjXvmCX6N3GRdLe1" /><figcaption>Photo by <a href="https://unsplash.com/@rawpixel?utm_source=medium&amp;utm_medium=referral">rawpixel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4><a href="http://OpenAPI specifications">OpenAPI specifications</a>:</h4><p><strong><em>OAS 3.0 </em></strong><a href="https://swagger.io/docs/specification/about/">https://swagger.io/docs/specification/about/</a></p><p><strong><em>OAS 2.0</em></strong> <a href="https://swagger.io/docs/specification/2-0/basic-structure/">https://swagger.io/docs/specification/2-0/basic-structure/</a></p><h4>Consideration before documenting on Swagger:</h4><p>Make sure to choose between version 2.0 and 3.0, before starting documentation. OAS 2.0 documentation is well supported whilst OAS 3.0 makes it quite easy to document specifications, and comes with additional features. Both versions are not compatible, so one have to choose upfront considering the usage of swagger.</p><p><strong><em>Consider OAS 2.0 if any of following is intended:</em></strong></p><p>AWS API Gateway — one can easily load 2.0 spec to initiate API Gateway. OAIS 3.0 is not supported as of now.</p><p>Variety of conversion tools from swagger specs to HTML, PDF are available for version 2.0.</p><p>Stub (Client or Server) can easily be generated using OAS 2.0</p><p>Swagger inspector can load response schema for 2.0 but it fails to load for 3.0</p><p><strong><em>Consider OAS 3.0 which includes following features( Recommended):</em></strong></p><p>Enhanced Security Definitions</p><p>Simplified structure, with increased reusability</p><p>Multiple Spec response schema support on same HTTP code</p><p>And many more features…</p><h3>Writing your first specification</h3><p>I recommend using <a href="https://editor.swagger.io/">https://editor.swagger.io/</a> which loads petstore sample containing various samples to refer.</p><h3><strong>Customize Swagger UI</strong></h3><p>Setting up local developement environment</p><pre>Swagger-UI includes a development server that provides hot module reloading and unminified stack traces, for easier development.</pre><p>Pre-requisites</p><pre><em>- </em>Node.js <em>`6.0.0` </em>or greater<br><em>- </em>npm <em>`3.0.0` </em>or greater<br><em>- </em>git, any version</pre><p>Steps:</p><pre><em>1. git clone </em><a href="https://github.com/swagger-api/swagger-ui.git">https://github.com/swagger-api/swagger-ui.git</a></pre><pre><em>2. cd swagger-ui</em></pre><pre><em>3. npm install</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5EdcD_zGJvxuoD0TsR903Q.png" /><figcaption>terminal output: npm install</figcaption></figure><pre><em>4. npm run dev</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*5N7qHz1oDWPbZ1Vk3xk-1Q.png" /><figcaption>terminal output — npm run dev</figcaption></figure><pre><em>5. </em>Wait a bit<br><em>6. </em>Open http://localhost:3200/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*edk5hAY126jG4UmSDbcd9w.png" /><figcaption>local development instance execution</figcaption></figure><h4>Key notes:</h4><pre>The most useful file is <em>`swagger-ui-bundle.js`</em>, which is a build of Swagger-UI that includes all the code it needs to run in one file. The folder also has an <em>`index.html` </em>asset, to make it easy to serve Swagger-UI like so:</pre><blockquote>const express = require(&#39;express&#39;)<br>const pathToSwaggerUi = require(&#39;swagger-ui-dist&#39;).absolutePath()<br>const app = express()<br>app.use(express.static(pathToSwaggerUi))<br>app.listen(3000)</blockquote><pre>The module also exports <em>`SwaggerUIBundle` </em>and <em>`SwaggerUIStandalonePreset`</em>, so if you’re in a JavaScript project that can’t handle a traditional npm module, you could do something like this:</pre><blockquote>var SwaggerUIBundle = require(&#39;swagger-ui-dist&#39;).SwaggerUIBundle<br>const ui = SwaggerUIBundle({<br> url: &quot;https://petstore.swagger.io/v2/swagger.json&quot;,<br> dom_id: &#39;#swagger-ui&#39;,<br> presets: [<br> SwaggerUIBundle.presets.apis,<br> SwaggerUIBundle.SwaggerUIStandalonePreset<br> ],<br> layout: &quot;StandaloneLayout&quot;<br> })</blockquote><pre>SwaggerUIBundle is equivalent to SwaggerUI</pre><h3>Run using Docker:</h3><blockquote>docker pull swaggerapi/swagger-ui</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*Zl5vMsrllEnQCVDitJmKxw.png" /></figure><blockquote>docker run -p 80:8080 swaggerapi/swagger-ui</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*mwoH3QbNse4xqeEs9D7bLw.png" /></figure><pre>This will start nginx with swagger-ui on port 80.<br><br>Or you can provide your own swagger.json on your host</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Csjrb8NE_zUVOm38cW5nmA.png" /><figcaption>docker swagger execution</figcaption></figure><h4>Load your own spec:</h4><blockquote>docker run -p 80:8080 -e SWAGGER_JSON=/foo/sample_spec.json -v $PWD:/foo swaggerapi/swagger-ui</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0cTmHPV01iLWeO0B67CPFg.png" /></figure><h3>Documenting an existing API:</h3><p>We can use <a href="https://inspector.swagger.io/">https://inspector.swagger.io/</a> and generate OAS 2.0 or OAS 3.0 compliant specifications.</p><p>Ensure existing API is compliant to RESTful norms.</p><blockquote>Swagger Inspector is not free, limits documenting 3 APIs on free version. In addition, there is a limitation on OAS 3.0 in creating model for API responses.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d85c73ef3524" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>