ADS-0007: Resource Representation Consistency
Single canonical resource schemas, per-service Operation resources, cross-method response consistency, strict collection slices, mutation input symmetry, sub-resources, and the x-photon-resource OpenAPI extension across Photon public HTTP APIs.
- Status: Approved
- Updated: 2026-11-28
When a resource uses one canonical schema across reads, lists, and mutations, callers, generated SDKs, CLIs, dashboards, and automated agents can cache, diff, and update state without endpoint-specific field mappers or per-method type conversions. This standard is part of Photon API Design Standards and uses the keywords MUST, MUST NOT, SHOULD, and MAY as described in RFC 2119.
Scope
This standard governs schema consistency across every representation of a resource within Photon public HTTP APIs:
- Single canonical resource schemas anchored to single-resource
GET 200responses. - Per-service canonical
Operationresource modeling for long-running operations. - Cross-method response consistency across
GET,POST,PATCH, andPUT. - Strict subset guarantees for collection
GETitem slices. - Field-name, type, and writability symmetry for
POST,PATCH, andPUTrequest bodies. - Declarative schema roles through the
x-photon-resourceOpenAPI extension. - Sub-resources: owned value objects, embedded resources and nested slices, and URL-nested collection and singleton sub-resources.
Related concerns are governed by separate standards:
- Resource identifier fields (
id,<resource>Id) and URL path parameter naming ({<resource>Id}) are defined inADS-0001. - Flat top-level JSON response objects and flat one-time creation secrets are defined in
ADS-0002. - Long-running operation lifecycle, polling, and
Operationenvelope fields are defined inADS-0004. - Standard HTTP methods, read symmetry, canonical status codes, URL naming, and RFC 7396 JSON Merge Patch wire rules are defined in
ADS-0005. - Forward cursor pagination (
pageSize,pageToken,nextPageToken) is defined inADS-0006.
Normative Rules
1. Canonical Resource Model
Every addressable resource and singleton MUST have a single authoritative canonical resource schema (C), defined by its single-resource GET 200 representation.
- Whether a resource is retrieved at a direct child path (for example
GET /v1/projects/{projectId}/api-keys/{apiKeyId}) or at a hoisted canonical path (for exampleGET /v1/projects/{projectId}paired withGET /v1/organizations/{organizationId}/projects), that single-resourceGET 200schema is the source of truth for the resource's field names, types, nullability, and nested structures. - Single-resource fields MUST appear flat at the root JSON object per
ADS-0002. - Server-managed attributes (such as
id,createdAt,updatedAt, and computed status or audit fields) SHOULD be annotated withreadOnly: trueonCso documentation, SDK generators, and automated validators can distinguish output-only fields from writable attributes. - Every other representation of that resource — collection list items, mutation responses, and mutation request bodies — MUST derive from
Crather than inventing parallel field names or incompatible types.
2. Per-Service Operation Canonical Resource
Long-running operations (defined in ADS-0004) MUST be modeled as a canonical resource scoped to the owning service or domain (for example projects.operation or billing.operation), not as a single shared cross-service union across all domains.
- Each service's
Operationcanonical schema MUST satisfy the universalADS-0004contract (id,type,status,createdAt,updatedAt,completedAt,response, anderror, plus optionalcancellable,nextAction, andmetadatawith allADS-0004status-specific invariants), while specializingtype,response,nextAction, andmetadatastrictly to the operation types that service owns. - Scoping the canonical
Operationresource per service keeps generated SDK unions small, prevents unrelated services from coupling their release cycles, and gives each service'sGET .../operations/{operationId}endpoint a clean canonical schemaC. - Tracked long-running asynchronous mutations returning
202 AcceptedperADS-0004return the owning service's canonicalOperationresource rather than the target domain resource. Lifecycle-bearing resources returning202 AcceptedwithLocationpointing to the resource itself and fire-and-forget202 Acceptedendpoints remain governed byADS-0004andADS-0005.
3. Cross-Method Response Consistency
Every synchronous 2xx JSON response returning a single resource — GET 200, PATCH 200, PUT 200/201, and synchronous collection POST 200/201 — MUST be structurally consistent with the resource's canonical GET 200 representation C:
- Every field returned in the response MUST exist on
Cwith the same name and a compatible (equal or narrower) JSON type, checked recursively through nested objects and arrays. - Responses MUST NOT omit required properties declared on
C, rename canonical fields, or attach ad-hoc fields absent fromC. - The following narrow exceptions apply:
- One-time creation secrets (
ADS-0002§3): A synchronous creation response (POST 200/201orPUT 201) MAY return a one-time sensitive credential (such assecret,signingSecret,clientSecret,token, oraccessToken) as a flat sibling top-level field alongside all canonical fields ofC. SubsequentGET,PATCH, andDELETEresponses omit the one-time secret while keeping every canonical field identical. Creation responses MUST NOT wrap the resource and secret in a split two-key envelope ({ "apiKey": { ... }, "secret": "..." }), perADS-0002§3. - Asynchronous operations (
ADS-0004): Tracked long-running202 Acceptedresponses (and synchronous idempotent replays on endpoints declaring202that return anADS-0004Operationresource) return the owning service'sOperationschema rather thanC. - Bodyless responses:
204 No Contentresponses (such asDELETE 204) return no body.
- One-time creation secrets (
- Custom action endpoints (
POST .../{resourceId}/<action>) and query/utility endpoints (such as/search,/query,/preview,/validate,/batch,/count, or/status) are governed by their own action or query contracts and are not required to returnCunless the action updates and returns the resource itself.
4. Collection Slices
Collection GET 200 endpoints MAY return either the full canonical schema C for each item in the collection array or a slice (strict projection) of C that omits expensive, bulky, or nested fields.
- Every property declared on a collection list item MUST exist on
Cwith the exact same name and a compatible (equal or narrower) type, checked recursively through nested objects and arrays. - Collection items MUST NOT introduce list-only fields absent from
C, rename canonical fields, or widen a field's type relative toC. - If a computed summary or metadata attribute is useful on collection responses, expose it on
Cas well so single-resourceGETremains a strict superset of collection list items. - For hoisted canonical resources (where
GET /v1/organizations/{organizationId}/projectslists items whose canonical single-resource read lives atGET /v1/projects/{projectId}), the list items MUST remain a strict slice of the hoisted canonicalGET 200schema.
5. Mutation Input Symmetry
Request bodies for PATCH, PUT, and collection POST MUST stay symmetric with canonical C:
- Type and name symmetry: Every request body property whose name matches a property on
CMUST use a compatible (equal or narrower) type, checked recursively through nested objects and arrays. Fields MUST NOT silently change type between write and read (for example accepting an integer onPATCHwhile returning a string onGET). - No server-managed or
readOnlyinputs:PATCHandPUTrequest bodies MUST NOT acceptid,createdAt,updatedAt, or any canonical property markedreadOnly: true.- Collection
POSTrequest bodies MUST NOT acceptcreatedAt,updatedAt, or any canonical property markedreadOnly: true. Client-suppliedidon creation is permitted only whenidis writable (not markedreadOnly: true) onC. - Request bodies MUST NOT accept embedded canonical resources or slices as writable inputs (see §7).
- Merge Patch compliance on
PATCH: EveryPATCHrequest body MUST additionally satisfy RFC 7396 JSON Merge Patch rules inADS-0005§6 (no required top-level fields outside an explicit union discriminator, andadditionalProperties: falseorunevaluatedProperties: false). - Non-resource creation inputs: Collection
POSTrequest bodies MAY accept creation-only input fields that are consumed during resource creation and not stored directly onC(for exampletemplateId,initialPlanId, orsendInviteEmail). When the schema carriesx-photon-resource, declare those inputs explicitly innonResourceInputs(see §6).
6. The x-photon-resource OpenAPI Extension
Schemas MAY declare the x-photon-resource OpenAPI vendor extension to make canonical ownership and derived schema roles machine-readable for SDK generation, documentation, and strict static checks.
Canonical form
Attach the canonical form to the authoritative component schema C:
x-photon-resource:
type: "<domain>.<entity>"typeMUST match^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$— lowercasekebab-casedomain and entity separated by a single dot (for exampleprojects.project,projects.api-key,billing.operation).- Every canonical
typeMUST be globally unique within an OpenAPI document. - The canonical object MUST NOT include derived keys (
role,canonical, ornonResourceInputs).
Derived form
Attach the derived form to any slice or mutation schema derived from C:
x-photon-resource:
role: "create" # one of: "slice", "create", "patch", "replace"
canonical: "#/components/schemas/<CanonicalSchemaName>"
nonResourceInputs: # optional; allowed ONLY when role is "create"
- "templateId"roleMUST be one of"slice","create","patch", or"replace".canonicalMUST be a local JSON Pointer (#/components/schemas/<Name>) referring to an existing schema undercomponents.schemasthat declares canonicalx-photon-resource: { type }. Dangling pointers, self-references, and derived-to-derived chains are forbidden.nonResourceInputsis allowed ONLY whenroleis"create". When present, it MUST be a non-empty array of unique property names, each of which MUST exist on the derived schema and MUST NOT exist on the canonical schemaC.
Derived role contract
Each derived role enforces a strict contract against its canonical schema C:
| Role | Allowed properties | readOnly / server-managed fields | Additional constraints |
|---|---|---|---|
slice | Strict subset of C with compatible types (recursively) | Allowed (id, createdAt, etc.) | Used for list summaries and reduced projections |
create | Subset of C with compatible types, plus properties listed in nonResourceInputs | Forbidden (readOnly: true, createdAt, updatedAt, embedded resources per §7) | Unlisted extra properties are rejected |
patch | Strict subset of C with compatible types (recursively) | Forbidden (readOnly: true, id, createdAt, updatedAt, embedded resources per §7) | No top-level required (except an explicit union discriminator); additionalProperties: false (or unevaluatedProperties: false) required per ADS-0005 §6 |
replace | Strict subset of C with compatible types (recursively) | Forbidden (readOnly: true, id, createdAt, updatedAt, embedded resources per §7) | Full-replacement PUT input |
7. Sub-Resources: Owned Value Objects, Embedded Resources, and Nested Routes
A resource can relate to a smaller resource or object in one of three ways. Choose the pattern by whether the sub-object has an identity and a lifecycle of its own:
| Pattern | Identity and endpoint | x-photon-resource | Where it appears | Writable through the parent |
|---|---|---|---|---|
| Owned value object | None; exists only inside the parent | None | Inline property of C | Yes, in create, patch, and replace inputs |
| Embedded canonical resource or slice | Its own canonical resource and endpoints | { type } on the canonical schema, or { role: "slice", canonical } | Property of C, beside a flat <resource>Id | No; change <resource>Id or use the resource's own endpoints |
| URL-nested sub-resource | Its own canonical resource, mounted under the parent path | { type } on the canonical schema | A separate route, not a property of C | Through its own POST, PATCH, or PUT routes |
7.1 Owned value objects
An owned value object is a 1:1 sub-object owned exclusively by the parent, with no independent identity, endpoint, or x-photon-resource annotation (for example notifications or scheduledPlanChange).
- It MUST be declared inline in
C(directly or through a$refto an unannotated component schema). - When mutable, it MUST be writable in
create,patch, andreplaceinputs with the same shape as onC. - In
PATCHrequest bodies, its fields MUST be recursively optional, it MUST declareadditionalProperties: false(orunevaluatedProperties: false), and it merges recursively perADS-0005§6.
7.2 Embedded canonical resources and slices
A parent MAY embed another resource (for example Subscription.plan embedding Plan) or a projection of one (for example PaymentAction.operation embedding OperationSummary) for read convenience. The embedded property:
- MUST reuse the embedded resource's canonical schema (
x-photon-resource: { type }) or a strictsliceof it (x-photon-resource: { role: "slice", canonical }), never an ad-hoc third shape. - SHOULD sit beside a flat
<resource>Idfield (for exampleplanId) that carries the identifier perADS-0001. - MUST NOT embed unbounded child collections; expose a separate paginated collection endpoint per
ADS-0006instead. - MUST NOT use polymorphic expand unions that return either an identifier string or the object (
string | Plan,string | Plan | null,(string | Plan)[], orstring[] | Plan[]). Always return the embedded object in the same shape and pair it with the flat<resource>Idfield. - MUST remain read-only on parent mutations. Collection
POST,PATCH, andPUTrequest bodies, andcreate,patch, andreplaceschemas, MUST NOT accept an embedded canonical resource orsliceas a writable input, even when the embedded property onCdoes not carryreadOnly: true. This also applies to an embedded resource nested inside an owned value object. - MUST NOT embed a
create,patch, orreplaceinput schema inside a read representation.
A property embeds a resource when its schema, directly or through $ref, an allOf member, an anyOf or oneOf branch (including a nullable branch), or array items, resolves to a schema that declares canonical x-photon-resource: { type } or x-photon-resource: { role: "slice" }. A sub-object whose schema carries no x-photon-resource annotation is treated as an owned value object, so the embedded-resource rules in this section apply only to annotated targets.
Nested slicing: A parent slice (such as a collection list item) MAY omit an embedded resource or narrow it to a slice whose x-photon-resource.canonical points to the same canonical resource that C embeds. A nested slice MUST NOT substitute a slice of a different canonical resource, even when that slice is structurally a subset (for example narrowing Subscription.plan to an InvoiceSummary that declares only id). When C embeds a polymorphic union of canonical resources (for example Cat | Dog), a nested slice MAY narrow it to slices of any of those members.
7.3 URL-nested independent sub-resources
An independent canonical resource (x-photon-resource: { type }) MAY be mounted under a parent path instead of being embedded in the parent's representation:
- Collection sub-resources (for example
/v1/projects/{projectId}/api-keyswith a nested or hoisted single-resource/{apiKeyId}route) stay decoupled from the parent's JSON representation. The parent MUST NOT embed the full collection; clients list it through the paginated collection endpoint. - Singleton sub-resources (for example
/v1/projects/{projectId}/subscription,/v1/subscriptions/{subscriptionId}/usage, or/v1/projects/{projectId}/settings) model a 0..1 or 1:1 sub-resource that warrants its own endpoint because it is heavy or computed, needs independent authorization, or has an independent mutation lifecycle. A singleton'sGETdefines its canonical schemaC, andPATCHorPUTon the same path follow §3 and §5 like any other resource.
x-photon-resource stays URL-agnostic. It declares only type, role, canonical, and nonResourceInputs, with no parent or singleton metadata. Route hierarchy is inferred from the OpenAPI paths and the canonical schemas those routes return.
Examples
Canonical resource with derived slice, create, and patch schemas
Good — one canonical Project schema anchored to hoisted GET /v1/projects/{projectId}, paired with an explicit slice, a create input declaring nonResourceInputs, an RFC 7396 patch input, and a flat POST 201 one-time secret on CreatedApiKey (ADS-0002 §3):
components:
schemas:
Project:
x-photon-resource:
type: projects.project
type: object
required:
- id
- organizationId
- name
- createdAt
properties:
id:
type: string
readOnly: true
organizationId:
type: string
readOnly: true
name:
type: string
description:
type:
- string
- "null"
createdAt:
type: string
format: date-time
readOnly: true
ProjectSummary:
x-photon-resource:
role: slice
canonical: "#/components/schemas/Project"
type: object
required:
- id
- name
- createdAt
properties:
id:
type: string
readOnly: true
name:
type: string
createdAt:
type: string
format: date-time
readOnly: true
CreateProjectRequest:
x-photon-resource:
role: create
canonical: "#/components/schemas/Project"
nonResourceInputs:
- templateId
type: object
required:
- name
properties:
name:
type: string
description:
type:
- string
- "null"
templateId:
type: string
PatchProjectRequest:
x-photon-resource:
role: patch
canonical: "#/components/schemas/Project"
type: object
additionalProperties: false
minProperties: 1
properties:
name:
type: string
description:
type:
- string
- "null"
ApiKey:
x-photon-resource:
type: projects.api-key
type: object
required:
- id
- name
- createdAt
properties:
id:
type: string
readOnly: true
name:
type: string
createdAt:
type: string
format: date-time
readOnly: true
CreatedApiKey:
allOf:
- $ref: "#/components/schemas/ApiKey"
- type: object
required:
- secret
properties:
secret:
type: string
readOnly: true
paths:
/v1/projects/{projectId}:
get:
summary: Get a project
responses:
"200":
description: Canonical project representation
content:
application/json:
schema:
$ref: "#/components/schemas/Project"
/v1/projects/{projectId}/api-keys/{apiKeyId}:
get:
summary: Get an API key
responses:
"200":
description: Canonical API key representation (never includes secret)
content:
application/json:
schema:
$ref: "#/components/schemas/ApiKey"
/v1/projects/{projectId}/api-keys:
post:
summary: Create an API key
responses:
"201":
description: Created API key with flat one-time secret
content:
application/json:
schema:
$ref: "#/components/schemas/CreatedApiKey"Per-service Operation canonical resource
Good — each service declares its own canonical Operation schema (billing.operation) on its operations route while preserving the ADS-0004 status invariants and field names (id, type, status, createdAt, updatedAt, completedAt, response, error):
components:
schemas:
BillingOperationBase:
type: object
required:
- id
- type
- status
- createdAt
- updatedAt
- completedAt
- response
- error
properties:
id:
type: string
readOnly: true
type:
type: string
const: billing.checkout
readOnly: true
createdAt:
type: string
format: date-time
readOnly: true
updatedAt:
type: string
format: date-time
readOnly: true
BillingOperation:
x-photon-resource:
type: billing.operation
oneOf:
- allOf:
- $ref: "#/components/schemas/BillingOperationBase"
- type: object
properties:
status:
type: string
enum:
- pending
- running
completedAt:
type: "null"
response:
type: "null"
error:
type: "null"
- allOf:
- $ref: "#/components/schemas/BillingOperationBase"
- type: object
properties:
status:
type: string
const: succeeded
completedAt:
type: string
format: date-time
response:
type: object
required:
- invoiceId
properties:
invoiceId:
type: string
error:
type: "null"Sub-resources: owned value objects, embedded resources, and nested slices
Good — Subscription embeds the canonical Plan beside a flat planId and owns an inline notifications value object. The list slice narrows plan to PlanSummary, a slice of the same canonical Plan. The patch input changes the plan only through planId, and notifications stays recursively optional:
components:
schemas:
Plan:
x-photon-resource:
type: billing.plan
type: object
required: [id, name, amount]
properties:
id: { type: string, readOnly: true }
name: { type: string }
amount: { type: integer }
PlanSummary:
x-photon-resource:
role: slice
canonical: "#/components/schemas/Plan"
type: object
required: [id, name]
properties:
id: { type: string, readOnly: true }
name: { type: string }
Subscription:
x-photon-resource:
type: billing.subscription
type: object
required: [id, planId, plan, notifications]
properties:
id: { type: string, readOnly: true }
planId: { type: string }
plan:
$ref: "#/components/schemas/Plan"
notifications:
type: object
additionalProperties: false
properties:
email: { type: boolean }
sms: { type: boolean }
SubscriptionSummary:
x-photon-resource:
role: slice
canonical: "#/components/schemas/Subscription"
type: object
required: [id, plan]
properties:
id: { type: string, readOnly: true }
plan:
$ref: "#/components/schemas/PlanSummary"
UpdateSubscriptionRequest:
x-photon-resource:
role: patch
canonical: "#/components/schemas/Subscription"
type: object
additionalProperties: false
minProperties: 1
properties:
planId: { type: string }
notifications:
type: object
additionalProperties: false
properties:
email: { type: boolean }
sms: { type: boolean }Good — a singleton sub-resource with its own endpoint. GET and PATCH share one path and one canonical schema:
paths:
/v1/projects/{projectId}/subscription:
get:
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/Subscription"
patch:
requestBody:
content:
application/merge-patch+json:
schema:
$ref: "#/components/schemas/UpdateSubscriptionRequest"
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/Subscription"Bad — a patch input that accepts the embedded Plan as a writable object instead of planId:
UpdateSubscriptionRequest:
x-photon-resource:
role: patch
canonical: "#/components/schemas/Subscription"
type: object
additionalProperties: false
properties:
plan:
$ref: "#/components/schemas/Plan"Bad — a polymorphic expand union that returns either the plan identifier or the plan object:
Subscription:
x-photon-resource:
type: billing.subscription
type: object
properties:
plan:
oneOf:
- type: string
- $ref: "#/components/schemas/Plan"Bad — a nested slice that narrows Subscription.plan to a slice of a different canonical resource. It fails even though InvoiceSummary declares only id, because Subscription.plan embeds Plan:
InvoiceSummary:
x-photon-resource:
role: slice
canonical: "#/components/schemas/Invoice"
type: object
properties:
id: { type: string }
SubscriptionSummary:
x-photon-resource:
role: slice
canonical: "#/components/schemas/Subscription"
type: object
properties:
id: { type: string }
plan:
$ref: "#/components/schemas/InvoiceSummary"Non-conformant patterns
Bad — list item with extra list-only property and type drift, PATCH accepting readOnly createdAt and missing additionalProperties: false, PATCH 200 returning a mismatched shape, and invalid x-photon-resource pointers:
components:
schemas:
BadProjectListItem:
x-photon-resource:
role: slice
canonical: "#/components/schemas/Project"
type: object
properties:
id:
type: integer
listOnlyBadge:
type: string
BadPatchProjectRequest:
x-photon-resource:
role: patch
canonical: "#/components/schemas/Project"
type: object
required:
- name
properties:
id:
type: string
createdAt:
type: string
format: date-time
name:
type: string
BadDerivedAnnotation:
x-photon-resource:
role: slice
canonical: "#/components/schemas/NonExistentResource"
nonResourceInputs:
- templateId
type: object
properties:
id:
type: stringChangelog
- 2026-11-28: Approved and published as
ADS-0007, defining the canonical resource model, per-serviceOperationcanonical resources, cross-method response consistency, collection slices, mutation input symmetry, thex-photon-resourceOpenAPI extension, and sub-resource rules for owned value objects, embedded resources and nested slices, and URL-nested collection and singleton sub-resources.
Feedback
Found a Photon API that does not follow this standard, or have a suggestion to improve it? Open an issue in photon-hq/api-design-standards (we do not accept external pull requests).