fix: handle swagger:type array by falling through to underlying type resolution#11
Conversation
Add go.mod replace directive pointing go-openapi/codescan to ory-corp/codescan which includes the fix for swagger:type array producing incomplete schemas (missing items). Upstream PR: go-openapi/codescan#11 Upstream issue: go-openapi/codescan#10 This replace should be removed once the upstream PR is merged and a new go-swagger release includes it. Signed-off-by: Kevin Doan <kevin.doan@ory.sh>
1a7e648 to
ec3df12
Compare
Add go.mod replace directive pointing go-openapi/codescan to ory-corp/codescan which includes the fix for swagger:type array producing incomplete schemas (missing items). Upstream PR: go-openapi/codescan#11 Upstream issue: go-openapi/codescan#10 This replace should be removed once the upstream PR is merged and a new go-swagger release includes it. Signed-off-by: Kevin Doan <kevin.doan@ory.sh> Signed-off-by: KT-Doan <kevin.doan@ory.sh>
ec3df12 to
2e04a26
Compare
Add go.mod replace directive pointing go-openapi/codescan to ory-corp/codescan which includes the fix for swagger:type array producing incomplete schemas (missing items). Upstream PR: go-openapi/codescan#11 Upstream issue: go-openapi/codescan#10 This replace should be removed once the upstream PR is merged and a new go-swagger release includes it. Signed-off-by: Kevin Doan <kevin.doan@ory.sh> Signed-off-by: KT-Doan <kevin.doan@ory.sh>
2e04a26 to
57152d0
Compare
Add go.mod replace directive pointing go-openapi/codescan to ory-corp/codescan which includes the fix for swagger:type array producing incomplete schemas (missing items). Upstream PR: go-openapi/codescan#11 Upstream issue: go-openapi/codescan#10 This replace should be removed once the upstream PR is merged and a new go-swagger release includes it. Signed-off-by: Kevin Doan <kevin.doan@ory.sh> Signed-off-by: KT-Doan <kevin.doan@ory.sh>
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (26.66%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #11 +/- ##
==========================================
- Coverage 72.43% 72.34% -0.10%
==========================================
Files 14 14
Lines 3795 3804 +9
==========================================
+ Hits 2749 2752 +3
- Misses 734 738 +4
- Partials 312 314 +2 ☔ View full report in Codecov by Sentry. |
Ah I didn't add tests for the other three fixes, let me do that now. |
…resolution
When swagger:type is set to a value not handled by swaggerSchemaForType
(e.g., "array"), the function returns an error. Previously this error was
silently ignored and the function returned nil, losing all type info.
Now, when swaggerSchemaForType returns an error, the code falls through
to buildFromType with the underlying type, producing the correct schema.
For example, swagger:type array on type StringSlice []string now produces
{type: "array", items: {type: "string"}} with the field's description
preserved, instead of a $ref that drops the description.
* fixes go-openapi#10
Signed-off-by: Kevin Doan <kevin.doan@ory.sh>
Signed-off-by: KT-Doan <kevin.doan@ory.sh>
57152d0 to
0e87d63
Compare
|
@fredbi I added the remaining tests! please approve the workflow when you have the chance 🙇 |
|
Thanks. Really appreciate this fix. |
Problem
When
swagger:typeis set to a value not handled byswaggerSchemaForType(e.g.,array), the annotation is silently ignored in multiple code paths, producing incomplete or empty schemas.This affects three named-type builder functions:
buildFromType):swaggerSchemaForTypeerror was silently discarded with_ =, returningnilwith no type infobuildNamedSlice): noswagger:typecheck at all, always fell through tomakeRefcreating a$refeven when the type definition was suppressedbuildNamedArray): same as slicesbuildNamedStruct):swaggerSchemaForTypeerror was silently discarded with_ =Example
Before:
Tagsgets{"$ref": "#/definitions/StringSlice"}or an empty schema (description only, no type). TheStringSlicedefinition is suppressed becauseswagger:typeis present, so the$refpoints to nothing.After:
Tagsgets{"type": "array", "items": {"type": "string"}, "description": "..."}— correctly inlined with full type information and description preserved.Fix
When
swaggerSchemaForTypereturns an error for an unsupported type name:buildFromType: fall through tos.buildFromType(underlying)to resolve the actual Go typebuildNamedSlice: skipmakeRef, inline the slice by building from the element typebuildNamedArray: same approach as slicesbuildNamedStruct: fall through tomakeRefinstead of returning an empty schemaThis is backwards-compatible: supported type names (
string,bool,int64,object, etc.) continue to work as before. Only previously-broken unsupported values now produce correct schemas.Fixes #10