Fix/backlog lot1#42
Merged
Merged
Conversation
go-swagger issue #3214 reported that a struct field referencing a named primitive type (e.g. `State State` -> `type State string`) whose doc comment carried both prose and an inline `enum:` annotation was only parsed for title/description, with the `enum:` declaration line wrongly folded into the description instead of parsed into enum values. The grammar2 migration already fixed this. This adds a regression lock: the referenced primitive is emitted as its own definition with `enum` parsed and the prose preserved (single-line -> title; multi-paragraph -> title + description), and the `enum:` line never leaks into either. Holds for ScanModels on and off. - fixtures/bugs/3214/types.go: the issue repro (Order/State) plus a multi-paragraph Currency variant pinning description survival. - internal/integration/coverage_bug_3214_test.go: asserts the parsed shape directly and compares against a golden. - fixtures/integration/golden/bugs_3214_schema.json: captured golden. * contributes go-swagger/go-swagger#3214 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
go-swagger issue #3107 reported that `generate spec -m` (scan-models) emitted a swagger:model struct as an empty definition carrying only `x-go-package`, with all fields dropped. This no longer reproduces. This adds a regression lock: under ScanModels the model is emitted with `type: object` and its full property set. The fixture places the model in its own package, referenced cross-package by a route response body, so it also exercises type resolution through the import graph — the v0.30.5 trigger where the model package was resolved by reference rather than directly scanned. Modern go/packages loading resolves the type fully. - fixtures/bugs/3107/model: the MyStruct swagger:model. - fixtures/bugs/3107/api: route whose response references it cross-package. - internal/integration/coverage_bug_3107_test.go: asserts the non-empty shape directly and compares against a golden. - fixtures/integration/golden/bugs_3107_schema.json: captured golden. * contributes go-swagger/go-swagger#3107 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…er#3100) go-swagger issue #3100 reported that a parameter declared with `in: formData` inside an inline `swagger:route` annotation lost its `in` field in the generated spec — the scanner only recognised `form` — so the parameter rendered with name/type/description but no `in`. This no longer reproduces. This adds a regression lock: the grammar YAML body parser preserves `in: formData` verbatim. The fixture uses the reporter's `+name:` flush form with two formData params plus a query param so the golden proves `in` survives for formData specifically, alongside other locations. - fixtures/bugs/3100/api.go: inline swagger:route with formData params. - internal/integration/coverage_bug_3100_test.go: asserts every param carries `in` and the formData values, plus golden compare. - fixtures/integration/golden/bugs_3100_schema.json: captured golden. * contributes go-swagger/go-swagger#3100 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…796) go-swagger issue #796 reported that `generate spec -m` (scan-models) emitted definitions for types carrying no `swagger:model`: an un-annotated interface (Handler) and a `swagger:parameters` struct (pingParams) both leaked into `definitions`. The parameter struct also folded its `in: path` annotation line into the property description. Neither reproduces. This adds a regression lock: under ScanModels only the swagger:model type (pingResponse) is emitted; the interface is dropped and the parameter struct renders as an operation parameter with a clean description and a real `in: path` field. - fixtures/bugs/796/main.go: faithful repro (meta + model + bare interface + parameters struct + route). - internal/integration/coverage_bug_796_test.go: asserts the absence of the extra definitions and the clean parameter, plus golden compare. - fixtures/integration/golden/bugs_796_schema.json: captured golden. * contributes go-swagger/go-swagger#796 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
go-swagger issue #3035 reported that a swagger:response whose body is an anonymous inline struct emitted only the response description with no schema at all — dropping the field-level Example/Required and property descriptions. This no longer reproduces: the inline body struct now produces a full object schema with its required set, property descriptions, and per-field example (examples in responses work). Confirmed with and without a blank line after the body field's leading prose. Documented delta: the schema-level description sourced from the body field's leading comment is not emitted. No codescan path surfaces a body field's prose as the schema description (verified against all response goldens) and the blank line does not enable it — consistent behaviour, not a regression. The test asserts that delta explicitly so a future change to it is a conscious decision. - fixtures/bugs/3035/response.go: the issue repro (inline body struct with field-level Example/Required), blank-line annotation form. - internal/integration/coverage_bug_3035_test.go: asserts the schema and the field example, plus golden compare. - fixtures/integration/golden/bugs_3035_schema.json: captured golden. * contributes go-swagger/go-swagger#3035 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
go-swagger issue #958 ("how to specify sample values in user structs")
noted that a field-level `default:` (and example) was carried for a plain
builtin field but dropped when the field used a named/defined type such
as `type SpecificType string`.
This no longer reproduces: both default and example survive for
defined-type fields. Because a $ref cannot carry sibling keywords, they
ride the override arm of an allOf compound — the same draft-4-compliant
shape used for description/example on $ref'd fields (#3125).
- fixtures/bugs/958/types.go: a plain-field model and a defined-type
model, each carrying default and example.
- internal/integration/coverage_bug_958_test.go: asserts the inline
placement for the plain field and the allOf override arm for the
defined-type field, plus golden compare.
- fixtures/integration/golden/bugs_958_schema.json: captured golden.
* contributes go-swagger/go-swagger#958
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…796 sibling #1109) go-swagger issue #1109 reported "invalid swagger.json when returning response is model": a route with `200: order`, where `order` is a model (not a named response), produced a dangling `$ref: #/responses/order` and no definitions. Per @casualjim this is expected behaviour, not a bug. Verified: the invalid-spec symptom no longer occurs. `200: <name>` resolves as (1) a named response → `$ref: #/responses/<name>`, else (2) a scanned model definition (requires -m) → promoted to a body `$ref: #/definitions/<name>`, else (3) dropped with a warning diagnostic rather than emitting an invalid ref. So the OP's exact `200: order` form now works with -m via the definition-fallback, as does casualjim's `200: body:order`. This is primarily a documentation matter (the -m requirement and the name-resolution order); flagged "Need doc" in the backlog. This commit locks both working forms as a regression witness. - fixtures/bugs/1109/responseref: OP's `200: order` form (definition fallback). - fixtures/bugs/1109/bodyref: casualjim's `200: body:order` form. - internal/integration/coverage_bug_1109_test.go: asserts a body schema $ref to the order definition (no dangling response ref, definition present) for both forms, plus golden compare. - fixtures/integration/golden/bugs_1109_{responseref,bodyref}_schema.json. * contributes go-swagger/go-swagger#1109 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
go-swagger issue #624 ("Model responses don't get included in
definitions", a regression from #596) reported that a model used only as
a field of a response body was not added to definitions. The reporter's
repro is the booking API, which is already in-repo as
fixtures/goparsing/bookings/api.go and asserted by
TestAppScanner_Definitions.
Verified no longer reproduces: the model-discovery rule works as the
reporter expected — a struct lands in definitions when swagger:model
-annotated OR referenced (transitively) by a route/response body;
un-annotated unreferenced structs are excluded. No new fixture: the
example exposes nothing the existing fixtures don't already cover (bare
`swagger:model`, body:Model responses are covered elsewhere).
This adds a doc comment cross-linking the locking test to the issue.
Primarily a documentation matter (the discovery rule); flagged "Need
doc" in the backlog for the doc-site pass.
* contributes go-swagger/go-swagger#624
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…-swagger#874)
go-swagger issue #874 reported that `swagger:response` "doesn't work with
a package prefix": a dotted name like `utils.Error` produced no response.
Root cause: the loose classification regex (rxSwaggerAnnotation) accepts
the `swagger:response` marker, so the type is classified as a response,
but the strict name matcher (rxResponseOverride) rejects `utils.Error`
(names must be plain identifiers). The two disagreed, so the annotation
was silently dropped with no feedback.
The OP's actual goal already works: cross-package types resolve
automatically and a plain response name round-trips fine. The package
prefix was a misunderstanding — response/definition names are JSON labels,
not Go-qualified identifiers, and we intentionally keep the name alphabet
to plain identifiers (opening it to `.` would invite arbitrary
characters).
The genuine defect was the silent drop. This makes the scanner WARN when
a swagger:model / swagger:response name is not a plain identifier, instead
of dropping it silently — consistent with the no-silent-fallthrough
posture elsewhere in the scanner.
- internal/parsers/{regexprs,matchers}.go: MalformedModelName /
MalformedResponseName detectors (loose arg capture vs strict override).
- internal/scanner/index.go: warnMalformedStructName, called from the
model/response classification arms (extracted to keep detectNodes under
the cognitive-complexity budget).
- internal/parsers/matchers_test.go: TestMalformedOverrideName — dotted
names flagged; bare markers, plain names, and trailing periods are not.
Primarily a documentation matter too (names are plain labels); flagged
"Need doc" in the backlog.
* contributes go-swagger/go-swagger#874
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…3213)
go-swagger issue #3213 ("Consider TypeSpec comments") asked whether doc
comments / swagger annotations attached to an individual TypeSpec inside a
grouped `type ( ... )` declaration — rather than to the enclosing GenDecl
— are parsed.
They are. This locks it with a fixture that proves per-TypeSpec capture:
two models share ONE type group, each with its own doc comment, and both
surface their distinct titles (a GenDecl-only reader could not). A grouped
swagger:enum referenced by one of them also has its const values parsed.
- fixtures/bugs/3213/api.go: two grouped models + a grouped enum.
- internal/integration/coverage_bug_3213_test.go: asserts both distinct
titles and the grouped enum values, plus golden compare.
- fixtures/integration/golden/bugs_3213_schema.json: captured golden.
* contributes go-swagger/go-swagger#3213
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
go-swagger issue #3119 ("Can not declare normal field in properties of
schema object") reported that scalar fields (limit, offset) declared
alongside an array field inside an inline swagger:operation response
schema ended up as siblings of `properties` rather than inside it.
Not a codescan defect. With consistent YAML indentation, scalar and array
properties all land correctly inside `properties` (matching the
reporter's own expected output). The reporter's input mixed tabs and
spaces, which is what broke the nesting — a YAML-indentation mistake, not
a parser bug.
No fixture: the behaviour is already exercised by the inline
swagger:operation corpus. Flagged "Need doc" in the backlog so the doc
site can warn that inline-schema YAML indentation must be consistent
(mixed tabs/spaces silently re-nests properties).
* contributes go-swagger/go-swagger#3119
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
go-swagger issue #2961 ("Improper parsing of uint enums") reported that an
`enum:` on a uint / uint64 field was emitted as strings (["1","2","3"]).
Fixed: enum values are coerced against the integer schema type, so a
`uint`/`uint64` field's `enum: 1,2,3` yields numeric `[1,2,3]`.
- fixtures/bugs/2961/api.go: uint and uint64 fields with comma-list enums.
- internal/integration/coverage_bug_2961_test.go: asserts numeric enum
values, plus golden compare.
* contributes go-swagger/go-swagger#2961
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…-swagger#3007)
go-swagger issue #3007 ("[Bug]generate spec error") reported that a
kubebuilder marker `+kubebuilder:default:=false` aborted the scan with
`strconv.ParseBool parsing "=false"`.
Fixed: the scan no longer crashes on non-swagger comment markers. Residual
(flagged Need doc): the marker is currently absorbed into the field
description rather than ignored — filtering known non-swagger markers
(kubebuilder, etc.) out of prose is a possible future enhancement, captured
as a TODO in the test.
- fixtures/bugs/3007/api.go: a field carrying a kubebuilder marker.
- internal/integration/coverage_bug_3007_test.go: asserts no scan error
and documents the description residual, plus golden compare.
* contributes go-swagger/go-swagger#3007
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…(go-swagger#3069)
go-swagger issue #3069 ("change the representation of one parameter") asked
how to make a custom-marshalled struct render with its real wire format.
codescan cannot infer a custom MarshalJSON, but a `swagger:type` override
(or encoding.TextMarshaler / swagger:strfmt) states the representation
explicitly. This witness shows ComplexType -> string making a
[]ComplexType field render as an array of strings, matching the reporter's
format. Flagged Need doc (document the override for custom-marshalled types).
- fixtures/bugs/3069/api.go: a custom-marshalled struct overridden via
swagger:type, used in a slice field.
- internal/integration/coverage_bug_3069_test.go: asserts array-of-string
items, plus golden compare.
* contributes go-swagger/go-swagger#3069
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…gger#2959)
go-swagger issue #2959 ("Unable to provide security definitions") reported
that a SecurityDefinitions block in swagger:meta crashed with "found
character that cannot start any token" — caused by TAB-indented YAML.
No longer reproduces: tab-indented SecurityDefinitions parse cleanly. This
is already covered by the existing meta fixtures (fixtures/goparsing/meta/v3
uses tab-indented SecurityDefinitions; enhancements_meta_securitydefs has a
golden), so no new fixture is added — this commit records the contribution
reference.
* contributes go-swagger/go-swagger#2959
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…2907)
go-swagger issue #2907 ("Go-Swagger not generating properties in yaml
file") reported that a response whose body is a slice of a cross-package
model (`Body []data.Movie`) emitted `items: {}` — the model's properties
were lost.
Fixed: the cross-package model is resolved, so the response schema is an
array of `$ref` to the emitted definition (with/without -m). The json:"-"
field is correctly excluded.
- fixtures/bugs/2907/{data,api}: a model in a sibling package referenced as
a []Model response body.
- internal/integration/coverage_bug_2907_test.go: asserts array-of-$ref
items and the emitted definition, plus golden compare.
* contributes go-swagger/go-swagger#2907
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…agger#2917) go-swagger issue #2917 reported `classifier: unknown swagger annotation "extendee"` when importing grpc-gateway openapiv2 options: an over-broad annotation regex matched `…openapiv2_swagger:extendee…` inside a generated comment and aborted the scan. Fixed: the current regex only matches `swagger:` at start-of-line or after whitespace/slash, so an embedded `_swagger:extendee` is not treated as an annotation. The scan completes. - fixtures/bugs/2917/api.go: a protobuf-style comment carrying `openapiv2_swagger:extendee`. - internal/integration/coverage_bug_2917_test.go: asserts no scan error, plus golden compare. * contributes go-swagger/go-swagger#2917 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…2912) go-swagger issue #2912 asked why parameter names come from Go field names rather than the `form:"..."` struct tag. Works-as-designed: codescan derives parameter names from the `json:` tag (the established convention), falling back to the Go field name. The `form:` tag (a binding-framework concern) is not consulted. Confirmed: a field with only `form:"sort_key"` is named `SortKey`, while adding `json:"sort_key"` names it `sort_key`. No code change; no fixture (json-tag naming is already exercised by the named-struct-tags corpus). Flagged "Need doc": document that parameter names derive from json tags, and the form-tag workaround. * contributes go-swagger/go-swagger#2912 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Mirror the go-openapi/runtime doc-site pattern to bootstrap https://go-openapi.github.io/codescan/: - hack/doc-site/hugo/: Hugo config, local runner (gendoc.go), the `code` shortcode + partials, and the shared go-openapi branding assets - .github/workflows/update-doc.yml: build + deploy to GitHub Pages - docs/doc-site/: home, usage (getting-started, examples, reference) and project (README, LICENSE) content - docs/examples/: a separate, test-covered Go module whose annotated petstore is scanned by codescan.Run; doc pages pull snippets straight from source via `// snippet:` markers, and the example page renders a golden swagger.json the test verifies (UPDATE_GOLDEN=1 to regenerate) Adding docs/examples makes this a multi-module repo, so: - switch go-test.yml to the go-test-monorepo.yml reusable workflow, so the examples module is built, tested and linted in CI alongside the root - disable gomoddirectives in .golangci.yml: local replace directives are needed for proper releasing of a multi-module repo Reference material under docs/*.md is linked from usage/reference for now; migrating it into first-class site pages is tracked separately. Signed-off-by: Frederic BIDON <fredbi@yahoo.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…lidations (go-swagger#2985)
go-swagger issue #2985 asked for minProperties / maxProperties (the
reporter's "minAttributes/maxAttributes") on swagger:model object types.
code-to-spec lacked them: they were not grammar keywords, so the
annotation lines were swallowed into the model description and no
validation was emitted on the object schema (spec-to-code already had
them). This adds them, the sibling patternProperties keyword, and wires
the wrong-context diagnostics that were previously missing for all three.
minProperties / maxProperties:
* new CtxSchema-only asInt() grammar keywords (object validations have no
SimpleSchema form), mirroring minItems/maxItems
* SchemaValidations.SetMin/MaxProperties wired through both schema-dispatch
paths (schemaIntegerHandler + walker.go onInteger)
* the validations.keywordTypeRules object shape-rule was already present
patternProperties:
* new CtxSchema-only asString() keyword whose argument is a regex; each
line adds a `regex -> {}` entry to schema.patternProperties
* the regex gets the same RE2-hygiene check as `pattern`: a non-compiling
value emits CodeInvalidAnnotation but is preserved (never dropped) — the
shared check is factored into warnInvalidRE2
Wrong-context diagnostics (previously silent):
* non-object model — a top-level scalar swagger:model dispatches its doc
block before the Go type is resolved, so the inline checkShape saw an
empty type and applied object/array/string/number keywords anyway. New
handlers.RecheckSchemaShape, called from schema.Build after buildFromDecl,
strips validations illegal for the resolved type and emits
CodeShapeMismatch. Done as a post-hoc strip rather than a dispatch
reorder to avoid changing default:/enum: coercion timing — zero golden
churn.
* SimpleSchema sites — the param/header/items dispatchers silently dropped
full-Schema-only object keywords. handlers.Integer now takes a diag and,
with UnsupportedSimpleSchemaString, emits CodeUnsupportedInSimpleSchema
for CtxSchema-only keywords (predicate isFullSchemaOnly, which correctly
excludes param-legal keywords like `in:`).
Tests/fixtures:
* bugs/2985 — object model asserting minProperties:1 / maxProperties:10
and no description leak
* enhancements/pattern-properties — valid + invalid-regex models
* enhancements/object-keywords-context — kept / shape-mismatch /
simple-schema across all three contexts
* keyword docs (docs/keywords.md), schema README (§decl-shape-recheck),
validations README type-domain table updated
* closes go-swagger/go-swagger#2985
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…#2875)
go-swagger issue #2875 ("AllOf member does not generate an external $ref
object"): an embedded struct annotated `swagger:allOf` inlined the embedded
type's properties instead of emitting an `allOf: [{$ref}]`.
Fixed: the member is emitted as an `allOf` arm referencing the embedded
model's definition via $ref.
- fixtures/bugs/2875/api.go: AllOfModel embedding SimpleOne with swagger:allOf.
- internal/integration/coverage_bug_2875_test.go: asserts the allOf $ref arm
and the emitted SimpleOne definition, plus golden compare.
* contributes go-swagger/go-swagger#2875
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
go-swagger issue #2899 ("Example not being added to schema for body string
params"): an `example:` on an inline body parameter of primitive type was
dropped.
Fixed: the example is carried onto the body parameter's schema. A known
residual (quirk F8) is tracked separately: a quoted string example
(`example: "123456"`) currently retains its surrounding quotes; the test
asserts the current value and references F8.
- fixtures/bugs/2899/api.go: inline body param with type:string + example.
- internal/integration/coverage_bug_2899_test.go: asserts the example is on
the param schema (the fix); documents the F8 quoting residual.
* contributes go-swagger/go-swagger#2899
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
go-swagger issue #2897 ("with go1.20 swagger missing definitions and refs")
reported missing definitions/refs from a debian-repo swagger binary, while a
self-built binary worked.
Not a codescan logic bug: the reporter's example (a swagger:response with a
struct Body) produces the definition and $ref correctly in the current
scanner. The failure was environmental (a stale/mismatched packaged binary
vs go version), not a scanner defect. No fixture (response-struct-body
resolution is already covered by #1109 / #2907).
* contributes go-swagger/go-swagger#2897
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
go-swagger issue #2898 reported that `[]interface{}` changed in 0.30 to emit
`items: {}` instead of `items: {type: object}`.
Works-as-designed: `items: {}` (an empty schema = "any type") is the correct
representation for a slice of `interface{}` — `{type: object}` would wrongly
restrict the elements to objects. The 0.30 change is a correctness
improvement, not a regression. No code change; flagged Need doc to explain
the rationale.
* contributes go-swagger/go-swagger#2898
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…wagger#2909)
go-swagger issue #2909 ("Regular cannot generate swagger automatically"): a
route path with an inline regex segment (gorilla/chi style, e.g.
{id:[0-9]+}) was silently dropped. rxPath's alphabet has no `[`/`]`, so the
swagger:route / swagger:operation line failed to match, the scanner never
collected the path, and nothing was emitted — with no diagnostic.
OpenAPI 2.0 path templating follows RFC 6570 URI Template Level-1 expansion
only (simple `{name}` substitution); it cannot express a regex constraint.
go-openapi's runtime path-templating middleware is Level-1 too. So rather
than silently dropping the route, strip the `:regex` constraint and warn.
Fix:
* parsers.stripPathParamRegex rewrites `{name:regex}` -> `{name}` on the
comment line BEFORE the rxRoute/rxOperation match. Brace matching is
depth-aware, so regex quantifiers carrying their own braces
({id:[0-9]{2,4}}) are handled. No rxPath alphabet change needed; the
original line is preserved for the description block.
* ParsedPathContent gains Pos + StrippedParams to carry the strip info out
of the scanner.
* common.Builder.WarnStrippedPathRegex (shared by the routes and operations
builders) emits a parse.invalid-annotation warning naming the affected
params and explaining the RFC 6570 Level-1 limitation.
Result: /items/{id:[0-9]+} now emits as /items/{id} with the operation
intact, plus a warning that the constraint was dropped.
Tests/fixtures/docs:
* bugs/2909 — asserts the route now emits as /items/{id} and warns
* enhancements/path-regex-stripping — swagger:route (multi-param),
swagger:operation (nested-brace quantifier), and a plain {id} control
that raises no warning
* unit table-test for stripPathParamRegex (simple / slash-class / nested /
multiple / no-colon control / unbalanced / empty-name)
* docs/annotations.md swagger:route path section documents RFC 6570 Level-1
and the strip behaviour
* closes go-swagger/go-swagger#2909
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
go-swagger issue #2802 ("Error generating spec if swagger:model is a
generic struct"): an instantiated generic (`WrappedRequest[Request]`)
panicked with "can't determine refined type T (*types.TypeParam)".
No longer panics: the instantiated type resolves its argument
(`Body.Body -> $ref: Request`); the uninstantiated generic's free type
param `T` is skipped with a warning (no spec representation), and the scan
completes.
- fixtures/bugs/2802/api.go: a generic struct + an instantiated alias.
- internal/integration/coverage_bug_2802_test.go: asserts the instantiated
type argument resolves to a $ref, plus golden compare.
* contributes go-swagger/go-swagger#2802
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…swagger#2837)
go-swagger issue #2837 ("Responses defined in routes break with go 1.19
formatting"): gofmt rewrites a route's `+ name:` parameter bullet to
`- name:`, which used to break parsing.
Both forms now parse to the same parameter. The fixtures are intentionally
the authored `+` form and the gofmt-canonical `-` form (fixtures/ is
excluded from the formatters); the test asserts they yield identical
parameters.
- fixtures/bugs/2837a (+ form) and 2837b (- / gofmt-canonical form).
- internal/integration/coverage_bug_2837_test.go: asserts both forms parse
to the same body param and golden-compares the gofmt-canonical output.
* contributes go-swagger/go-swagger#2837
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
go-swagger issue #2860 ("Models do not show fields from the struct")
reported that `-m` on the petstore fixture emitted definitions with only
title/x-go-name and no properties/required.
No longer reproduces: the petstore models emit their full fields, required
sets, and nested item schemas. Already covered by the petstore goldens
(petstore_schema_Order.json etc. and TestAppScanner_*). No new fixture;
contribution recorded via an empty commit.
* contributes go-swagger/go-swagger#2860
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #42 +/- ##
==========================================
+ Coverage 80.18% 81.83% +1.64%
==========================================
Files 71 80 +9
Lines 5739 7433 +1694
==========================================
+ Hits 4602 6083 +1481
- Misses 859 1006 +147
- Partials 278 344 +66 ☔ View full report in Codecov by Harness. |
…ets (go-swagger#2804)
go-swagger issue #2804 ("Should swagger:parameters support
map[string][]string?"): a Go map has no OAS2 SimpleSchema representation,
yet a map-typed field was mishandled in both SimpleSchema targets.
- swagger:parameters (non-body: query/formData/path/header): the scan
crashed with a nil-pointer dereference (parameterBuilder.buildFromField
-> Schema.Typed on a nil schema), because paramTypable.Schema() returns
nil off-body.
- swagger:response headers (in: header): no panic, but the map silently
wrote `object` onto the response *body* schema and left the header
untyped, because responseTypable.Schema() always returns the body
schema.
Both builders now apply the identical guard in buildFromFieldMap
(`typable.In() != inBody`): they return an internal sentinel
(errUnrepresentableParam / errUnrepresentableHeader); the field-level
caller records a located `validate.unsupported-in-simple-schema` warning
and skips the field instead of panicking or corrupting the output. Body
maps (object + additionalProperties) are unaffected.
The fixture carries both a map query param and a map response header; the
test asserts no panic, both fields skipped, the response body schema not
corrupted, and both diagnostics emitted. Also a concrete live witness for
the §8.1 scanner panic-recovery feature (forthcoming-features.md) — the
recover boundary should turn any remaining such panic into the same
located diagnostic.
* contributes go-swagger/go-swagger#2804
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…s (go-swagger#2251)
buildFromMap only emitted additionalProperties when the map key was string-
underlying or a TextMarshaler, silently dropping every other key to a typeless
property. But encoding/json marshals integer-kind keys (map[int]V, map[uint8]V,
uintptr, named integer types) as quoted JSON string keys, so those maps ARE
representable as {type: object, additionalProperties: V}.
Widen the gate via a new resolvers.IsJSONMapKey, mirroring encoding/json's
newMapEncoder rule exactly: key is a string kind OR any integer/unsigned kind
(incl. uintptr) OR implements encoding.TextMarshaler (json.Marshaler is never
consulted for keys; fmt.Stringer does not qualify).
A key that json.Marshal itself rejects (float, bool, struct without
TextMarshaler, interface, ...) is no longer dropped silently: it raises a
CodeUnsupportedType warning ("additionalProperties dropped") and emits no
additionalProperties. json:"-" map fields are muted before buildFromMap, so
they never warn.
The go123/special witness `index_map` (map[int]struct{}, formerly named
UnsupportedMap and asserted to render empty) is now genuinely supported:
renamed IndexedMap, its subtest asserts object+additionalProperties, and the
one drifting golden (go123_special_spec.json) is regenerated.
* contributes go-swagger/go-swagger#2251
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
… additionalProperties Adds the type/model-level `swagger:additionalProperties <spec>` classifier, where <spec> is `true`, `false`, or a swagger:type-style spec (primitive / []T / type-name). On a struct it complements the object (named properties stay — e.g. `false` closes the object); on a map it overrides the element-derived value schema; on a type that resolved to a bare $ref it defines a clean object. A type-name resolves to a $ref (and is registered for discovery), matching how a map[string]Model field renders. additionalProperties is the lowest-priority annotation: it only rides on an object, so a prior non-object resolution (swagger:type on a non-object, swagger:strfmt, a special type) drops it with a shape-mismatch diagnostic. It composes with the other object validations (maxProperties, ...). This resolves go-swagger#3005 (named properties + free-form values: the json:"-" map stays muted, the marker supplies the value schema) and implements the explicit additionalProperties control of go-swagger#2539 (forthcoming §17). Wired through the grammar (AnnAdditionalProperties classifier + argTypeRef arg) and the scanner classifier allow-list; resolved in classifierAdditionalProperties applied from Build after the Go type is known. * contributes go-swagger/go-swagger#3005 * contributes go-swagger/go-swagger#2539 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Adds the field-level `additionalProperties: <spec>` keyword (CtxSchema), sharing
the <spec> grammar (true | false | swagger:type-style spec) with the
swagger:additionalProperties marker. The resolver is refactored into a pure
resolveAdditionalPropertiesValue shared across the marker, the field keyword, and
the $ref-sibling path.
Two landing paths:
- a non-$ref field (map / inline object / primitive) post-scans the field block
and applies the spec on the field schema: it overrides a map's element schema,
or warn-drops on a primitive (lowest-priority precedence, like the marker);
- a $ref'd field rides the value as an allOf sibling
({allOf: [{$ref}, {additionalProperties: ...}]}) so the reference is preserved
(JSON-Schema-draft-4 semantics).
* contributes go-swagger/go-swagger#2539
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Adds the type/model-level `swagger:patternProperties "<re>": <spec>, …` marker —
the typed counterpart of the regex-only patternProperties: keyword (which sets an
empty {} value). Each pair maps a quoted property-name regex to a value schema
resolved through the shared <spec> grammar (primitive / []T / type-name → $ref).
The lexer captures the whole pair-list remainder as one raw arg token (regexes
may contain spaces / colons / commas); parsePatternPropertyPairs splits it,
respecting the double-quoted regex (only \" is an escape inside it — \d and other
backslashes are preserved). Same lowest-priority precedence as
additionalProperties (object-only, $ref-reset). Each regex is RE2-hygiene-checked
(CodeInvalidAnnotation on failure, value preserved); a malformed pair list is
dropped with a diagnostic.
patternProperties is a JSON-Schema-draft-4 keyword (not in the Swagger-2.0 subset)
— emitted ungated by design, consistent with go-openapi's JSON-Schema-first stance.
* contributes go-swagger/go-swagger#2539
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…tternProperties Both keywords are declared CtxSchema-only, so handlers.isFullSchemaOnly classes them full-Schema-only and the param/header/items SimpleSchema dispatchers route them through UnsupportedSimpleSchemaString — dropping the keyword with a CodeUnsupportedInSimpleSchema diagnostic instead of silently absorbing it. The type/model-level markers run only in the definitions branch of Build and never reach a SimpleSchema. Witness covers a non-body (query) parameter and a response header, each carrying additionalProperties + patternProperties: the emitted param/header stay clean strings and four CodeUnsupportedInSimpleSchema diagnostics are raised. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
#2838 reported `generate spec` emitting only the empty 3-line spec despite swagger:meta comments. Root cause was a Go version / toolchain mismatch (the installed Go could not load the project's packages), resolved by adding the `toolchain` directive to go.mod. Not a codescan scanner-logic bug — the basic swagger:meta path works. No witness (environmental/toolchain). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * contributes go-swagger/go-swagger#2838 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
…ger#2663) #2663 asked how to document a POST body parameter. The answer is a single `in: body` field whose Go type IS the body schema; a named type yields a reusable $ref. fixtures/bugs/2663 + TestCoverage_Bug2663 lock this in the issue's own login/CPF domain: one body parameter, schema $ref to AppUserCredentials, and the named-string CPF type preserved as its own definition. The witness also pins the contrast with the malformed forms floated on the issue: marking each scalar field `in: body` would emit one body parameter per field (invalid Swagger 2.0 — at most one body parameter per operation). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * contributes go-swagger/go-swagger#2663 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Replace the short-name definition-key proxy with a real model-identity
mechanism so distinct Go types that share a name no longer merge silently
(and non-deterministically) onto one definition.
The build keys every definition by a fully-qualified, compiler-unique
identity ("<pkgpath>/<name>", EntityDecl.DefKey); a final reduce stage
projects each back to the shortest acceptable user-facing name:
- a globally-unique leaf is lifted to its bare name (byte-identical to
the previous output — zero churn in the common case);
- a colliding leaf is qualified with the minimal-depth PascalCase concat
of its nearest package segments (b.Test / c.Test -> BTest / CTest),
deepening until the group is globally unique, with a diagnostic;
- same-package duplicates (necessarily via swagger:model overrides)
revert the later declaration to its Go name, with a diagnostic;
- a colliding group whose best flat concat exceeds a readability budget
can, opt-in, be emitted as nested container definitions instead.
The whole pass is a pure function of the reachable identity set, so the
output is deterministic regardless of discovery / map-iteration order.
Author short-name $refs resolve to a colliding identity by leaf
(unique -> promote, none -> dangling, ambiguous -> diagnose + drop).
New options (scanner.Options):
- NameConcatBudget (default 0.65): readability-score threshold above
which a concat is a candidate for the hierarchical fail-safe.
- EmitHierarchicalNames (default false): opt into the nested fallback.
Includes the witness corpus (recursion / no-collision controls; the
3-way / mixed / same-package-dup / deep / recursion-collision /
examples-no-mix / hierarchical scenarios) with golden locks, plus the
readability-score exploration harness (disabled).
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
contributes to go-swagger#2783
contributes to go-swagger#2637
contributes to go-swagger#2662
contributes to go-swagger#1734
contributes to go-swagger#2126
contributes to go-swagger#2398
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ords
The type-name keyword sites (swagger:type, swagger:additionalProperties,
swagger:patternProperties) resolved a bare type name only within the
annotating type's own package. A name referring to a model in another
package was silently dropped with an "unknown type" diagnostic — a gap
the name-identity work left open: it gave routes/responses cross-package
leaf resolution but not these schema keywords, and a textual merge could
not surface the inconsistency.
Resolve a bare leaf the same way the reduce stage does: own package first
(a local type wins), then uniquely across the scanned packages' annotated
model set —
- exactly one model with that leaf -> its definition (additionalProperties
/patternProperties emit a $ref via DefKey, so reduce shortens it like
any other; swagger:type inlines as before);
- several -> a validate.ambiguous-type-name diagnostic and the reference
is dropped (never guessed);
- none -> the existing unknown-type diagnostic.
Only the annotated model set (fixed before building) is searched, so the
result is a pure function of the source, not of build order. Witness
fixture keyword-xpkg-leaf covers the unique, ambiguous and swagger:type
cases with a golden lock.
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
contributes to go-swagger#2251
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Builder-unit tests dumped whole-spec snapshots via CompareOrDumpJSON,
capturing the pre-reduce builder output — fully-qualified
"#/definitions/<pkgpath>/<name>" keys and refs that only the spec-level
reduce stage shortens. Those snapshots were noisy, unrepresentative of
real codescan output, and obscured genuine regressions. Golden snapshots
belong to full-pipeline integration tests; unit tests should assert
properties.
- Remove every CompareOrDumpJSON from internal/builders/*_test.go (36
dumps); delete the orphaned fq goldens.
- petstore + classification schema/model coverage consolidates into
full-pipeline integration goldens: petstore_spec.json (existing) and
a new classification_spec.json across the (SkipExtensions, DescWithRef)
option matrix.
- Param/response/route/operation/go118 builder tests build curated
inputs not reachable from any route, so a full scan cannot snapshot
them; these keep their builder exercise and gain targeted property
assertions instead of a snapshot.
- Add a leak-guard integration test that fails if any committed golden
carries a fully-qualified $ref or definition key — locking the
invariant that goldens are always reduced full-pipeline output.
Net: zero golden dumps in builder-unit tests; ~41 fq goldens deleted; 4
clean integration goldens added; full suite + -race + lint green.
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Name-identity / cyclic-$ref deconfliction: distinct same-named models no longer merge silently; colliding definition names are deterministically qualified (minimal-depth concat under a readability budget, with an opt-in hierarchical fail-safe). Adds cross-package leaf resolution for the type-name keywords (swagger:type / additionalProperties / patternProperties), and moves builder-unit golden snapshots to full-pipeline integration tests (with a leak-guard locking the invariant). * contributes to go-swagger#2783 * contributes to go-swagger#2637 * contributes to go-swagger#2662 * contributes to go-swagger#1734 * contributes to go-swagger#2126 * contributes to go-swagger#2398 * contributes to go-swagger#2251 Signed-off-by: Frederic BIDON <fredbi@yahoo.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
codescan already records origin traceability on emitted definitions via x-go-name and x-go-package. This adds an opt-in `Options.EmitXGoType` that also stamps x-go-type with the fully-qualified originating Go type (`<package path>.<type name>`) — useful for round-tripping a generated spec back to its source Go types. The stamp lands in annotateSchema alongside x-go-package and rides the same `SkipExtensions` umbrella (no vendor extension is emitted when SkipExtensions is set). It is presence-guarded so it never clobbers the deliberate x-go-type value the special-type recognizers (`error`, the generic PkgForType fallback) already set; for ordinary types the recognizer leaves it unset and the option supplies it. Default-off, so existing specs are unchanged. Contributes to go-swagger/go-swagger#2924. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
By the first-sentence convention, a single-line doc comment ending in punctuation becomes the `title` (model / info) or `summary` (operation), which is not always what the author wants: some codebases use single-line comments purely as prose descriptions. This adds an opt-in `Options.SingleLineCommentAsDescription` that routes any single-line comment to `description`, never `title` / `summary`. Multi-line comments keep the existing title/description split, so only the single-line case changes. Plumbed through a new grammar parser option (`WithSingleLineCommentAsDescription`) consulted in `finaliseBase` via `demoteSingleLineTitle`: a one-line title (non-empty title, empty description, no embedded newline) is moved to the description, for both the full and preamble title/description pairs. All NewParser call sites (meta / operation / route / schema) pass the option from the scan context. Default-off, so existing specs are unchanged. Contributes to go-swagger/go-swagger#2626. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
The comment claimed externalDocs on route/operation/schema was a pending "separate feature (§9)". That work has landed — operation/schema emit via their own builders and per-tag externalDocs rides the KwTags []spec.Tag unmarshal (locked by TestCoverage_Bug2655). Update the comment to describe where each host object's externalDocs is actually emitted. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
The classification_spec golden snapshotted TextMarshalModel, whose
un-annotated `url.URL` field made the scanner expand net/url.URL (and
url.Userinfo) structurally, copying the stdlib field doc comments into
the spec. Those comments are Go stdlib source and drift between releases
(go1.25 vs go1.26 differ only in this prose), so the golden — generated
under the pinned toolchain go1.26.1 — failed on the go1.25 (oldstable)
CI job.
Expose the existing `URL` type as a swagger:model (keeping its
swagger:strfmt url) and point the field at it instead of bare url.URL.
swagger:strfmt overrides structural expansion (unlike a TextMarshaler,
which only short-circuits fields, not a type built as a model), so the
URL definition becomes {type: string, format: url} — toolchain
independent — while the field keeps its $ref to a single definition
rather than being inlined. The url property is byte-identical to before
($ref #/definitions/URL); only the URL definition body shrinks and
url.Userinfo drops out. customUrl now shares the same URL ref.
The url.URL ref behavior stays covered, version-independently, by the
schema builder unit test (asserting the $ref).
Verified: TestClassification_Spec, the no-fq-leak guard, and the full
suite (incl. -race) pass under both go1.25.7 and go1.26.1 with the same
golden.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Add the single source of truth bridging each annotation keyword to the JSON-pointer location its value renders at in the produced spec (specPointers + PointerPath in keywords.go), gated by the keyword's own Contexts. Consumers read this instead of re-encoding keyword knowledge in each builder walker; it underpins the cross-ref provenance that anchors a spec node to the comment line that produced it (e.g. `maximum` → .../maximum, `version` → /info/version), with the one context-divergent case (deprecated: schema-legal but only an operation/route node) handled in the table rather than at call sites. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Expose the scanner-level data the live spec generator and its diagnostics
view need:
- OnProvenance callback (Options) + Provenance{Pointer, Pos}; ScanCtx
RecordOrigin/OriginEnabled, the deferred RecordParamOrigin/ParamOrigin
pair, and per-value positions from FindEnumValues — the source side of
the spec↔source cross-ref linker (anchors a JSON pointer to a
token.Position). Opt-in: zero cost and byte-identical spec when no sink
is wired.
- EmitDiagnostic: the OnDiagnostic stream is now deduped scan-wide (same
position, code, message). The build re-processes the same field across
passes — most visibly a swagger:parameters struct applied to several
operation ids, which rebuilds every field once per id — so a field-level
diagnostic would otherwise surface once per visit. RecordDiagnostic
delivers through it; the raw Diagnostics() accumulator is unchanged.
- force module mode (GOWORK=off in NewScanCtx) so an ambient go.work —
including this repo's own monorepo workspace — can't switch ./... scans
to workspace mode and silently empty the produced spec.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Wire the builders to emit OnProvenance anchors tying each produced spec node to its Go source position. The base pointer is threaded via schema.WithPath using advance-on-descent: applyFieldCarrier advances to the property pointer, items/additionalProperties path-join their segment, and allOf members clear it so untracked subtrees resolve to their nearest anchored ancestor — keeping every emitted pointer geometrically correct. Anchors cover definitions, properties at every depth, responses, paths/operations (a new coarse ParsedPathContent.Pos), parameters (a deferred pass, since the op isn't path-bound at parameters-build time), enum values, and swagger:meta — plus finer keyword-line anchors: each scalar validation, meta and route keyword anchors to its own `// keyword:` comment line via grammar.PointerPath (so following e.g. a `maximum` or `default` node lands on the annotation, not the field). swagger:operation keywords stay at the coarse path anchor (YAML body, no per-keyword grammar Property). The geometry invariant test asserts every emitted pointer resolves in the rendered spec; opt-in, so the spec is byte-identical when provenance is off. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
The cross-ref provenance anchors emitted while building schemas,
parameters and responses must carry the JSON pointer of the spec node
the Go construct actually produces. Several sub-schema build sites
threaded the base path wrongly or not at all, so anchors landed at a
parent/sibling node (dangling) or were silently dropped. These only
surfaced visually in the TUI; the value-side builds that would expose
them ($ref/scalar) record nothing, so the geometry net never saw them.
Schema builder:
- pattern_properties: descend per-pair into patternProperties/<regex>
(was a shared additionalProperties segment); the regex key is RFC 6901
escaped so it round-trips against the raw map key.
- type_override: descend N items layers for `[]T` overrides so an inlined
named struct's properties anchor under .../items, not the parent.
- additionalProperties: descend the additionalProperties segment (marker
+ field keyword) and per-layer items; not the $ref-sibling path, whose
value lives in an untracked allOf member.
- add the shared descendItems(depth) helper.
Responses builder:
- anchor response headers at /responses/{name}/headers/{h}.
- thread a bodyPath cursor (/responses/{name}/schema) into the in:body
schema sub-builds, with descendBody for the array/map layers the
builder peels itself, so inline body properties anchor precisely.
Parameters builder: unchanged — resolution stops at /parameters/{i} by
design (the array index is only known after path binding).
Tests: exact-pointer assertions for the schema shapes, the regex-key
escaping, and the param/response anchor surface, each witness-validated;
geometry fixture list extended with the override / open-object / param
+ response fixtures.
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
packages.Load only surfaces the catastrophic error; degraded-but-loaded
results were accepted silently and produced an incomplete spec. The motivating
case (#2874): with type information unavailable, swagger:allOf quietly stopped
resolving and the scan emitted a degraded spec with no warning.
detectDegradedLoad inspects the pattern-matched root packages right after the
load and reacts by what is still recoverable:
- ABORT (Error diagnostic + returned error wrapping ErrDegradedLoad) when
nothing usable loaded: no packages matched the patterns; a package could
not be loaded at all (packages.ListError); or a package came back without
type information (Types/TypesInfo nil — the #2874 case).
- WARN and continue when a package carries only parse/type errors but its
type information is still usable. go/packages type-checks best-effort, so
its definitions remain scannable; a single non-building package must not
sink a whole ./... scan.
Only the root packages are inspected — transitive deps live in the import
graph and are not scanned, so dep noise does not trip the check (verified: the
full fixture corpus type-checks clean and the suite stays green).
Contributes to go-swagger/go-swagger#2874.
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A panic deep in a builder (e.g. the #2886 SIGSEGV in the responses builder) aborted Run with a raw Go stack trace and no indication of the offending source declaration. The spec builder now wraps each per-declaration build step (models, discovered schemas, parameters, responses, operations, routes) in a guard that recovers a panic, emits an Error-severity scan.internal-panic diagnostic naming the offending source (file:line + a human label: the qualified type, or "operation METHOD /path"), and returns an aborting error wrapping the new ErrInternalPanic sentinel. A coarse recover in Run backstops panics outside any decl loop (name reduction, the package walk), converting them into a clean error + diagnostic rather than a raw stack. A recovered panic aborts the scan (it is a bug, not a skippable condition); the located diagnostic and error are the loud, actionable signal. Contributes to go-swagger/go-swagger#2886. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
This was referenced Jun 17, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Change type
🔧 Bug fix'
Short description
Fixes most issues opened in go-swagger/go-swagger related to this library (e.g. swagger generate spec use case).
Fixes
Full description
Checklist
🐞 poison
🛠 fix-needed