Skip to content

Declare the output contract for Json's public commands #43

Description

Context and request

None of the three public commands declares [OutputType()], and none documents .INPUTS, .OUTPUTS, or .NOTES. The MSX PowerShell function standard treats [OutputType()] and its matching .OUTPUTS block as the contract between a function and its callers, and PlatyPS renders both into the generated reference pages published at psmodule.io/Json. Today those pages carry no output contract at all.

Each command already has .SYNOPSIS, .DESCRIPTION, at least one .EXAMPLE, and a correct .LINK, so this completes existing help rather than writing it from scratch.

Acceptance criteria.

  • Format-Json, Import-Json, and Export-Json each declare [OutputType()], scoped per parameter set where the sets return different types.
  • Each documents .INPUTS and .OUTPUTS, with a description for every entry and fully-qualified .NET type names.
  • .OUTPUTS matches [OutputType()] exactly.
  • Where no parameter accepts pipeline input, .INPUTS reads None with You can't pipe objects to <CommandName>. as its description.
  • Get-Help <Command> -Full shows inputs and outputs for all three commands.
  • The generated reference pages render the type as a heading with the description as body text below it.

Technical decisions

.INPUTS and .OUTPUTS use the PlatyPS blank-line format — type name on the first line, blank line, then the description as a plain paragraph:

.OUTPUTS
System.String

The formatted JSON text.

The single-line System.String. Description. form shown in about_Comment_Based_Help is not used: it triggers MD026 and puts a full sentence inside a ### heading when PlatyPS v2 processes it.

Type names are fully qualified — System.String, System.Management.Automation.PSCustomObject, System.IO.FileInfo — not accelerators.

Export-Json needs care on [OutputType()]. It emits System.IO.FileInfo only when -PassThru is supplied and nothing otherwise. Since that is a switch rather than a parameter set, a single unscoped [OutputType([System.IO.FileInfo])] is correct, with .OUTPUTS stating that output is produced only with -PassThru.

Import-Json currently emits objects carrying an injected _SourceFile property. The .OUTPUTS description documents the corrected contract — the deserialized document — not the current polluted one, so this should land after or alongside that correction.

This is a documentation and attribute change with no runtime behaviour change, which is why it is separated from the structural work on the same functions. src/ matches ImportantFilePatterns, so it still triggers a full build and warrants a Patch label.

Implementation plan

  • Add [OutputType([System.String])] to Format-Json with .INPUTS covering both pipeline-bound parameter sets and .OUTPUTS describing the formatted JSON text
  • Add [OutputType([System.Management.Automation.PSCustomObject])] to Import-Json with .INPUTS for the pipeline-bound Path and .OUTPUTS describing the deserialized document
  • Add [OutputType([System.IO.FileInfo])] to Export-Json with .INPUTS covering both pipeline-bound sets and .OUTPUTS noting output only occurs with -PassThru
  • Add .NOTES where there is genuinely something a caller needs to know, and omit it where there is not
  • Verify Get-Help <Command> -Full renders all sections correctly for each command
  • Confirm the generated documentation pages render the heading and body separation as intended
  • Confirm .OUTPUTS and [OutputType()] agree for every command

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions