All Projects → PowerShell → Psswagger

PowerShell / Psswagger

Licence: other
The cmdlet generator from OpenAPI (f.k.a Swagger) specification

Programming Languages

powershell
5483 projects

Projects that are alternatives of or similar to Psswagger

Restful React
A consistent, declarative way of interacting with RESTful backends, featuring code-generation from Swagger and OpenAPI specs 🔥
Stars: ✭ 1,814 (+1033.75%)
Mutual labels:  swagger, openapi
Terraform Provider Openapi
OpenAPI Terraform Provider that configures itself at runtime with the resources exposed by the service provider (defined in a swagger file)
Stars: ✭ 134 (-16.25%)
Mutual labels:  swagger, openapi
Graphql Mesh
GraphQL Mesh — Query anything, run anywhere
Stars: ✭ 2,114 (+1221.25%)
Mutual labels:  swagger, openapi
Open Api Renderer
🎩 A React renderer for OpenAPI v3.
Stars: ✭ 127 (-20.62%)
Mutual labels:  swagger, openapi
Swagger meqa
Auto generate and run tests using swagger/OpenAPI spec, no coding needed
Stars: ✭ 151 (-5.62%)
Mutual labels:  swagger, openapi
Angular Swagger Ui
An angularJS implementation of Swagger UI
Stars: ✭ 131 (-18.12%)
Mutual labels:  swagger, openapi
Prism
Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.
Stars: ✭ 2,484 (+1452.5%)
Mutual labels:  swagger, openapi
Wizard
Wizard是一款开源的文档管理工具,支持Markdown/Swagger/Table类型的文档。
Stars: ✭ 1,733 (+983.13%)
Mutual labels:  swagger, openapi
Gemini
Model Driven REST framework to automatically generate CRUD APIs
Stars: ✭ 138 (-13.75%)
Mutual labels:  swagger, openapi
Swaggerassertions
Assert your API requests and responses match with your swagger definition
Stars: ✭ 137 (-14.37%)
Mutual labels:  swagger, openapi
Vs Swagger Viewer
Swagger Viewer lets you preview and validate Swagger 2.0 and OpenAPI files as you type in Visual Studio Code.
Stars: ✭ 126 (-21.25%)
Mutual labels:  swagger, openapi
Swagger Axios Codegen
swagger client to use axios and typescript
Stars: ✭ 143 (-10.62%)
Mutual labels:  swagger, openapi
Grpc Gateway
The gRPC-Gateway is a plugin of the Google protocol buffers compiler protoc. It reads protobuf service definitions and generates a reverse-proxy server which translates a RESTful HTTP API into gRPC. This server is generated according to the google.api.http annotations in your service definitions.
Stars: ✭ 12,223 (+7539.38%)
Mutual labels:  swagger, openapi
Mentorship Backend
Mentorship System is an application that matches women in tech to mentor each other, on career development, through 1:1 relations during a certain period of time. This is the backend of this system.
Stars: ✭ 132 (-17.5%)
Mutual labels:  swagger, openapi
Http Router
🎉 Release 2.0 is released! Very fast HTTP router for PHP 7.1+ (incl. PHP8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger)
Stars: ✭ 124 (-22.5%)
Mutual labels:  swagger, openapi
Rapipdf
PDF generation from OpenAPI / Swagger Spec
Stars: ✭ 132 (-17.5%)
Mutual labels:  swagger, openapi
Openapi Core
OpenAPI core
Stars: ✭ 119 (-25.62%)
Mutual labels:  swagger, openapi
Netcoreblockly
.NET Core API to Blockly - generate from WebAPI, Swagger, OData, GraphQL =>
Stars: ✭ 121 (-24.37%)
Mutual labels:  swagger, openapi
Prance
Resolving Swagger/OpenAPI 2.0 and 3.0 Parser
Stars: ✭ 133 (-16.87%)
Mutual labels:  swagger, openapi
Express Oas Generator
OpenAPI (Swagger) specification generator for ExpressJS applications
Stars: ✭ 138 (-13.75%)
Mutual labels:  swagger, openapi

PSSwagger

A PowerShell module with commands to generate the PowerShell commands for a given RESTful Web Services using Swagger/OpenAPI documents.

PSSwagger is no longer being developed, but do not fret! AutoRest is now able to generate cmdlets directly, without needing PSSwagger. Please refer to: https://devblogs.microsoft.com/powershell/cmdlets-via-autorest/

This repository remains available for reference but pull requests and new issues will not be monitored.

PSSwagger Documentation

PSSwagger commands

Customizing PowerShell Metadata

Testing generated module

Supported Platforms

Usage Platforms
Developer Windows, PowerShell 5.1+, Latest PowerShell Core
Module Publisher PowerShell 5.1+
Module Consumer PowerShell 5.1+, Latest PowerShell Core

Future note: We plan on supporting PowerShell 4+ for module consumers in the future; that scenario is untested currently. Testing note: While any full PowerShell version is fine for development, we recommend using PowerShell 5.1+ to enable testing our implementation of Get-FileHash.

Dependencies

Dependency Version Description
AutoRest 0.17.3 or newer Tool to generate C# SDK from Swagger spec
CSC.exe (Microsoft.Net.Compilers) 2.3.1 or newer C# Compiler to generate C# SDK assembly on Windows PowerShell
Newtonsoft.Json Full CLR: 6.0.8, Core CLR: 9.0.1 NuGet package containing Newtonsoft.Json assembly, required for all modules
Microsoft.Rest.ClientRuntime 2.3.4 or newer NuGet package containing Microsoft.Rest.ClientRuntime assembly, required for all modules
Microsoft.Rest.ClientRuntime.Azure 3.3.4 or newer NuGet package containing Microsoft.Rest.ClientRuntime.Azure assembly, required for Microsoft Azure modules
AzureRM.Profile 2.0.0 or newer Module containing authentication helpers, required for Microsoft Azure modules on PowerShell
AzureRM.Profile.NetCore.Preview * Module containing authentication helpers, required for Microsoft Azure modules on PowerShell Core

Usage

NOTE: In the short term, for best performance, the operation IDs in your Open API specifications should be of the form "_". For example, the operation ID "Resource_GetByName" gets a resource named Resource by name.

  1. Get PSSwagger!

    • Install from PowerShellGallery.com
      Install-Module -Name PSSwagger
      
    • Clone the repository
      git clone https://github.com/PowerShell/PSSwagger.git
      
  2. Ensure AutoRest is installed and available in $env:PATH

    • Follow the instructions provided at AutoRest github repository.
    • Ensure AutoRest.cmd path is in $env:Path
      $env:path += ";$env:APPDATA\npm"
      Get-Command -Name AutoRest
      
  3. Ensure CSC.exe is installed and available in $env:PATH

    • If CSC.exe is not installed already, install Microsoft.Net.Compilers package
      Install-Package -Name Microsoft.Net.Compilers -Source https://www.nuget.org/api/v2 -Scope CurrentUser
      
    • Add CSC.exe path to $env:Path
      $package = Get-Package -Name Microsoft.Net.Compilers
      $env:path += ";$(Split-Path $package.Source -Parent)\tools"
      Get-Command -Name CSC.exe
      
  4. If you plan on pre-compiling the generated assembly, ensure you have the module AzureRM.Profile or AzureRM.NetCore.Preview available to PackageManagement if you are on PowerShell or PowerShell Core, respectively.

  5. Run the following in a PowerShell console from the directory where you cloned PSSwagger in

    # Import PSSwagger module
    Import-Module PSSwagger
    
    # If you are trying from a clone of this repository, follow below steps to import the PSSwagger module.
    # Ensure PSSwaggerUtility module is available in $env:PSModulePath
    # Please note the trialing back slash ('\') to ensure PSSwaggerUtility module is available.
    $PSSwaggerFolderPath = Resolve-Path '.\PSSwagger\'
    $env:PSModulePath = "$PSSwaggerFolderPath;$env:PSModulePath"
    Import-Module .\PSSwagger
    
    # Ensure PSSwagger module is loaded into the current session
    Get-Module PSSwagger
    
    # Prepare input parameters for cmdlet generation
    $null = New-Item -ItemType Directory -Path C:\GeneratedModules -Force
    $params = @{
      # Download the Open API v2 Specification from this location
      SpecificationUri = 'https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-batch/2015-12-01/swagger/BatchManagement.json'
      # Output the generated module to this path
      Path           = 'C:\GeneratedModules\'
      # Name of the generated module
      Name           = 'AzBatchManagement'
      # This specification is for a Microsoft Azure service, so use Azure-specific functionality
      UseAzureCsharpGenerator = $true
    }
    
    # You may be prompted to download missing dependencies
    New-PSSwaggerModule @params
    

    The generated module will be in the C:\Temp\GeneratedModule\Generated.AzureRM.BatchManagement folder. For more New-PSSwaggerModule options, check out the documentation.

  6. Your generated module is now ready! For production modules (i.e. modules you will publish to PowerShellGallery.com), we recommend using the -IncludeCoreFxAssembly option to generate the Core CLR assembly, strong name signing assemblies in the generated module, and authenticode signing the module. Optionally, you can remove the generated C# code (under the Generated.CSharp folder) for even more security.

Metadata Generation

There are many cases where module generation doesn't result in the most optimal names for things like parameters or commands. To enable this and many other customization options, we've introduced additional PowerShell-specific Open API extensions that can be specified separately from your main specification. For more information, check out PowerShell Extensions and New-PSSwaggerMetadataFile.

Dynamic generation of C# assembly

When importing the module for the first time, the packaged C# files will be automatically compiled if the expected assembly doesn't exist.

Microsoft.Rest.ServiceClientTracing support

To enable Microsoft.Rest.ServiceClientTracing support, pass -Debug into any generated command.

The included PowerShell tracer uses Write-Debug to write tracing messages.

When the module is imported to older version of PowerShell, the following steps will need to be taken:

  1. Implement either Microsoft.PowerShell.Commands.PSSwagger.PSSwaggerClientTracing or Microsoft.Rest.IServiceClientTracingInterceptor
  2. Call: [Microsoft.Rest.ServiceClientTracing]::AddTracingInterceptor($myTracer)
  3. If you use the Verbose or Debug streams of PowerShell, set $VerbosePreference or $DebugPreference, respectively

Note 1: We're not sure why yet, but something is setting [Microsoft.Rest.ServiceClientTracing]::IsEnabled to true before all cmdlet calls

Symbol Path

If the module's full CLR assembly is precompiled, the symbols folder will contain:

  1. Generated.cs - The C# code used to generate the assembly
  2. *.pdb - The corresponding PDB file that defines Generated.cs as the source file

Paging

When the "x-ms-pageable" extension is specified in the Swagger spec, paging is enabled in the generated module. This is true for both fragment URLs (when operationName is specified) and full URLs (when operationName is not specified).

A cmdlet that supports paging will have two additional optional parameters: -Paging: A switch parameter that specifies the cmdlet should only return the first page. To access the items, use $returnValue.Page -Page: Takes as input the last page return value and outputs the next page return value (again, to access the items, use $returnValue.Page). If the return value is null, no additional pages exist.

If -Paging is not specified and the cmdlet supports paging, the cmdlet will automatically unroll all pages. Assigning the result to a variable will result in all items being retrieved. Piping the cmdlet will result in pages being retrieved on-demand.

Silent execution when missing dependency packages

When dependency packages are expected to be missing, silent execution (bypassing the missing packages prompt) can be achieved by calling:

Import-Module PSSwaggerUtility
PSSwaggerUtility\Initialize-PSSwaggerDependencies -AcceptBootstrap -Azure

For Microsoft Azure modules, or:

Import-Module PSSwaggerUtility
PSSwaggerUtility\Initialize-PSSwaggerDependencies -AcceptBootstrap

For all other modules.

Notes

  1. Swagger Specification is at: http://swagger.io/specification/
  2. Azure ARM based Swagger documents at: https://github.com/Azure/azure-rest-api-specs
  3. AutoRest Generators: https://github.com/Azure/autorest/tree/master/src/generator

Developers

Testing

You can run tests right after cloning the repository. The test scripts should install the required packages. To run the tests, navigate to the Tests directory, then run:

.\run-tests.ps1 -TestFramework <framework> -Verbose -TestSuite <TestSuite> -TestName <TestName>

TestFramework should be one of "net452" | "netstandard1.7". If you are on Windows, you can use either net452, which uses the full CLR, or netstandard1.7, which uses the Core CLR. For Linux, Darwin, or Nano Server users, you will have to use netstandard1.7.

TestFramework defaults to net452

Use TestSuite or TestName parameters to filter by Pester Tag or test name.

What does the script do?

The script will ensure dependencies exist on your machine, like AutoRest, node.js, npm, json-server, and dotnet CLI. Then it will run pester tests in a separate PS session and validate no tests failed.

If dotnet CLI is already in your PS session's path, and you don't need to upgrade, you can use the parameter -SkipBootstrap to skip dotnet CLI bootstrapping and save lots of time.

Unit tests

Scenario Description
Get-InternalFileHash Tests that Get-InternalFileHash is equivalent to Get-FileHash in PS 5.1+

Scenario tests

The scenario test suite contains tests that hit actual (local) web API endpoints. The following scenarios are covered:

Scenario Description
PsSwaggerTestsBasic A very basic test of a single string-only path using get and post.

PSSwagger.LiveTestFramework

The PSSwagger implementation of the Azure Live Test Framework protocol is currently located in this repository in a subdirectory. Once PSSwaggerUtility is published to PowerShellGallery.com, the PSSwagger.LiveTestFramework code will be moved to a separate repository. You can find the readme for the PSSwagger.LiveTestFramework module here.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].