Skip to content

Commit

Permalink
internazioanalization+ example
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaneri committed Nov 5, 2024
1 parent b64da21 commit 7db258a
Show file tree
Hide file tree
Showing 22 changed files with 455 additions and 85 deletions.
12 changes: 0 additions & 12 deletions examples/PetStore/Petstore-OpenApi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -895,17 +895,5 @@ Some useful links:
Set-PodeOARequest -Parameters ( New-PodeOAStringProperty -Name 'username' -Description 'The name that needs to be deleted.' -Required | ConvertTo-PodeOAParameter -In Path ) -PassThru |
Add-PodeOAResponse -StatusCode 400 -Description 'Invalid username supplied' -PassThru |
Add-PodeOAResponse -StatusCode 404 -Description 'User not found'

Add-PodeRoute -PassThru -Method Get -Path '/dump' -ScriptBlock {
$format = $WebEvent.Query['format']
try {
# Simulate a critical error
throw [System.DivideByZeroException] 'Simulated divide by zero error'
}
catch {
$_ | Invoke-PodeDump -Format $format
}
} | Set-PodeOARouteInfo -Summary 'Dump state' -Description 'Dump the memory state of the server.' -Tags 'dump' -OperationId 'dump'-PassThru |
Set-PodeOARequest -Parameters (New-PodeOAStringProperty -Name 'format' -Description 'Dump export format.' -Enum 'json', 'clixml', 'txt', 'bin', 'yaml' -Default 'json' | ConvertTo-PodeOAParameter -In Query )
}
}
91 changes: 91 additions & 0 deletions examples/Web-Dump.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<#
.SYNOPSIS
Initializes and starts a Pode server with OpenAPI support and error logging.
.DESCRIPTION
This script sets up a Pode server with HTTP endpoints, error logging, and OpenAPI documentation.
It also includes a sample route to simulate a critical error and dump the server's memory state.
.EXAMPLE
To run the sample: ./Web-Dump.ps1
OpenAPI Info:
Specification:
http://localhost:8081/openapi
Documentation:
http://localhost:8081/docs
.LINK
https://github.com/Badgerati/Pode/blob/develop/examples/Web-Dump.ps1
.NOTES
Author: Pode Team
License: MIT License
#>

try {
# Determine the script path and Pode module path
$ScriptPath = (Split-Path -Parent -Path $MyInvocation.MyCommand.Path)
$podePath = Split-Path -Parent -Path $ScriptPath

# Import the Pode module from the source path if it exists, otherwise from installed modules
if (Test-Path -Path "$($podePath)/src/Pode.psm1" -PathType Leaf) {
Import-Module "$($podePath)/src/Pode.psm1" -Force -ErrorAction Stop
}
else {
Import-Module -Name 'Pode' -MaximumVersion 2.99 -ErrorAction Stop
}
}
catch { throw }

# Start Pode server with specified script block
Start-PodeServer -Threads 1 -ScriptBlock {

# listen on localhost:8081
Add-PodeEndpoint -Address localhost -Port 8081 -Protocol Http

# set view engine to pode renderer
Set-PodeViewEngine -Type Pode

# Enable error logging
New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging


# Enable OpenAPI documentation

Enable-PodeOpenApi -Path '/docs/openapi' -OpenApiVersion '3.0.3' -DisableMinimalDefinitions -NoDefaultResponses

Add-PodeOAInfo -Title 'Dump - OpenAPI 3.0.3' -Version 1.0.1
Add-PodeOAServerEndpoint -url '/api/v3' -Description 'default endpoint'

# Enable OpenAPI viewers
Enable-PodeOAViewer -Type Swagger -Path '/docs/swagger'
Enable-PodeOAViewer -Type ReDoc -Path '/docs/redoc' -DarkMode
Enable-PodeOAViewer -Type RapiDoc -Path '/docs/rapidoc' -DarkMode
Enable-PodeOAViewer -Type StopLight -Path '/docs/stoplight' -DarkMode
Enable-PodeOAViewer -Type Explorer -Path '/docs/explorer' -DarkMode
Enable-PodeOAViewer -Type RapiPdf -Path '/docs/rapipdf' -DarkMode

# Enable OpenAPI editor and bookmarks
Enable-PodeOAViewer -Editor -Path '/docs/swagger-editor'
Enable-PodeOAViewer -Bookmarks -Path '/docs'

# Setup session details
Enable-PodeSessionMiddleware -Duration 120 -Extend

# Define API routes
Add-PodeRouteGroup -Path '/api/v3' -Routes {

Add-PodeRoute -PassThru -Method Get -Path '/dump' -ScriptBlock {
$format = $WebEvent.Query['format']
try {
# Simulate a critical error
throw [System.DivideByZeroException] 'Simulated divide by zero error'
}
catch {
$_ | Invoke-PodeDump -Format $format
}
} | Set-PodeOARouteInfo -Summary 'Dump state' -Description 'Dump the memory state of the server.' -Tags 'dump' -OperationId 'dump'-PassThru |
Set-PodeOARequest -Parameters (New-PodeOAStringProperty -Name 'format' -Description 'Dump export format.' -Enum 'json', 'clixml', 'txt', 'bin', 'yaml' -Default 'json' | ConvertTo-PodeOAParameter -In Query )
}
}
14 changes: 13 additions & 1 deletion src/Locales/ar/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,17 @@
getRequestBodyNotAllowedExceptionMessage = "'{0}' لا يمكن أن يحتوي على جسم الطلب. استخدم -AllowNonStandardBody لتجاوز هذا التقييد."
fnDoesNotAcceptArrayAsPipelineInputExceptionMessage = "الدالة '{0}' لا تقبل مصفوفة كمدخل لأنبوب البيانات."
unsupportedStreamCompressionEncodingExceptionMessage = 'تشفير الضغط غير مدعوم للتشفير {0}'
LocalEndpointConflictExceptionMessage = "تم تعريف كل من '{0}' و '{1}' كنقاط نهاية محلية لـ OpenAPI، لكن يُسمح فقط بنقطة نهاية محلية واحدة لكل تعريف API."
localEndpointConflictExceptionMessage = "تم تعريف كل من '{0}' و '{1}' كنقاط نهاية محلية لـ OpenAPI، لكن يُسمح فقط بنقطة نهاية محلية واحدة لكل تعريف API."
suspendingMessage = 'تعليق الخادم...'
resumingMessage = 'استئناف الخادم...'
serverControlCommandsTitle = 'أوامر التحكم بالخادم:'
gracefullyTerminateMessage = 'إنهاء الخادم بلطف.'
restartServerMessage = 'إعادة تشغيل الخادم وتحميل التكوينات.'
resumeServerMessage = 'استئناف الخادم.'
suspendServerMessage = 'تعليق الخادم.'
generateDiagnosticDumpMessage = 'إنشاء تفريغ تشخيصي لأغراض التصحيح.'
initializingMessage = 'جارٍ التهيئة'
restartingMessage = 'جارٍ إعادة التشغيل'
suspendedMessage = 'معلق'
runningMessage = 'يعمل'
}
14 changes: 13 additions & 1 deletion src/Locales/de/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,17 @@
getRequestBodyNotAllowedExceptionMessage = "'{0}' Operationen dürfen keinen Anfragekörper haben. Verwenden Sie -AllowNonStandardBody, um diese Einschränkung zu umgehen."
fnDoesNotAcceptArrayAsPipelineInputExceptionMessage = "Die Funktion '{0}' akzeptiert kein Array als Pipeline-Eingabe."
unsupportedStreamCompressionEncodingExceptionMessage = 'Die Stream-Komprimierungskodierung wird nicht unterstützt: {0}'
LocalEndpointConflictExceptionMessage = "Sowohl '{0}' als auch '{1}' sind als lokale OpenAPI-Endpunkte definiert, aber es ist nur ein lokaler Endpunkt pro API-Definition erlaubt."
localEndpointConflictExceptionMessage = "Sowohl '{0}' als auch '{1}' sind als lokale OpenAPI-Endpunkte definiert, aber es ist nur ein lokaler Endpunkt pro API-Definition erlaubt."
suspendingMessage = 'Server wird angehalten...'
resumingMessage = 'Server wird fortgesetzt...'
serverControlCommandsTitle = 'Serversteuerbefehle:'
gracefullyTerminateMessage = 'Server sanft beenden.'
restartServerMessage = 'Server neu starten und Konfigurationen laden.'
resumeServerMessage = 'Server fortsetzen.'
suspendServerMessage = 'Server anhalten.'
generateDiagnosticDumpMessage = 'Diagnostischen Dump für Debuggingzwecke erstellen.'
initializingMessage = 'Initialisierung'
restartingMessage = 'Neustart'
suspendedMessage = 'Angehalten'
runningMessage = 'Läuft'
}
15 changes: 14 additions & 1 deletion src/Locales/en-us/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,17 @@
getRequestBodyNotAllowedExceptionMessage = "'{0}' operations cannot have a Request Body. Use -AllowNonStandardBody to override this restriction."
fnDoesNotAcceptArrayAsPipelineInputExceptionMessage = "The function '{0}' does not accept an array as pipeline input."
unsupportedStreamCompressionEncodingExceptionMessage = 'Unsupported stream compression encoding: {0}'
LocalEndpointConflictExceptionMessage = "Both '{0}' and '{1}' are defined as local OpenAPI endpoints, but only one local endpoint is allowed per API definition."}
localEndpointConflictExceptionMessage = "Both '{0}' and '{1}' are defined as local OpenAPI endpoints, but only one local endpoint is allowed per API definition."
suspendingMessage = 'Suspending server...'
resumingMessage = 'Resuming server...'
serverControlCommandsTitle = 'Server Control Commands:'
gracefullyTerminateMessage = 'Gracefully terminate the server.'
restartServerMessage = 'Restart the server and reload configurations.'
resumeServerMessage = 'Resume the server.'
suspendServerMessage = 'Suspend the server.'
generateDiagnosticDumpMessage = 'Generate a diagnostic dump for debugging purposes.'
initializingMessage = 'Initializing'
restartingMessage = 'Restarting'
suspendedMessage = 'Suspended'
runningMessage = 'Running'
}
14 changes: 13 additions & 1 deletion src/Locales/en/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,17 @@
getRequestBodyNotAllowedExceptionMessage = "'{0}' operations cannot have a Request Body. Use -AllowNonStandardBody to override this restriction."
fnDoesNotAcceptArrayAsPipelineInputExceptionMessage = "The function '{0}' does not accept an array as pipeline input."
unsupportedStreamCompressionEncodingExceptionMessage = 'Unsupported stream compression encoding: {0}'
LocalEndpointConflictExceptionMessage = "Both '{0}' and '{1}' are defined as local OpenAPI endpoints, but only one local endpoint is allowed per API definition."
localEndpointConflictExceptionMessage = "Both '{0}' and '{1}' are defined as local OpenAPI endpoints, but only one local endpoint is allowed per API definition."
suspendingMessage = 'Suspending server...'
resumingMessage = 'Resuming server...'
serverControlCommandsTitle = 'Server Control Commands:'
gracefullyTerminateMessage = 'Gracefully terminate the server.'
restartServerMessage = 'Restart the server and reload configurations.'
resumeServerMessage = 'Resume the server.'
suspendServerMessage = 'Suspend the server.'
generateDiagnosticDumpMessage = 'Generate a diagnostic dump for debugging purposes.'
initializingMessage = 'Initialising'
restartingMessage = 'Restarting'
suspendedMessage = 'Suspended'
runningMessage = 'Running'
}
14 changes: 13 additions & 1 deletion src/Locales/es/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,17 @@
getRequestBodyNotAllowedExceptionMessage = "Las operaciones '{0}' no pueden tener un cuerpo de solicitud. Use -AllowNonStandardBody para evitar esta restricción."
fnDoesNotAcceptArrayAsPipelineInputExceptionMessage = "La función '{0}' no acepta una matriz como entrada de canalización."
unsupportedStreamCompressionEncodingExceptionMessage = 'La codificación de compresión de transmisión no es compatible: {0}'
LocalEndpointConflictExceptionMessage = "Tanto '{0}' como '{1}' están definidos como puntos finales locales de OpenAPI, pero solo se permite un punto final local por definición de API."
localEndpointConflictExceptionMessage = "Tanto '{0}' como '{1}' están definidos como puntos finales locales de OpenAPI, pero solo se permite un punto final local por definición de API."
suspendingMessage = 'Suspendiendo el servidor...'
resumingMessage = 'Reanudando el servidor...'
serverControlCommandsTitle = 'Comandos de control del servidor:'
gracefullyTerminateMessage = 'Terminar el servidor de manera ordenada.'
restartServerMessage = 'Reiniciar el servidor y recargar configuraciones.'
resumeServerMessage = 'Reanudar el servidor.'
suspendServerMessage = 'Suspender el servidor.'
generateDiagnosticDumpMessage = 'Generar un volcado de diagnóstico para fines de depuración.'
initializingMessage = 'Inicializando'
restartingMessage = 'Reiniciando'
suspendedMessage = 'Suspendido'
runningMessage = 'En ejecución'
}
14 changes: 13 additions & 1 deletion src/Locales/fr/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,17 @@
getRequestBodyNotAllowedExceptionMessage = "Les opérations '{0}' ne peuvent pas avoir de corps de requête. Utilisez -AllowNonStandardBody pour contourner cette restriction."
fnDoesNotAcceptArrayAsPipelineInputExceptionMessage = "La fonction '{0}' n'accepte pas un tableau en tant qu'entrée de pipeline."
unsupportedStreamCompressionEncodingExceptionMessage = "La compression de flux {0} n'est pas prise en charge."
LocalEndpointConflictExceptionMessage = "Les deux '{0}' et '{1}' sont définis comme des points de terminaison locaux pour OpenAPI, mais un seul point de terminaison local est autorisé par définition d'API."
localEndpointConflictExceptionMessage = "Les deux '{0}' et '{1}' sont définis comme des points de terminaison locaux pour OpenAPI, mais un seul point de terminaison local est autorisé par définition d'API."
suspendingMessage = 'Suspension du serveur...'
resumingMessage = 'Reprise du serveur...'
serverControlCommandsTitle = 'Commandes de contrôle du serveur :'
gracefullyTerminateMessage = 'Arrêter le serveur gracieusement.'
restartServerMessage = 'Redémarrer le serveur et recharger les configurations.'
resumeServerMessage = 'Reprendre le serveur.'
suspendServerMessage = 'Suspendre le serveur.'
generateDiagnosticDumpMessage = 'Générer un dump diagnostique à des fins de débogage.'
initializingMessage = 'Initialisation'
restartingMessage = 'Redémarrage'
suspendedMessage = 'Suspendu'
runningMessage = "En cours d'exécution"
}
14 changes: 13 additions & 1 deletion src/Locales/it/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,17 @@
getRequestBodyNotAllowedExceptionMessage = "Le operazioni '{0}' non possono avere un corpo della richiesta. Utilizzare -AllowNonStandardBody per aggirare questa restrizione."
fnDoesNotAcceptArrayAsPipelineInputExceptionMessage = "La funzione '{0}' non accetta una matrice come input della pipeline."
unsupportedStreamCompressionEncodingExceptionMessage = 'La compressione dello stream non è supportata per la codifica {0}'
LocalEndpointConflictExceptionMessage = "Sia '{0}' che '{1}' sono definiti come endpoint locali OpenAPI, ma è consentito solo un endpoint locale per definizione API."
localEndpointConflictExceptionMessage = "Sia '{0}' che '{1}' sono definiti come endpoint locali OpenAPI, ma è consentito solo un endpoint locale per definizione API."
suspendingMessage = 'Sospensione del server...'
resumingMessage = 'Ripresa del server...'
serverControlCommandsTitle = 'Comandi di controllo del server:'
gracefullyTerminateMessage = 'Termina il server con grazia.'
restartServerMessage = 'Riavviare il server e ricaricare le configurazioni.'
resumeServerMessage = 'Riprendi il server.'
suspendServerMessage = 'Sospendi il server.'
generateDiagnosticDumpMessage = 'Genera un dump diagnostico a scopo di debug.'
initializingMessage = 'Inizializzazione'
restartingMessage = 'Riavvio'
suspendedMessage = 'Sospeso'
runningMessage = 'In esecuzione'
}
Loading

0 comments on commit 7db258a

Please sign in to comment.