|
| 1 | +// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +// Package alias_responses_calibration is the cycle-5 calibration |
| 5 | +// fixture for the W3 alias workshop — the responses-builder |
| 6 | +// analogue of cycle-4 (alias-parameters-calibration). |
| 7 | +// |
| 8 | +// The fixture surfaces the responses-builder's current behaviour |
| 9 | +// for the three reach contexts the cycle-5 workshop has to cover: |
| 10 | +// |
| 11 | +// 1. Top-level alias annotated `swagger:response` — |
| 12 | +// AliasedTopResponse = internalResponse. The existing |
| 13 | +// alias-response/ fixture documents that the Default mode |
| 14 | +// crashes on this path ("anonymous types are currently not |
| 15 | +// supported for responses"); R8 should fix that as a side |
| 16 | +// effect of routing through the alias's RHS. |
| 17 | +// 2. Body field typed as an alias, both annotated and unannotated |
| 18 | +// — DirectResponse.BodyAliasPlain / .BodyAliasModeled. |
| 19 | +// 3. Non-body (header) field typed as an alias — DirectResponse |
| 20 | +// header fields. |
| 21 | +// |
| 22 | +// `DirectResponse` carries the control case (BodyDirect typed as |
| 23 | +// the raw Envelope model) alongside the alias variants so the |
| 24 | +// comparison is on one canvas. |
| 25 | +// |
| 26 | +// Two real `swagger:route` handlers bind the responses to |
| 27 | +// operations so the response shapes are visible in the captured |
| 28 | +// spec under the operations' `responses` block (and any |
| 29 | +// auto-discovered top-level entries under the spec's `responses` |
| 30 | +// block too). |
| 31 | +// |
| 32 | +// See `.claude/plans/workshops/alias-responses.md` §4 for the R8 |
| 33 | +// rule candidate and `.claude/plans/workshops/alias-ledger.md` |
| 34 | +// cycle 5 for the running judgment record. |
| 35 | +package alias_responses_calibration |
| 36 | + |
| 37 | +// Envelope is the canonical response body model. |
| 38 | +// |
| 39 | +// swagger:model Envelope |
| 40 | +type Envelope struct { |
| 41 | + // required: true |
| 42 | + ID int64 `json:"id"` |
| 43 | + |
| 44 | + Name string `json:"name"` |
| 45 | +} |
| 46 | + |
| 47 | +// HeaderID is a named string backing the non-body (header) alias |
| 48 | +// witnesses. SimpleSchema targets can't carry $ref, so R8 clause 3 |
| 49 | +// always expands non-body aliases regardless of annotation. |
| 50 | +type HeaderID string |
| 51 | + |
| 52 | +// EnvelopeAlias is an UNANNOTATED alias of Envelope. Under R8 the |
| 53 | +// body field reference must dissolve to `$ref: Envelope` (not |
| 54 | +// `$ref: EnvelopeAlias`), and the alias must not produce its own |
| 55 | +// `definitions` entry. |
| 56 | +type EnvelopeAlias = Envelope |
| 57 | + |
| 58 | +// EnvelopeAliasModeled is the ANNOTATED counterpart of |
| 59 | +// EnvelopeAlias. `swagger:model` opts the alias in as a |
| 60 | +// first-class spec entity — body field sites preserve |
| 61 | +// `$ref: EnvelopeAliasModeled` and the alias gets its own |
| 62 | +// definition. |
| 63 | +// |
| 64 | +// swagger:model EnvelopeAliasModeled |
| 65 | +type EnvelopeAliasModeled = Envelope |
| 66 | + |
| 67 | +// EnvelopeAlias2 is a 2-link unannotated chain. Both links |
| 68 | +// dissolve under R8 → body fields land on `$ref: Envelope`. |
| 69 | +type EnvelopeAlias2 = EnvelopeAlias |
| 70 | + |
| 71 | +// HeaderIDAlias is an unannotated alias of HeaderID. Non-body |
| 72 | +// SimpleSchema use sites can't carry $ref regardless of annotation; |
| 73 | +// the witness mainly asserts the alias does not produce a dangling |
| 74 | +// definition. |
| 75 | +type HeaderIDAlias = HeaderID |
| 76 | + |
| 77 | +// internalResponse is the unexported backing struct for the |
| 78 | +// top-level aliased response below. Q12 witness — pre-R8 captures |
| 79 | +// surface this struct as a `definitions` entry under non-Transparent |
| 80 | +// modes despite carrying no `swagger:model` annotation. |
| 81 | +type internalResponse struct { |
| 82 | + // Body is the response body for the aliased top-level response. |
| 83 | + // |
| 84 | + // in: body |
| 85 | + Body Envelope `json:"body"` |
| 86 | + |
| 87 | + // XSession is a header on the aliased top-level response. |
| 88 | + // |
| 89 | + // in: header |
| 90 | + XSession HeaderID `json:"X-Session"` |
| 91 | +} |
| 92 | + |
| 93 | +// AliasedTopResponse is a top-level alias annotated |
| 94 | +// `swagger:response`. R8 clause 1 says neither this alias nor its |
| 95 | +// backing struct should surface in `definitions` — the response's |
| 96 | +// body / headers come from the fields of the unaliased target. |
| 97 | +// |
| 98 | +// swagger:response aliasedTopResponse |
| 99 | +type AliasedTopResponse = internalResponse |
| 100 | + |
| 101 | +// DirectResponse is the control response: declared directly (not |
| 102 | +// via an alias), holding body and non-body fields typed as the |
| 103 | +// alias variants above so every reach context is visible inside |
| 104 | +// one response. |
| 105 | +// |
| 106 | +// swagger:response directResponse |
| 107 | +type DirectResponse struct { |
| 108 | + // BodyDirect — body typed as the raw Envelope model (control |
| 109 | + // case, R6/R7/R8-independent). |
| 110 | + // |
| 111 | + // in: body |
| 112 | + BodyDirect Envelope `json:"bodyDirect"` |
| 113 | + |
| 114 | + // XHeaderPlain — header typed as the UNANNOTATED alias |
| 115 | + // HeaderIDAlias. SimpleSchema target — the alias must expand |
| 116 | + // to its primitive type inline regardless of mode, and |
| 117 | + // HeaderIDAlias must not appear in `definitions`. |
| 118 | + // |
| 119 | + // in: header |
| 120 | + XHeaderPlain HeaderIDAlias `json:"X-Header-Plain"` |
| 121 | +} |
| 122 | + |
| 123 | +// BodyAliasPlainResponse — body response typed as the UNANNOTATED |
| 124 | +// alias EnvelopeAlias. Under R8 the body schema's $ref dissolves |
| 125 | +// to Envelope. |
| 126 | +// |
| 127 | +// swagger:response bodyAliasPlainResponse |
| 128 | +type BodyAliasPlainResponse struct { |
| 129 | + // in: body |
| 130 | + Body EnvelopeAlias `json:"body"` |
| 131 | +} |
| 132 | + |
| 133 | +// BodyAliasModeledResponse — body response typed as the |
| 134 | +// ANNOTATED alias EnvelopeAliasModeled. Under R8 the body |
| 135 | +// schema's $ref preserves EnvelopeAliasModeled (and the alias |
| 136 | +// surfaces as its own definition). |
| 137 | +// |
| 138 | +// swagger:response bodyAliasModeledResponse |
| 139 | +type BodyAliasModeledResponse struct { |
| 140 | + // in: body |
| 141 | + Body EnvelopeAliasModeled `json:"body"` |
| 142 | +} |
| 143 | + |
| 144 | +// BodyAliasChainResponse — body response typed as the 2-link |
| 145 | +// unannotated chain EnvelopeAlias2. Both layers dissolve to |
| 146 | +// Envelope. |
| 147 | +// |
| 148 | +// swagger:response bodyAliasChainResponse |
| 149 | +type BodyAliasChainResponse struct { |
| 150 | + // in: body |
| 151 | + Body EnvelopeAlias2 `json:"body"` |
| 152 | +} |
0 commit comments