Skip to content

feat(examples): add examples.yaml JSON schema and examples-validate tool#4908

Draft
timotheeguerin wants to merge 1 commit into
mainfrom
examples-file-format
Draft

feat(examples): add examples.yaml JSON schema and examples-validate tool#4908
timotheeguerin wants to merge 1 commit into
mainfrom
examples-file-format

Conversation

@timotheeguerin

Copy link
Copy Markdown
Member

Part of the Unified Examples Format epic (#4831). Implements #4832 — the examples.yaml JSON Schema + examples-validate tool.

What

New package @azure-tools/typespec-azure-examples, the foundational piece of the epic.

  • Schema (TypeSpec → JSON Schema → ajv)schema/examples-yaml.tsp is the source of truth (RFC §4 model), compiled via @typespec/json-schema to ExamplesYaml.json and wrapped as schema.js, mirroring the existing service.yaml schema pattern in typespec-autorest. ajv (draft 2020-12) validates parsed files against it.
  • examples-validate CLI + programmatic API — discovers examples.yaml / examples/*.yaml in a service directory, reads the adjacent service.yaml for version metadata, reports located diagnostics, and exits non-zero on error (--warn-as-error to also fail on warnings).

Rules enforced (RFC §3)

  • Only $schema/$namespace may be $-prefixed; every other bare top-level key is an operation that must be a list of examples.
  • Response keys are integer status codes; range keys (2XX) and default are rejected.
  • since must be a quoted string and a version listed in service.yaml.
  • Per lineage (entries grouped by title; untitled → default lineage): at most one entry without since, and since values are unique.
  • An operation's full example set lives in a single file; each interface appears in exactly one file.
  • {api-version} is the only supported placeholder, and api-version must not appear as a request parameter.

Notes / scope

Validation

Build (schema regen + tsc), 24 vitest tests, oxlint, prettier, cspell, and tsc -b all pass; CLI verified end-to-end (exit 0 on valid, exit 1 with located diagnostics on invalid).

Add @azure-tools/typespec-azure-examples, the foundational piece of the
Unified Examples Format epic (#4831, issue #4832):

- examples.yaml JSON Schema authored in TypeSpec (schema/examples-yaml.tsp)
  and compiled via @typespec/json-schema.
- examples-validate CLI + programmatic API that runs structural (ajv)
  validation plus the RFC section 3 semantic rules: metadata keys,
  integer-only status codes, quoted since in service.yaml, per-lineage
  base/uniqueness, one-interface-per-file, and {api-version}-only placeholder.
@azure-sdk-automation

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @azure-tools/typespec-azure-examples
Show changes

@azure-tools/typespec-azure-examples - feature ✏️

Add @azure-tools/typespec-azure-examples with the examples.yaml JSON Schema and the examples-validate tool for the unified examples format.

@pkg-pr-new

pkg-pr-new Bot commented Jul 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/Azure/typespec-azure/@azure-tools/typespec-azure-examples@4908

commit: 7e4f1ad

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant