Skip to content

Latest commit

 

History

History
144 lines (105 loc) · 6.99 KB

README.md

File metadata and controls

144 lines (105 loc) · 6.99 KB

Photon API Design Standards

Public HTTP API design standards and deterministic Redocly OpenAPI lint rules for Photon APIs.

Each standard in Photon API Design Standards (ADS) defines a service-agnostic contract guarantee for external developers, SDK consumers, and automated clients, co-located with its executable lint rules and test suite.

Standards Index

Standard Title Status Rules
ADS-0001 Resource Identifiers and Path Parameter Naming Approved photon-ads/ads-0001-resource-primary-id, photon-ads/ads-0001-path-param-naming, photon-ads/ads-0001-path-param-consistency
ADS-0002 Top-Level JSON Response Structure Approved photon-ads/ads-0002-top-level-json-object, photon-ads/ads-0002-no-single-resource-wrapper, photon-ads/ads-0002-flat-creation-secret

Status Lifecycle

  • Draft: Problem space identified; conventions are not yet settled.
  • Reviewing: Core direction is agreed, with open questions under review.
  • Approved: Binding default for new and redesigned Photon public HTTP APIs.
  • Deprecated: Superseded by a newer standard.

Proposals are developed through collaborator pull requests in this repository, and only Approved standards are published to the developer docs.

Feedback & Reporting Issues

We do not accept external pull requests to this repository. Instead, GitHub Issues are open to everyone:

  • Report a non-conformant Photon API: If you find any Photon API endpoint that does not follow these standards, please open an issue with the HTTP method, path, the standard or rule that is violated, and a sanitized or synthetic example request or response payload (with any credentials, tokens, or sensitive customer data removed) when available.
  • Suggest improvements or new standards: Open an issue describing the problem, proposed convention, and motivating examples.

Using the Redocly Plugin

@photon-hq/api-design-standards is published to GitHub Packages alongside GitHub Releases. Configure your project's .npmrc to resolve the @photon-hq scope from GitHub Packages (authentication requires a GitHub token with read:packages scope):

@photon-hq:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}

Install @photon-hq/api-design-standards alongside @redocly/cli (v2):

pnpm add -D @photon-hq/api-design-standards @redocly/cli

Register the photon-ads plugin and extend photon-ads/recommended in your redocly.yaml:

plugins:
  - "@photon-hq/api-design-standards/redocly"

extends:
  - recommended
  - photon-ads/recommended

You can also override individual rule severities or add declarative rule-level ignore entries under rules::

rules:
  photon-ads/ads-0001-resource-primary-id:
    severity: error
    ignore:
      - schema: LegacyProject
        reason: Existing v1 schema pending deprecation
      - path: /v1/legacy/items/{itemId}
        method: get
        reason: Existing response shape preserved for backward compatibility
  photon-ads/ads-0001-path-param-naming: error
  photon-ads/ads-0001-path-param-consistency: error
  photon-ads/ads-0002-top-level-json-object: error
  photon-ads/ads-0002-no-single-resource-wrapper:
    severity: error
    ignore:
      - path: /v1/legacy/items/{itemId}
        method: get
        reason: Legacy wrapper endpoint
  photon-ads/ads-0002-flat-creation-secret: error

Each ignore entry accepts path, method, schema, and an optional reason string:

  • path: Exact OpenAPI path template (trailing slash trimmed except /). Omitting method matches all methods (and path-level parameters) on that path.
  • method: Case-insensitive HTTP method (get, post, patch, put, delete, etc.) narrowing a path or schema match where operation context applies. Component schema diagnostics (under components.schemas) have no HTTP method context, so suppressing them requires a schema-only ignore entry.
  • schema: Component schema name under components.schemas (used by photon-ads/ads-0001-resource-primary-id).
  • reason: Optional human-readable explanation for reviewers.

Run Redocly against your OpenAPI 3 specification:

npx redocly lint openapi.yaml --config redocly.yaml

Repository Layout

The external developer documentation overview and each standard live under ads/:

ads/
  overview.md      # External developer documentation overview
  0001-resource-identifiers/
    index.md       # Authoritative Markdown specification and rule table
    rules.ts       # Deterministic Redocly OpenAPI 3 rules
    rules.test.ts  # Unit and end-to-end Redocly CLI tests
  0002-top-level-json-response/
    index.md       # Authoritative Markdown specification and rule table
    rules.ts       # Deterministic Redocly OpenAPI 3 rules
    rules.test.ts  # Unit and end-to-end Redocly CLI tests

Running Checks Locally

Requires Node.js 22.12+ (CI runs Node 24) and pnpm:

pnpm install
pnpm check

Individual commands:

  • pnpm typecheck — strict TypeScript check across source, rules, scripts, and tests.
  • pnpm lint — Biome formatting and linting check.
  • pnpm build — compiles the TypeScript plugin package into dist/.
  • pnpm test — runs unit tests and end-to-end redocly lint verification.
  • pnpm redocly:check — lints the reference OpenAPI 3.1 fixture with redocly.yaml.
  • pnpm docs:export — builds and validates artifacts/docs-reference.json for documentation publishing.
  • pnpm check:public — verifies tracked files contain only public-safe content.

Proposing a New Standard

We do not accept external pull requests. To propose a new API Design Standard or suggest a change to an existing one, open a GitHub issue describing the problem, proposed contract rules, and motivating examples. Proposals are developed through collaborator pull requests in this repository, and only Approved standards are published to the developer docs.

Collaborator Authoring Checklist

When implementing an approved proposal:

  1. Create the next sequential folder under ads/<num>-<slug>/.
  2. Add index.md with YAML frontmatter (title, sidebarTitle, description, ads, status, updated), RFC 2119 normative guidance, concrete Good/Bad examples, and a Lint Rules table.
  3. Implement deterministic Redocly rules in rules.ts, register them in src/catalog.ts and src/plugin.ts, and cover valid, invalid, and edge cases in rules.test.ts.
  4. Ensure pnpm check passes cleanly, including docs:export parity checks and Mintlify MDX safety validation.

License

Apache-2.0. See LICENSE.