<?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 Ghufran Zahidi on Medium]]></title>
        <description><![CDATA[Stories by Ghufran Zahidi on Medium]]></description>
        <link>https://medium.com/@ghufz.learn?source=rss-44111fa9fcb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5VCvEo1eA3d1tyZJvM4-gA.jpeg</url>
            <title>Stories by Ghufran Zahidi on Medium</title>
            <link>https://medium.com/@ghufz.learn?source=rss-44111fa9fcb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 20 Jun 2026 05:36:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ghufz.learn/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[Generate PowerShellSDK using openapi-generator]]></title>
            <link>https://medium.com/@ghufz.learn/generate-powershellsdk-using-openapi-generator-33b700891e33?source=rss-44111fa9fcb------2</link>
            <guid isPermaLink="false">https://medium.com/p/33b700891e33</guid>
            <category><![CDATA[powershell]]></category>
            <category><![CDATA[open-api]]></category>
            <category><![CDATA[openapi-generator]]></category>
            <category><![CDATA[sdk]]></category>
            <dc:creator><![CDATA[Ghufran Zahidi]]></dc:creator>
            <pubDate>Tue, 15 Sep 2020 16:44:22 GMT</pubDate>
            <atom:updated>2020-09-15T16:44:22.938Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://github.com/OpenAPITools/openapi-generator">OpenAPI generator</a> generates the client side PowerShellSDK by given a OpenAPI document. PowerShellSDK generated by the openapi-generator can be used out of the box without any changes.</p><p>Here is the some benefit of powershell sdk</p><ol><li>No dependency on c# code. It is pure PowerShell script.</li><li>HTTPSigning supported out of the box for RSA and ECDSA key.</li><li>Cookies and API Key Auth supported.</li><li>It is based on OpenAPI Spec 3.0.1.</li><li>Generated Sdk is compatible with PowerShell 5.1 and above, It is recommended to use PowerShell v7.</li></ol><p>I want to give a little highlight for <a href="https://github.com/OpenAPITools/openapi-generator">openapi-generator</a>, It is build upon java , it provides SDK generator for most of the languages. One can check the supported language with following command.</p><pre>Java -jar ./openapi-generator-cli.jar list</pre><p>see the help related to sdk generator by using below command</p><pre>Java -jar ./openapi-generator-cli.jar help generate</pre><p>To generate the PowerShell SDK I am referring the Petstore OpenAPI document which can be found at below link.</p><p><a href="https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/powershell/petstore.yaml">OpenAPITools/openapi-generator</a></p><p>Command to generate the PowerShell SDK</p><pre>Java -jar ./openapi-generator-cli.jar generate -i ./Petstore.yaml -o ./Petstore-PowerShellSDK -c .\PowerShellConfig.Yaml -g powershell<br></pre><p>Here is the brief of parameter used for sdk generation</p><ul><li>generate :- Command to generate the SDK</li><li>-g or — generator-name :- specify the generator name (refer to the command for list of supported languages)</li></ul><pre>java ./openapi-generator-cli.jar list</pre><ul><li>-i or — input-spec :- Location of the OpenAPI document , it can be a url or file path</li><li>-o or — output :- Specify the output directory where to write the generated files.</li><li>-c or — config :- specify the language specific configurations. it can be yaml or json file. for more about the configuration files refer to below command. <em>it is an optional parameter</em>.</li></ul><pre>java -jar ./openapi-generator-cli.jar config-help -g powershell </pre><p>Here is the sample config file for PowerShellSDK</p><pre>#Package guid to uniquely identify the module.<br>packageGuid: e4848b95-3695-4d55-92b9-744a153d2bc7</pre><pre>#User can map the Verbs as per PowerShell supported verbs.Like below #PowerShell does not support the Verb Delete so it is mapped with #the verb Remove<br>commonVerbs: Delete=Remove:Patch=Update</pre><pre>#Module package version<br>packageVersion: 1.0.2</pre><pre>#Module name <br>packageName: PSPetstore</pre><pre>#PowerShell gallery url if module is published on PowerShell gallery<br>powershellGalleryUrl: <a href="https://www.powershellgallery.com/packages/PSPetstore">https://www.powershellgallery.com/packages/PSPetstore</a></pre><pre>#Prefix for the cmdlet<br>apiNamePrefix: PS</pre><pre>#Minimum supported PowerShell version.<br>powershellVersion: &quot;7.0&quot;</pre><p>Once the PowerShellSDK is generated, user needs to run the <em>Build.ps1</em> script which generates the.psd1 file for the generated module.</p><p>The generated PowerShellSDK has following folder layout.</p><pre>├───.openapi-generator<br>├───docs<br>├───src<br>│   └───PSPetstore<br>│       ├───Api<br>│       ├───Client<br>│       ├───en-US<br>│       ├───Model<br>│       └───Private</pre><pre>└───tests<br>    ├───Api<br>    └───Model</pre><p>Here is the brief of the above folder layout</p><blockquote>docs :- It contains the generated docs for API and Model</blockquote><blockquote>src :- This folder contains the generated PowerShell SDK, The folder Api contains the Cmdlet to perform the operation. The folder Model contains the model based on the OpenAPI doc schema. It contains ConvertTo-&lt;Name&gt; and Initialize-&lt;Name&gt; cmdlets. ConevrtTo-&lt;Name&gt; cmdlets are internally used by the API cmldets to validate the server response as per OpebAPI doc. The Initiailize-&lt;Noun&gt; cmdlet is used to generate the PSObject which can be directly passed to the cmdlet (New and Set cmdlets). The folder Client provides the cmdlet to perform the environment configuration like</blockquote><blockquote>Set-Configuration -BaseUrl &quot;https://petstore.com&quot; -Cookies &quot;xyxxxxxxx&quot;</blockquote><blockquote>src folder contains the .psd1 and .psm1 files.</blockquote><blockquote>tests:- tests folder contains the Pester test for Api and Model folder. it provides the place holder user needs to add the specific test case based on the cmdlet behaviour.</blockquote><p><strong>Using the PowerShell SDK</strong></p><p>After running the Build.ps1 script, import the module and follow the below steps to connect to the remote server and use the generated cmdlets.</p><pre>PS c:/&gt; Import-Module -Name .\src\PSPetstore</pre><pre>#Verify the module is imported by following cmdlet.<br>PS C:/&gt; Get-Module<br><br>ModuleType Version    Name         ExportedCommands<br>---------- -------    ----         ----------------<br>Script     1.0.2      PSPetstore    {Add-PSPet, ConvertFrom-PSJsonToApiResponse, ConvertFrom-PSJsonToCategory, ConvertFrom-PSJsonToInlineObject…}</pre><pre>#Configure the url and Auth configuration<br>PS C:/&gt; Set-PSConfiguration -BaseUrl &quot;https://petstore.xyz.com&quot; -cookie &#39;Token=&quot;jgjgcjshdchdsgcjsdhgc&quot;&#39;</pre><pre>Once the the url and Auth configuration is done user can verify the same by using the cmdlet </pre><pre>PS C:/&gt; Get-PSConfiguration</pre><pre>Name                           Value<br>----                           -----<br>Username<br>ApiKeyPrefix                   {}<br>Cookie                         Token=&quot;jgjgcjshdchdsgcjsdhgc&quot; <br>BaseUrl                        <a href="http://petstore.swagger.io:80/v2">http://petstore.xyz.com</a><br>AccessToken<br>DefaultHeaders                 {}<br>ApiKey                         {}<br>Password<br>SkipCertificateCheck           False</pre><p><strong>Happy learning :-)</strong></p><p>For more about OpenAPI refer to <a href="https://www.openapis.org/">https://www.openapis.org/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33b700891e33" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>