Add session materials: PimpYourPrameters and GitToGallery - MacInally#31
Open
LindnerBrewery wants to merge 1 commit into
Open
Add session materials: PimpYourPrameters and GitToGallery - MacInally#31LindnerBrewery wants to merge 1 commit into
LindnerBrewery wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds new session/demo materials for “Pimp Your Parameter Validation Classes” and “From Git to Gallery with Open Source” to the repository’s session-content structure.
Changes:
- Added a PowerShell demo script showcasing custom
ValidateArgumentsAttributevalidators (ticket IDs, semver, safe paths, ports, and a combined completer/transformer/validator example). - Added a PowerShell demo script showcasing JSON Schema-based validation patterns (inline schema, schema file, schema URL, and combined “auto source” validator), plus schema file setup.
- Added a D&D character JSON schema file and a short README pointing to the full external “Git to Gallery” repo.
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| PimpYourParameterValidationClasses-MacInally/demo/validationClassesDemo_JsonSchema.ps1 | Adds JSON Schema validation demo classes and example functions, including schema file setup. |
| PimpYourParameterValidationClasses-MacInally/demo/validationClassesDemo.ps1 | Adds custom validation attribute demos (including safe path and port validation). |
| PimpYourParameterValidationClasses-MacInally/demo/character.schema.json | Adds a sample JSON schema used by the demos. |
| FromGitToGalleryWithOpenSource-MacInally/readme.md | Adds a brief readme with a link to the full demo environment repository. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| [void] Validate([object]$arguments, [System.Management.Automation.EngineIntrinsics]$engineIntrinsics) { | ||
| # If something is wrong: throw an exception | ||
| # If everything is fine: do nothing (return void) | ||
| if ([datetime]$arguments -is [datetime] -and ([datetime]$arguments).DayOfWeek -eq 'Friday') { |
Comment on lines
+303
to
+304
|
|
||
| if (-not $resolvedPath.StartsWith($resolvedRoot, [System.StringComparison]::OrdinalIgnoreCase)) { |
Comment on lines
+359
to
+365
| if ($port -lt 0 -or $port -gt 65535) { | ||
| throw "Port $port is out of range. Valid ports: 0-65535." | ||
| } | ||
|
|
||
| if ($port -le 1023 -and -not $this.AllowWellKnown) { | ||
| throw "Port $port is a well-known port (0-1023). Use ports 1024-65535 or explicitly allow well-known ports." | ||
| } |
Comment on lines
+387
to
+398
| function Test-Connection { | ||
| [CmdletBinding()] | ||
| param ( | ||
| [Parameter(Mandatory)] | ||
| [string]$Hostname, | ||
|
|
||
| [Parameter()] | ||
| [ValidatePort($true)] # Allow well-known ports (80, 443, etc.) | ||
| [int]$Port = 443 | ||
| ) | ||
| "Testing connection to ${Hostname}:${Port}..." | ||
| } |
Comment on lines
+622
to
+657
| #region ---- Setup: Create Schema Files for File-Based Examples ---- | ||
|
|
||
| # Run this region first to set up the schema files needed for Examples 3 and 5 | ||
|
|
||
| $schemasDir = "$PSScriptRoot\schemas" | ||
| if (-not (Test-Path $schemasDir)) { | ||
| New-Item -Path $schemasDir -ItemType Directory -Force | Out-Null | ||
| } | ||
|
|
||
| # D&D Character schema (for Example 3) | ||
| @' | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "title": "D&D Character", | ||
| "type": "object", | ||
| "properties": { | ||
| "name": { "type": "string", "minLength": 2 }, | ||
| "class": { "type": "string", "enum": ["Barbarian", "Bard", "Cleric", "Druid", "Fighter", "Monk", "Paladin", "Ranger", "Rogue", "Sorcerer", "Warlock", "Wizard"] }, | ||
| "level": { "type": "integer", "minimum": 1, "maximum": 20 }, | ||
| "race": { "type": "string" }, | ||
| "stats": { | ||
| "type": "object", | ||
| "properties": { | ||
| "strength": { "type": "integer", "minimum": 1, "maximum": 30 }, | ||
| "dexterity": { "type": "integer", "minimum": 1, "maximum": 30 }, | ||
| "constitution": { "type": "integer", "minimum": 1, "maximum": 30 }, | ||
| "intelligence": { "type": "integer", "minimum": 1, "maximum": 30 }, | ||
| "wisdom": { "type": "integer", "minimum": 1, "maximum": 30 }, | ||
| "charisma": { "type": "integer", "minimum": 1, "maximum": 30 } | ||
| }, | ||
| "required": ["strength", "dexterity", "constitution", "intelligence", "wisdom", "charisma"] | ||
| } | ||
| }, | ||
| "required": ["name", "class", "level", "race", "stats"] | ||
| } | ||
| '@ | Set-Content -Path "$schemasDir\character.schema.json" -Force |
| # It's a file path - read it | ||
| $schema = Get-Content -Path $this.SchemaSource -Raw -ErrorAction Stop | ||
| } | ||
| else { |
Comment on lines
+341
to
+353
| try { | ||
| $schema = (Invoke-WebRequest -Uri $this.SchemaUri -TimeoutSec $this.TimeoutSec -ErrorAction Stop).Content | ||
| } | ||
| catch { | ||
| throw "Failed to fetch schema from '$($this.SchemaUri)': $($_.Exception.Message)" | ||
| } | ||
|
|
||
| try { | ||
| $json | Test-Json -Schema $schema -ErrorAction Stop | Out-Null | ||
| } | ||
| catch { | ||
| throw "JSON does not match remote schema! $($_.Exception.Message)" | ||
| } |
Contributor
|
@LindnerBrewery please update per copilots request and do a whole new session at Summit. Jk lol |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added session materials