-
Notifications
You must be signed in to change notification settings - Fork 535
Expose JSON schemas for audit and logs output #59720
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
Open
Copilot
wants to merge
14
commits into
main
Choose a base branch
from
copilot/add-json-schema-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e8a9427
Add audit and logs JSON schema command
Copilot d44e604
Add schemas Make target
Copilot b59e389
Add draft ADR for JSON schema CLI output
github-actions[bot] 9684f73
Cover all JSON schema output modes
Copilot 0a2b15f
Merge remote-tracking branch 'origin/main' into copilot/add-json-sche…
Copilot 701431d
Match schemas to JSON wire formats
Copilot f4f94b8
Verify schema review fixes
Copilot 5861ab9
Restore workflow lock files
Copilot 2885241
Plan branch refresh verification
Copilot 65493af
Restore workflow lock files
Copilot 4caba5c
Plan final review verification
Copilot c809753
Restore workflow lock files
Copilot 77014fb
Cover all custom JSON schema wire shapes
Copilot bb01d36
Merge branch 'main' into copilot/add-json-schema-command
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # ADR-59720: Expose JSON schemas for CLI output | ||
|
|
||
| **Date**: 2026-09-09 | ||
| **Status**: Draft | ||
| **Deciders**: gh-aw maintainers | ||
|
|
||
| --- | ||
|
|
||
| ### Context | ||
|
|
||
| `gh aw audit --json` and `gh aw logs --json` already emit structured data, but the repository did not provide a supported way for users or downstream tooling to discover those payload shapes. This PR adds a `json-schema` CLI command, checked-in schema artifacts, Makefile regeneration, tests, and documentation centered on the audit and logs outputs. The change also keeps the Go output types as the source of truth by generating schemas directly from `AuditData` and `LogsData`. The repository needs an explicit decision on whether structured CLI outputs should expose versioned machine-readable schemas as part of the developer-facing interface. | ||
|
|
||
| ### Decision | ||
|
|
||
| We will expose JSON schemas for the structured `audit` and `logs` CLI outputs through a new `gh aw json-schema <schema>` command and commit regenerated schema artifacts under `schemas/`. We will generate those schemas directly from the existing Go output types and share the same serialization path between CLI output and checked-in artifacts so the published schemas stay deterministic and consistent. We will also regenerate the artifacts during `make recompile` so schema freshness becomes part of the normal repository regeneration flow. | ||
|
|
||
| ### Alternatives Considered | ||
|
|
||
| #### Alternative 1: Keep structured JSON output undocumented and schema-less | ||
|
|
||
| The project could continue emitting `audit --json` and `logs --json` without publishing schemas. This was considered because it avoids adding a new command, generated files, and regeneration logic. It was not chosen because downstream automation would still need to reverse-engineer payloads, and the PR explicitly adds tests and docs to make the output contract inspectable. | ||
|
|
||
| #### Alternative 2: Hand-maintain static schema files separately from the Go types | ||
|
|
||
| Another option would be to write `audit.schema.json` and `logs.schema.json` manually and update them when the output types change. This was considered because it could avoid adding schema-generation entry points to the CLI. It was not chosen because the PR evidence shows a stronger preference for using `GenerateOutputSchema[...]()` and shared marshaling so JSON tags and type definitions remain the single source of truth. | ||
|
|
||
| #### Alternative 3: Expose schemas only in repository files, without a CLI command | ||
|
|
||
| The project could check in generated schema artifacts but omit a user-facing command. This was considered because consumers could read the committed files directly from the repository. It was not chosen because the PR intentionally adds `gh aw json-schema audit` and `gh aw json-schema logs`, making schema discovery available from the installed CLI and not only from the source tree. | ||
|
|
||
| ### Consequences | ||
|
|
||
| #### Positive | ||
| - Downstream tools gain a supported machine-readable contract for `gh aw audit --json` and `gh aw logs --json`. | ||
| - Generating schemas from `AuditData` and `LogsData` reduces drift between implementation and published schema. | ||
| - Deterministic CLI output and checked-in artifacts make schema changes easier to test and review. | ||
|
|
||
| #### Negative | ||
| - The repository now carries large generated schema artifacts that must be regenerated when output types change. | ||
| - `make recompile` takes on additional responsibility, so schema generation failures can block broader regeneration workflows. | ||
| - Exposing schemas makes output-shape changes more visible and may increase compatibility expectations for future changes. | ||
|
|
||
| #### Neutral | ||
| - A new `json-schema` command is added to the CLI utilities group. | ||
| - Tests now verify command registration, argument handling, schema validity, determinism, and artifact freshness. | ||
| - `.prettierignore` is extended to exclude the generated schema files from formatting. | ||
|
|
||
| --- | ||
|
|
||
| *ADR created by [adr-writer agent]. Review and finalize before changing status from Draft to Accepted.* |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
|
|
||
| "github.com/github/gh-aw/pkg/constants" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // NewJSONSchemaCommand creates the json-schema command. | ||
| func NewJSONSchemaCommand() *cobra.Command { | ||
| return newJSONSchemaCommand(os.Stdout) | ||
| } | ||
|
|
||
| func newJSONSchemaCommand(output io.Writer) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "json-schema <schema>", | ||
| Short: "Generate JSON Schemas for structured command output", | ||
| Long: "Generate the JSON Schema for audit or logs JSON output.", | ||
| Example: ` ` + string(constants.CLIExtensionPrefix) + ` json-schema audit | ||
| ` + string(constants.CLIExtensionPrefix) + ` json-schema logs`, | ||
| Args: cobra.ExactArgs(1), | ||
| ValidArgs: []string{"audit", "logs"}, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| data, err := GenerateNamedOutputSchema(args[0]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if _, err := output.Write(data); err != nil { | ||
| return fmt.Errorf("failed to write %s schema: %w", args[0], err) | ||
| } | ||
| return nil | ||
| }, | ||
| SilenceUsage: true, | ||
| } | ||
| return cmd | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot create target to make schemas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented in d44e604.
make schemasnow generates the audit and logs schema artifacts, andmake recompiledepends on it.