Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for OpenAPI 3.x Callbacks #1157

Closed
mdaneri opened this issue Oct 8, 2023 · 0 comments
Closed

Support for OpenAPI 3.x Callbacks #1157

mdaneri opened this issue Oct 8, 2023 · 0 comments
Milestone

Comments

@mdaneri
Copy link
Contributor

mdaneri commented Oct 8, 2023

Feature

Add support for OpenAPI 3.x Callbacks

New Functions

  • Add-PodeOACallBack
  • New-PodeOAResponse
  • Add-PodeOAComponentCallBack

Impacted Functions

  • Add-PodeRoute

Parameters

Add-PodeOACallBack
  • -Path
    Specifies the callback path, usually a relative URL.
    The key that identifies the Path Item Object is a runtime expression evaluated in the context of a runtime HTTP request/response to identify the URL for the callback request.
    A simple example is $request.body#/url.
    The runtime expression allows complete access to the HTTP message, including any part of a body that a JSON Pointer (RFC6901) can reference.
    More information on JSON Pointer can be found at RFC6901.

  • -Name
    Alias for 'Name'. A unique identifier for the callback.
    It must be a valid string of alphanumeric characters, periods (.), hyphens (-), and underscores (_).

  • -Reference
    A reference to a reusable CallBack component.

  • -Method
    Defines the HTTP method for the callback (e.g., GET, POST, PUT). Supports standard HTTP methods and a wildcard (*) for all methods.

  • -Parameters
    The Parameter definitions the request uses (from ConvertTo-PodeOAParameter).

  • -RequestBody
    Defines the schema of the request body. Can be set using New-PodeOARequestBody.

  • -Responses
    Defines the possible responses for the callback. Can be set using New-PodeOAResponse.

  • -DefinitionTag
    An Array of strings representing the unique tag for the API specification.
    This tag helps in distinguishing between different versions or types of API specifications within the application.
    You can use this tag to reference the specific API documentation, schema, or version that your function interacts with.

Add-PodeOAComponentCallBack
  • -Path
    Specifies the callback path, usually a relative URL.
    The key that identifies the Path Item Object is a runtime expression evaluated in the context of a runtime HTTP request/response to identify the URL for the callback request.
    A simple example is $request.body#/url.
    The runtime expression allows complete access to the HTTP message, including any part of a body that a JSON Pointer (RFC6901) can reference.
    More information on JSON Pointer can be found at RFC6901.

  • -Name
    Alias for 'Name'. A unique identifier for the callback.
    It must be a valid string of alphanumeric characters, periods (.), hyphens (-), and underscores (_).

  • -Method
    Defines the HTTP method for the callback (e.g., GET, POST, PUT). Supports standard HTTP methods and a wildcard (*) for all methods.

  • -Parameters
    The Parameter definitions the request uses (from ConvertTo-PodeOAParameter).

  • -RequestBody
    Defines the schema of the request body. Can be set using New-PodeOARequestBody.

  • -Responses
    Defines the possible responses for the callback. Can be set using New-PodeOAResponse.

  • -DefinitionTag
    An Array of strings representing the unique tag for the API specification.
    This tag helps in distinguishing between different versions or types of API specifications within the application.
    You can use this tag to reference the specific API documentation, schema, or version that your function interacts with.

Example

Add-PodeOACallBack

 Add-PodeRoute -PassThru -Method Post -Path '/petcallback'  -Authentication 'Login-OAuth2' -Scope 'write'  -ScriptBlock {
#code
            } | Set-PodeOARouteInfo -Summary 'Add a new pet to the store' -Description 'Add a new pet to the store' -Tags 'pet' -OperationId 'addPetcallback' -PassThru |
                Set-PodeOARequest -RequestBody (New-PodeOARequestBody -Reference 'PetBodySchema' ) -PassThru |
                Add-PodeOAResponse -StatusCode 200 -Description 'Successful operation' -Content (New-PodeOAContentMediaType -MediaType 'application/json', 'application/xml' -Content 'Pet' ) -PassThru |
                Add-PodeOAResponse -StatusCode 405 -Description 'Validation exception' -Content @{
                    'application/json' = (New-PodeOAObjectProperty -Properties @(    (New-PodeOAStringProperty -Name 'result'), (New-PodeOAStringProperty -Name 'message')  ))
                } -PassThru |
                Add-PodeOACallBack -Name 'test' -Path '{$request.body#/id}' -Method Post  -RequestBody (New-PodeOARequestBody -Content @{'*/*' = (New-PodeOAStringProperty -Name 'id') } ) `
                    -Response (
                    New-PodeOAResponse -StatusCode 200 -Description 'Successful operation' -Content (New-PodeOAContentMediaType -MediaType 'application/json', 'application/xml' -Content 'Pet' -Array) |
                        New-PodeOAResponse -StatusCode 400 -Description 'Invalid ID supplied' |
                        New-PodeOAResponse -StatusCode 404 -Description 'Pet not found' |
                        New-PodeOAResponse -Default   -Description 'Something is wrong'
                    )

Add-PodeOAComponentCallBack

Add-PodeOAComponentCallBack -Name 'test' -Path '{$request.body#/id}' -Method Post  -RequestBody (New-PodeOARequestBody -Content @{'*/*' = (New-PodeOAStringProperty -Name 'id') } ) `
                    -Response (
                    New-PodeOAResponse -StatusCode 200 -Description 'Successful operation' -Content (New-PodeOAContentMediaType -MediaType 'application/json', 'application/xml' -Content 'Pet' -Array) |
                        New-PodeOAResponse -StatusCode 400 -Description 'Invalid ID supplied' |
                        New-PodeOAResponse -StatusCode 404 -Description 'Pet not found' |
                        New-PodeOAResponse -Default   -Description 'Something is wrong'
                    )

 Add-PodeRoute -PassThru -Method Post -Path '/petcallback'  -Authentication 'Login-OAuth2' -Scope 'write'  -ScriptBlock { 
#code
            } | Set-PodeOARouteInfo -Summary 'Add a new pet to the store' -Description 'Add a new pet to the store' -Tags 'pet' -OperationId 'addPetcallback' -PassThru |
                Set-PodeOARequest -RequestBody (New-PodeOARequestBody -Reference 'PetBodySchema' ) -PassThru |
                Add-PodeOAResponse -StatusCode 200 -Description 'Successful operation' -Content (New-PodeOAContentMediaType -MediaType 'application/json', 'application/xml' -Content 'Pet' ) -PassThru |
                Add-PodeOAResponse -StatusCode 405 -Description 'Validation exception' -Content @{
                    'application/json' = (New-PodeOAObjectProperty -Properties @(    (New-PodeOAStringProperty -Name 'result'), (New-PodeOAStringProperty -Name 'message')  ))
                } -PassThru |
                Add-PodeOACallBack -Reference 'test'  
@mdaneri mdaneri changed the title Support for OpenAPI Callbacks Support for OpenAPI 3.x Callbacks Dec 28, 2023
@Badgerati Badgerati added this to the 2.10.0 milestone Apr 13, 2024
Badgerati pushed a commit that referenced this issue Apr 14, 2024
* fixes

* replace [void] with $null =

* [switch] vs bool

* minor fixes

* remove Pode.sln

* fixes

Fix an issue with YAML and http string
fix an issue with multiple objects and allOf/oneOf/anyOff
fix #1177 When the Access-Control-Allow-Headers is *, the Authorization has to be explicitly  listed

Still some issues with Test-PodeOARequestSchema when allOf is present

* fix to Test-PodeOARequestSchema

* Set-PodeSecurityAccessControl headers and methods auto-popuate

Set-PodeSecurityAccessControl now can automatically populate headers and methods. No more '*' are required

* code compliance

* added some references to the help

* fix an issue with merge and objects

* Fix $Return

* first openapitest

* additional tests

* Additional tests

* new tests and buf fixes

* fixes and tests

* additional tests

* Update tests to be Pester 5.5 compatible

Updated all tests to be 5.x compatible
Upgrade Pester to 5.5
additional OpenApi tests
bug fixes

* Update OpenAPI.md

* Update OpenAPI.md

* documentation 1st addition

* Documentation and fixes

Test [order] on OpenAPI fixed
Added assembly version to C# DLL
Added OpenAPI 3.0.3 doc - work in progress

* docs and cmdlet changes

* Add-PodeOAInfo test fix

* new openapi auth

Add OAuth2 OpenAPI support
Fix #1182
added new API documentation

* fix OpenApi Authentication

* fixes

* fixes

* OpenApi doc addiction

* reorg properties

* Add exemples

* fix examples

* examples property fixes

* improvements

* added aditional PodeOAParam

* Support for .Net8 and PWSH 7.4

Added support for pwsh 7.4 and .Net8
Added .Net8 DLL build
Fixes to ConvertTo-PodeOAParameter
Pester fixes

* Added support for RFC1866

* Added support for encoding

Added support for OpenApi RequestBody encoding definition #1190
Fix an issue with YAML conversion where a number is converted to string
Additional OpenApi documentation related to encoding

* fixes

* header response support

* Default OAproperty fix

* report pwsh version during build

* fix an compatibility with pwsh<7.3

* Create PSScriptAnalyzer.yml

* powershell test

* build fix for desktop pwsh

* upgrade invokeBuild

* .

* .

* VSCode made me crazy

* .

* added pwsh 7.4

* Add pwsh version check

* update actions to v3

* changed version on pode.build

* try pwsh 7.4 test

* modified:   .github/workflows/ci-pwsh7_4.yml

* added macos to 7.4

* fix mac

* .

* .

* add chmod

* added 7.3 test

* fixes

* .

* fix version print

* new corner cases

* New Features and 3 new cmdlets

Added support for File Uploads #1160
Added support for Response Links #1158  (Add-PodeOAResponseLink)
Added support for Callbacks #1157 (Add-PodeOACallBacksResponse) (Add-PodeOACallBacks)

* fix Cmdlet names

* various improvements

* Added new Route OAResponses param

* Add New-PodeOAMediaContentType

* fixes and improvements

* fix openapi test

* fix a text replacement went wrong

* Doc changes

* change to  Test-PodeOAJsonSchemaCompliance

* fix Petstore

* test fix

* remove default response option

* Added support for OA3.1

Open API 3.1 #1193
Fix an issue with example accepting only string

* Added components for links and callback

* fix content link,callback

* Fix test

* change default responses

* Added support for route auth and anon

* Improved XML elements parameters

* fix openapi test

* fix openapi test syntax error

* added documentation + fix -AdditionalProperties

* fix an response header issue. cleanup PetStore

* Petstore Sample+ convert xml to hash

* fixes

* add new New-PodeOAMultiTypeProperty for 3.1 multitype support

* petstore

* completed petstore sample

* Fix server test

* Review OpenAPI Doc and fix some property name

* doc changes

* docs update

* Split OpenApi to 3 files

* first drop for multi openapi definitions

* cleanup parameters + fixes

* OpenApi support for Path Server + fixes

OpenApi support for Path Servers #1201
OpenApi documentation update
fixes

* doc fix

* Change $OAtag to $SpecTag

* Added SpeTag to public OpenaAPI

* Multi OpenApi documents support

Now is possible to define multiple OpenAPI documents with different characteristic and assign it to different path

* Change property name from SpecTag to DefinitionTag

* Add help to Add-PodeComponentGroup

* Add webhook and fix headers reference

* fix header test

* Add a new server configuration DefaultOADefinitionTag

* Fix tests

* fixes

* fixes

* fix parameters  help test

* test fixes + Select-PodeOADefinition use a stack

* fix openapi test

* documentation update

* fix the restart server

* fix server test

* new docs

* minor update

* fix openapi test

* swagger pump to last version

* State OpenAPI definition at server start

New Features addressed
- #1193
- #1203
- #1205
- #1209
- #1190
- #1160
- #1157
- #1201
- #1213
- #1206
- #1204
- #1212
- #1202
- #1168
- #1212
- #1218
- #1219
- #1157
- #1211
- #1220
- #1164
- #1210
- #1215
- #1214
- #1216
- #1224
- #1225

* fix an OpenAPI spec Tag issue + build improvements

* Add support for recursive components

FIx #1088

* fix OpenAPI test

* fix an issue with PodeOAViewer and endpoints

* fix pode.build InstallCurrentUser

* Fix a version comparison issue with DLL

* fix an issue with testing

* fixes

* Add Swagger-Editor as OpenAPI editor

* added Enable-PodeOAViewer  -Editor documentation

* fix a wrong function call

* set default path for  Enable-PodeOAViewer

* Added authentication to Enable-PodeOpenApi and Enable-PodeOAViewer

* fixes

* Update license.txt

* update license year

* Invoke-PodeAuthValidation parallel validation with PowershellS >7.x

* Badgerati recommendation

* Badgerati recommendation

* fix tests

* new static web example

* .

* Matthew recommendations

+ new PrivateOpenAPI test
+ added comments and headers to some private OpenAPI functions
+ fix a bug with New-PodeOResponseInternal OpenAPI `Description` response property

* review docs

* fixes

fix an issue with Test-PodeOAJsonSchemaCompliance relate to definition tags
add remove-module task to Pode.build.ps1
rename installcurrentuser to install-module in  Pode.build.ps1

* Update Security.ps1

fix to solve Access-Control-Allow-Methods requires all methods to be uppercase  requirement

* more headers and tests

* Documentation fixes

+ package support for Linux build

* more private/OpenAPI.ps1 tests and inline comments

* fix Initialize-OpenApiTable Tests on Pws 5.1, change default OAViewer path

* build cross-platform improvements

* fix the checksum issue on linux

* improved build clean

* Added a new build guide

* fix a workflow issue with versions

* additional comment and test to private/OpenApi.ps1

* move build.md under docs

* Move build.md to Getting-Started

* build.md added MacOS

* fix an issue with schema Validation when oneof and anyof is part of the schema

* Implement File Browsing feature #1237

* Fix the random file generator

* added -FileBrowser to Start-PodeStaticServer Add-PodeStaticRouteGroup

Start-PodeStaticServer Add-PodeStaticRouteGroup now have -FileBrowser  switch
New function `Write-PodeDirectoryResponse`
changed if else indentation for compliancy

* Code is working but test is failing

* Reorganize Write-PodeFileResponse

* FileBrowser and Default page fixes

Solve the issue with the static page and Default pages. Now the default page is loaded correctly with the right link
Cleanup folders check functions

* support for independent static paths

Now each static path is independent.
FileBrowser.ps1 sample implement 3 distinct routes with different settings

* Get-PodeRouteByUrl improvement

Now Get-PodeRouteByUrl is using a regex to find the right route solving the problem when path include *(/something/*/test) or a Path parameter like (/something/:mystuff/test)

* fix tests

* Added Mathew fix for static routes order + fix openapi auth with static route

* Address the problem with static path containing /*/ + some cleanup

New helper Get-PodeUrlPart to address url path with *
New internal function Write-PodeAttachmentResponseInternal used to replace internally the public Set-PodeResponseAttachment.
Set-PodeResponseAttachment now is calling Write-PodeAttachmentResponseInternal
Find-PodeStaticRoute now accept a new RequestUrl param that represent the user url ( to manage /*/ url)

* Fix an issue with public and Set-PodeResponseAttachment

* fix Write-PodeAttachmentResponseInternal

* added PSScriptAnalyzer.psd1 ExcludeRules = @('PSAvoidUsingCmdletAliases' ,'PSAvoidUsingPlainTextForPassword')

* add ConvertTo-PodeYamlInternal test and fix an issue with the conversion with -nonewline and array

* fix ConvertTo-PodeYamlInternal test

* fix spaces in  ConvertTo-PodeYamlInternal test

* Fix PodeSession tests `Should Throw` is not allowed in 5.5 `Should -Throw` is the right syntax

* .

* moved PSScriptAnalyzerSettings.psd1 to root

* PSScriptAnalyzer and Customizable Default Folder Paths

Enhancing Flexibility with Customizable Default Folder Paths in Pode #1243
Incorporate PSScriptAnalyzerSettings for Enhanced Code Quality #1244
+
Modified test script to be excluded by PSScriptAnalyzer
Implemented some of PSScriptAnalyzer recommendation
+
added multiple function headers

* GitHub Actions: Transitioning from Node 16 to Node 20

* Update PSScriptAnalyzer.yml

* rollback process{}

* Rollback the Pattern/Route logic

* Fix the issue with broswing a path with *
Added documentation for -FileBrowser feature

* Fix an issue when a default file(index.htm) is on root and -FileBrowser is used

* Move Write-PodeFileResponse internal call to Write-PodeFileResponseInternal

* fix a test issue

* fix an security issue durieng a pegasus scan

* Adding server.psd1 new properties documentation

* fix an issue withe external OpenAPI requests

* update github workflow

* fix a label for pwsh 7.5

* doc fixes

* workaround for https rest test with powershell 7.4.x

* cleanup

* change curl.exe to curl for linux compatibility

* fix test for linux and mac

* reinstate SkipCertificateCheck

* fix desktop

* restore Server.test.ps1

* new file:   .github/workflows/ci-pwsh7_2.yml
 	modified:   pode.build.ps1
 	modified:   src/Pode.psd1
 	modified:   src/Pode.psm1
 	modified:   src/Private/Server.ps1

* .

* .

* .

* .

* .

* .

* Create SECURITY.md

* Add Versioning functions

* .

* Update pode.build.ps1

* fix an issue with build

* fix build

* fix configuration.md

* Update StaticContent.md

* review-1

* docs update

* fix issues reported by  _Test

* Documentation fixes

* first round

* second round

* Third iteration

* Fix ConvertTo-PodeYamlInternal Tests
@github-project-automation github-project-automation bot moved this from Backlog to Done in 🚀 Pode Roadmap Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants