Skip to content

Commit

Permalink
Add presentation and codegen script for first part of the session
Browse files Browse the repository at this point in the history
  • Loading branch information
dpecanha committed May 8, 2023
1 parent 43dbef8 commit ad9effb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Binary file not shown.
51 changes: 51 additions & 0 deletions Code-Generation-by-daniele-pecanha-n-zhenhao-ye/mustache_demo.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#more details and credits to: https://github.com/swagger-api/swagger-codegen/tree/master

# get swagger generator
#wget https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.31/swagger-codegen-cli-2.4.31.jar -O swagger-codegen-cli.jar

# download swagger schema
Invoke-WebRequest -Uri https://petstore.swagger.io/v2/swagger.yaml -o swagger.yaml

# generate ps code
java -jar swagger-codegen-cli.jar generate -i .\swagger.yaml -l powershell -o petstore/powershell

# try to import
import-Module .\petstore\powershell\src\IO.Swagger\\IO.Swagger.psm1

#generate csharp code
java -jar swagger-codegen-cli.jar generate -i .\swagger.yaml -l csharp -o petstore/powershell/csharp/SwaggerClient

# build ps module
./petstore/powershell/Build.ps1

# Import module
cd .\petstore\powershell\src\IO.Swagger
import-Module .\IO.Swagger.psd1 -Force

# list cmdlets
Get-Command -module IO.Swagger

# get help
Get-Help Invoke-StoreApiPlaceOrder -Full

# place order
$order = New-Order -id 1 -petId 125 -quantity 1 -shipDate (Get-Date) -status approved -complete $true
Invoke-StoreApiPlaceOrder -body $order


# Try again with mustache templates:
cd ../../../../

# TODO: get mustache templates from
# https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources/powershell

# TODO: update api.mustache with your preferences

# regenerate with templates
java -jar swagger-codegen-cli.jar generate -i .\swagger.yaml -l powershell -o petstore/powershell -t .\mustache
./petstore/powershell/Build.ps1

# Import module
cd .\petstore\powershell\src\IO.Swagger
import-Module .\IO.Swagger.psd1 -Force
Get-Command -module IO.Swagger

0 comments on commit ad9effb

Please sign in to comment.