File tree 3 files changed +19
-9
lines changed 3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -514,7 +514,7 @@ func ExampleReflector_SetRequest_queryObject() {
514
514
Quux float64 `query:"quux"`
515
515
Deeper struct {
516
516
Val string `query:"val"`
517
- } `json :"deeper"`
517
+ } `query :"deeper"`
518
518
}
519
519
520
520
type req struct {
@@ -559,12 +559,12 @@ func ExampleReflector_SetRequest_queryObject() {
559
559
// $ref: '#/components/schemas/QueryOpenapi3TestJsonFilter'
560
560
// in: query
561
561
// name: json_filter
562
- // - content:
563
- // application/json:
564
- // schema:
565
- // $ref: '#/components/schemas/QueryOpenapi3TestDeepObjectFilter'
562
+ // - explode: true
566
563
// in: query
567
564
// name: deep_object_filter
565
+ // schema:
566
+ // $ref: '#/components/schemas/QueryOpenapi3TestDeepObjectFilter'
567
+ // style: deepObject
568
568
// - in: path
569
569
// name: id
570
570
// required: true
@@ -578,9 +578,15 @@ func ExampleReflector_SetRequest_queryObject() {
578
578
// schemas:
579
579
// QueryOpenapi3TestDeepObjectFilter:
580
580
// properties:
581
+ // baz:
582
+ // type: boolean
581
583
// deeper:
582
- // nullable: true
584
+ // properties:
585
+ // val:
586
+ // type: string
583
587
// type: object
588
+ // quux:
589
+ // type: number
584
590
// type: object
585
591
// QueryOpenapi3TestJsonFilter:
586
592
// properties:
Original file line number Diff line number Diff line change @@ -309,7 +309,7 @@ func (r *Reflector) parseParametersIn(
309
309
310
310
// Check if parameter is an JSON encoded object.
311
311
property := reflect .New (field .Type ).Interface ()
312
- if refl .HasTaggedFields (property , tagJSON ) {
312
+ if refl .HasTaggedFields (property , tagJSON ) && ! refl . HasTaggedFields ( property , string ( in )) {
313
313
propertySchema , err := r .Reflect (property ,
314
314
r .withOperation (oc , false , string (in )),
315
315
jsonschema .DefinitionsPrefix (definitionsPrefix ),
Original file line number Diff line number Diff line change @@ -878,6 +878,8 @@ func TestReflector_SetupRequest_form_only(t *testing.T) {
878
878
func TestReflector_SetRequest_queryObject (t * testing.T ) {
879
879
reflector := openapi3.Reflector {}
880
880
881
+ // JSON object is only enabled when at least one `json` tag is available on top-level property,
882
+ // and there are no `in` tags, e.g. `query`.
881
883
type jsonFilter struct {
882
884
Foo string `json:"foo"`
883
885
Bar int `json:"bar"`
@@ -886,9 +888,11 @@ func TestReflector_SetRequest_queryObject(t *testing.T) {
886
888
} `json:"deeper"`
887
889
}
888
890
891
+ // Deep object structure may have `json` tags, they are ignored in presence of
892
+ // at least one top-level field with a matching `in` tag, e.g. `query`.
889
893
type deepObjectFilter struct {
890
- Baz bool `query:"baz"`
891
- Quux float64 `query:"quux"`
894
+ Baz bool `json:"baz" query:"baz"`
895
+ Quux float64 `json:"quux" query:"quux"`
892
896
Deeper struct {
893
897
Val string `query:"val"`
894
898
} `query:"deeper"`
You can’t perform that action at this time.
0 commit comments