diff --git a/configuration-schema.json b/configuration-schema.json index 8f902ca708..9290cc121a 100644 --- a/configuration-schema.json +++ b/configuration-schema.json @@ -257,6 +257,10 @@ "type": "boolean", "description": "Disable the generation of a `ContentType()` method on response objects for `ClientWithResponses`, which is otherwise generated by default." }, + "skip-response-body-getters": { + "type": "boolean", + "description": "Disable the generation of `GetBody()` and `Get()` getter methods on response objects for `ClientWithResponses`, which are otherwise generated by default." + }, "prefer-skip-optional-pointer": { "type": "boolean", "description": "Allows defining at a global level whether to omit the pointer for a type to indicate that the field/type is optional. This is the same as adding `x-go-type-skip-optional-pointer` to each field (manually, or using an OpenAPI Overlay). A field can set `x-go-type-skip-optional-pointer: false` to still require the optional pointer.", diff --git a/examples/authenticated-api/echo/api/api.gen.go b/examples/authenticated-api/echo/api/api.gen.go index d9b8dffea2..e3c5d2591a 100644 --- a/examples/authenticated-api/echo/api/api.gen.go +++ b/examples/authenticated-api/echo/api/api.gen.go @@ -293,6 +293,16 @@ type ListThingsResponse struct { JSON200 *[]ThingWithID } +// GetJSON200 returns JSON200 +func (r ListThingsResponse) GetJSON200() *[]ThingWithID { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r ListThingsResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r ListThingsResponse) Status() string { if r.HTTPResponse != nil { @@ -323,6 +333,16 @@ type AddThingResponse struct { JSON201 *[]ThingWithID } +// GetJSON201 returns JSON201 +func (r AddThingResponse) GetJSON201() *[]ThingWithID { + return r.JSON201 +} + +// GetBody returns the raw response body bytes (Body) +func (r AddThingResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r AddThingResponse) Status() string { if r.HTTPResponse != nil { diff --git a/examples/authenticated-api/stdhttp/api/api.gen.go b/examples/authenticated-api/stdhttp/api/api.gen.go index 97f16b2ff2..979cd32020 100644 --- a/examples/authenticated-api/stdhttp/api/api.gen.go +++ b/examples/authenticated-api/stdhttp/api/api.gen.go @@ -294,6 +294,16 @@ type ListThingsResponse struct { JSON200 *[]ThingWithID } +// GetJSON200 returns JSON200 +func (r ListThingsResponse) GetJSON200() *[]ThingWithID { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r ListThingsResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r ListThingsResponse) Status() string { if r.HTTPResponse != nil { @@ -324,6 +334,16 @@ type AddThingResponse struct { JSON201 *[]ThingWithID } +// GetJSON201 returns JSON201 +func (r AddThingResponse) GetJSON201() *[]ThingWithID { + return r.JSON201 +} + +// GetBody returns the raw response body bytes (Body) +func (r AddThingResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r AddThingResponse) Status() string { if r.HTTPResponse != nil { diff --git a/examples/client/client.gen.go b/examples/client/client.gen.go index 786d8c0b10..430496de89 100644 --- a/examples/client/client.gen.go +++ b/examples/client/client.gen.go @@ -232,6 +232,16 @@ type GetClientResponse struct { JSON200 *ClientType } +// GetJSON200 returns JSON200 +func (r GetClientResponse) GetJSON200() *ClientType { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetClientResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetClientResponse) Status() string { if r.HTTPResponse != nil { @@ -264,6 +274,18 @@ type UpdateClientResponse struct { } } +// GetJSON400 returns JSON400 +func (r UpdateClientResponse) GetJSON400() *struct { + Code string `json:"code"` +} { + return r.JSON400 +} + +// GetBody returns the raw response body bytes (Body) +func (r UpdateClientResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r UpdateClientResponse) Status() string { if r.HTTPResponse != nil { diff --git a/examples/clienttypenameclash/client.gen.go b/examples/clienttypenameclash/client.gen.go index 4ed74d1777..99ab3e36a2 100644 --- a/examples/clienttypenameclash/client.gen.go +++ b/examples/clienttypenameclash/client.gen.go @@ -187,6 +187,16 @@ type UpdateClientResp struct { JSON400 *UpdateClientResponse } +// GetJSON400 returns JSON400 +func (r UpdateClientResp) GetJSON400() *UpdateClientResponse { + return r.JSON400 +} + +// GetBody returns the raw response body bytes (Body) +func (r UpdateClientResp) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r UpdateClientResp) Status() string { if r.HTTPResponse != nil { diff --git a/examples/custom-client-type/custom-client-type.gen.go b/examples/custom-client-type/custom-client-type.gen.go index 27f63d8185..adbb290453 100644 --- a/examples/custom-client-type/custom-client-type.gen.go +++ b/examples/custom-client-type/custom-client-type.gen.go @@ -187,6 +187,16 @@ type GetClientResponse struct { JSON200 *Client } +// GetJSON200 returns JSON200 +func (r GetClientResponse) GetJSON200() *Client { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetClientResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetClientResponse) Status() string { if r.HTTPResponse != nil { diff --git a/examples/petstore-expanded/petstore-client.gen.go b/examples/petstore-expanded/petstore-client.gen.go index 5b5d01d78b..0b77852791 100644 --- a/examples/petstore-expanded/petstore-client.gen.go +++ b/examples/petstore-expanded/petstore-client.gen.go @@ -445,6 +445,21 @@ type FindPetsResponse struct { JSONDefault *Error } +// GetJSON200 returns JSON200 +func (r FindPetsResponse) GetJSON200() *[]Pet { + return r.JSON200 +} + +// GetJSONDefault returns JSONDefault +func (r FindPetsResponse) GetJSONDefault() *Error { + return r.JSONDefault +} + +// GetBody returns the raw response body bytes (Body) +func (r FindPetsResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r FindPetsResponse) Status() string { if r.HTTPResponse != nil { @@ -476,6 +491,21 @@ type AddPetResponse struct { JSONDefault *Error } +// GetJSON200 returns JSON200 +func (r AddPetResponse) GetJSON200() *Pet { + return r.JSON200 +} + +// GetJSONDefault returns JSONDefault +func (r AddPetResponse) GetJSONDefault() *Error { + return r.JSONDefault +} + +// GetBody returns the raw response body bytes (Body) +func (r AddPetResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r AddPetResponse) Status() string { if r.HTTPResponse != nil { @@ -506,6 +536,16 @@ type DeletePetResponse struct { JSONDefault *Error } +// GetJSONDefault returns JSONDefault +func (r DeletePetResponse) GetJSONDefault() *Error { + return r.JSONDefault +} + +// GetBody returns the raw response body bytes (Body) +func (r DeletePetResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r DeletePetResponse) Status() string { if r.HTTPResponse != nil { @@ -537,6 +577,21 @@ type FindPetByIDResponse struct { JSONDefault *Error } +// GetJSON200 returns JSON200 +func (r FindPetByIDResponse) GetJSON200() *Pet { + return r.JSON200 +} + +// GetJSONDefault returns JSONDefault +func (r FindPetByIDResponse) GetJSONDefault() *Error { + return r.JSONDefault +} + +// GetBody returns the raw response body bytes (Body) +func (r FindPetByIDResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r FindPetByIDResponse) Status() string { if r.HTTPResponse != nil { diff --git a/examples/streaming/client/sse/streaming.gen.go b/examples/streaming/client/sse/streaming.gen.go index d20b2063e3..31b195d7e2 100644 --- a/examples/streaming/client/sse/streaming.gen.go +++ b/examples/streaming/client/sse/streaming.gen.go @@ -180,6 +180,11 @@ type GetStreamResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetStreamResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetStreamResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/anonymous_inner_hoisting/client.gen.go b/internal/test/anonymous_inner_hoisting/client.gen.go index 74fe6907c2..f022093572 100644 --- a/internal/test/anonymous_inner_hoisting/client.gen.go +++ b/internal/test/anonymous_inner_hoisting/client.gen.go @@ -928,6 +928,11 @@ type PostBodyPropertyOneOfResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostBodyPropertyOneOfResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostBodyPropertyOneOfResponse) Status() string { if r.HTTPResponse != nil { @@ -957,6 +962,11 @@ type PostBodyRootOneOfResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostBodyRootOneOfResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostBodyRootOneOfResponse) Status() string { if r.HTTPResponse != nil { @@ -991,6 +1001,20 @@ type GetResponseDeepNestedResponse struct { } } +// GetJSON200 returns JSON200 +func (r GetResponseDeepNestedResponse) GetJSON200() *struct { + Wrapper *struct { + Inner *GetResponseDeepNested200JSONResponseBody_Wrapper_Inner `json:"inner,omitempty"` + } `json:"wrapper,omitempty"` +} { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetResponseDeepNestedResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetResponseDeepNestedResponse) Status() string { if r.HTTPResponse != nil { @@ -1023,6 +1047,18 @@ type GetResponseItemsOneOfResponse struct { } } +// GetJSON200 returns JSON200 +func (r GetResponseItemsOneOfResponse) GetJSON200() *struct { + Items []GetResponseItemsOneOf200JSONResponseBody_Items_Item `json:"items"` +} { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetResponseItemsOneOfResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetResponseItemsOneOfResponse) Status() string { if r.HTTPResponse != nil { @@ -1053,6 +1089,16 @@ type GetResponseRootAnyOfResponse struct { JSON200 *GetResponseRootAnyOf200JSONResponseBody } +// GetJSON200 returns JSON200 +func (r GetResponseRootAnyOfResponse) GetJSON200() *GetResponseRootAnyOf200JSONResponseBody { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetResponseRootAnyOfResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetResponseRootAnyOfResponse) Status() string { if r.HTTPResponse != nil { @@ -1083,6 +1129,16 @@ type GetResponseRootOneOfResponse struct { JSON200 *GetResponseRootOneOf200JSONResponseBody } +// GetJSON200 returns JSON200 +func (r GetResponseRootOneOfResponse) GetJSON200() *GetResponseRootOneOf200JSONResponseBody { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetResponseRootOneOfResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetResponseRootOneOfResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/any_of/codegen/inline/openapi.gen.go b/internal/test/any_of/codegen/inline/openapi.gen.go index c9eeb406b3..e1bb5cfbd7 100644 --- a/internal/test/any_of/codegen/inline/openapi.gen.go +++ b/internal/test/any_of/codegen/inline/openapi.gen.go @@ -313,6 +313,18 @@ type GetPetsResponse struct { } } +// GetJSON200 returns JSON200 +func (r GetPetsResponse) GetJSON200() *struct { + Data *[]GetPets200JSONResponseBody_Data_Item `json:"data,omitempty"` +} { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetPetsResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetPetsResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/any_of/codegen/ref_schema/openapi.gen.go b/internal/test/any_of/codegen/ref_schema/openapi.gen.go index f8dcee8ce4..c69077123e 100644 --- a/internal/test/any_of/codegen/ref_schema/openapi.gen.go +++ b/internal/test/any_of/codegen/ref_schema/openapi.gen.go @@ -316,6 +316,16 @@ type GetPetsResponse struct { JSON200 *GetPetsDto } +// GetJSON200 returns JSON200 +func (r GetPetsResponse) GetJSON200() *GetPetsDto { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetPetsResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetPetsResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/any_of/param/param.gen.go b/internal/test/any_of/param/param.gen.go index 694d466b9d..69e50dd32e 100644 --- a/internal/test/any_of/param/param.gen.go +++ b/internal/test/any_of/param/param.gen.go @@ -380,6 +380,11 @@ type GetTestResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetTestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetTestResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/client/client.gen.go b/internal/test/client/client.gen.go index 7a26ea68a2..aa6d0a4c7d 100644 --- a/internal/test/client/client.gen.go +++ b/internal/test/client/client.gen.go @@ -611,6 +611,11 @@ type PostBothResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostBothResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostBothResponse) Status() string { if r.HTTPResponse != nil { @@ -640,6 +645,11 @@ type GetBothResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetBothResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetBothResponse) Status() string { if r.HTTPResponse != nil { @@ -669,6 +679,11 @@ type PostJsonResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostJsonResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostJsonResponse) Status() string { if r.HTTPResponse != nil { @@ -698,6 +713,11 @@ type GetJsonResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetJsonResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetJsonResponse) Status() string { if r.HTTPResponse != nil { @@ -727,6 +747,11 @@ type PostOtherResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostOtherResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostOtherResponse) Status() string { if r.HTTPResponse != nil { @@ -756,6 +781,11 @@ type GetOtherResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetOtherResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetOtherResponse) Status() string { if r.HTTPResponse != nil { @@ -785,6 +815,11 @@ type GetJsonWithTrailingSlashResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetJsonWithTrailingSlashResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetJsonWithTrailingSlashResponse) Status() string { if r.HTTPResponse != nil { @@ -814,6 +849,11 @@ type PostVendorJsonResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostVendorJsonResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostVendorJsonResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/extensions/param-ref-sibling-omitempty/issue.gen.go b/internal/test/extensions/param-ref-sibling-omitempty/issue.gen.go index 1cc7a983d3..3ee44a323d 100644 --- a/internal/test/extensions/param-ref-sibling-omitempty/issue.gen.go +++ b/internal/test/extensions/param-ref-sibling-omitempty/issue.gen.go @@ -217,6 +217,11 @@ type ListThingsResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r ListThingsResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r ListThingsResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1039/client.gen.go b/internal/test/issues/issue-1039/client.gen.go index 63ef866784..9e9696094e 100644 --- a/internal/test/issues/issue-1039/client.gen.go +++ b/internal/test/issues/issue-1039/client.gen.go @@ -211,6 +211,11 @@ type ExamplePatchResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r ExamplePatchResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r ExamplePatchResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1087/api.gen.go b/internal/test/issues/issue-1087/api.gen.go index dcbcca53ea..527ceb2e45 100644 --- a/internal/test/issues/issue-1087/api.gen.go +++ b/internal/test/issues/issue-1087/api.gen.go @@ -209,6 +209,36 @@ type GetThingsResponse struct { JSON500 *externalRef0.DefaultError } +// GetJSON200 returns JSON200 +func (r GetThingsResponse) GetJSON200() *ThingResponse { + return r.JSON200 +} + +// GetJSON401 returns JSON401 +func (r GetThingsResponse) GetJSON401() *externalRef0.N401 { + return r.JSON401 +} + +// GetJSON403 returns JSON403 +func (r GetThingsResponse) GetJSON403() *externalRef0.N403 { + return r.JSON403 +} + +// GetJSON404 returns JSON404 +func (r GetThingsResponse) GetJSON404() *N404 { + return r.JSON404 +} + +// GetJSON500 returns JSON500 +func (r GetThingsResponse) GetJSON500() *externalRef0.DefaultError { + return r.JSON500 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetThingsResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetThingsResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1180/issue.gen.go b/internal/test/issues/issue-1180/issue.gen.go index 4f11b798d5..11fe0948f7 100644 --- a/internal/test/issues/issue-1180/issue.gen.go +++ b/internal/test/issues/issue-1180/issue.gen.go @@ -195,6 +195,11 @@ type GetSimplePrimitiveResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetSimplePrimitiveResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetSimplePrimitiveResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1182/pkg1/pkg1.gen.go b/internal/test/issues/issue-1182/pkg1/pkg1.gen.go index e548f06834..e02ca358c2 100644 --- a/internal/test/issues/issue-1182/pkg1/pkg1.gen.go +++ b/internal/test/issues/issue-1182/pkg1/pkg1.gen.go @@ -188,6 +188,11 @@ type TestGetResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r TestGetResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r TestGetResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1189/issue1189.gen.go b/internal/test/issues/issue-1189/issue1189.gen.go index 45bd54e759..0296cf0d90 100644 --- a/internal/test/issues/issue-1189/issue1189.gen.go +++ b/internal/test/issues/issue-1189/issue1189.gen.go @@ -400,6 +400,16 @@ type TestResponse struct { JSON200 *Test } +// GetJSON200 returns JSON200 +func (r TestResponse) GetJSON200() *Test { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r TestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r TestResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1208-1209/issue-multi-json.gen.go b/internal/test/issues/issue-1208-1209/issue-multi-json.gen.go index cb42ffded3..cbd99a6ec8 100644 --- a/internal/test/issues/issue-1208-1209/issue-multi-json.gen.go +++ b/internal/test/issues/issue-1208-1209/issue-multi-json.gen.go @@ -208,6 +208,31 @@ type TestResponse struct { ApplicationfooJSON201 *BazApplicationFooPlusJSON } +// GetApplicationbarJSON200 returns ApplicationbarJSON200 +func (r TestResponse) GetApplicationbarJSON200() *Bar { + return r.ApplicationbarJSON200 +} + +// GetApplicationfooJSON200 returns ApplicationfooJSON200 +func (r TestResponse) GetApplicationfooJSON200() *Foo { + return r.ApplicationfooJSON200 +} + +// GetApplicationbarJSON201 returns ApplicationbarJSON201 +func (r TestResponse) GetApplicationbarJSON201() *BazApplicationBarPlusJSON { + return r.ApplicationbarJSON201 +} + +// GetApplicationfooJSON201 returns ApplicationfooJSON201 +func (r TestResponse) GetApplicationfooJSON201() *BazApplicationFooPlusJSON { + return r.ApplicationfooJSON201 +} + +// GetBody returns the raw response body bytes (Body) +func (r TestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r TestResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1212/pkg1/pkg1.gen.go b/internal/test/issues/issue-1212/pkg1/pkg1.gen.go index 34e300a96c..23d6c7db96 100644 --- a/internal/test/issues/issue-1212/pkg1/pkg1.gen.go +++ b/internal/test/issues/issue-1212/pkg1/pkg1.gen.go @@ -190,6 +190,11 @@ type TestResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r TestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r TestResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1277/content-array.gen.go b/internal/test/issues/issue-1277/content-array.gen.go index 4e13565987..e2e7846119 100644 --- a/internal/test/issues/issue-1277/content-array.gen.go +++ b/internal/test/issues/issue-1277/content-array.gen.go @@ -275,6 +275,16 @@ type TestResponse struct { JSON200 *[]Test200JSONResponseBody_Item } +// GetJSON200 returns JSON200 +func (r TestResponse) GetJSON200() *[]Test200JSONResponseBody_Item { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r TestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r TestResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1298/issue1298.gen.go b/internal/test/issues/issue-1298/issue1298.gen.go index 3d79747d26..a3229d9c86 100644 --- a/internal/test/issues/issue-1298/issue1298.gen.go +++ b/internal/test/issues/issue-1298/issue1298.gen.go @@ -223,6 +223,11 @@ type TestResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r TestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r TestResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1397/issue1397.gen.go b/internal/test/issues/issue-1397/issue1397.gen.go index c4330e0475..4ff816ae40 100644 --- a/internal/test/issues/issue-1397/issue1397.gen.go +++ b/internal/test/issues/issue-1397/issue1397.gen.go @@ -265,6 +265,11 @@ type TestResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r TestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r TestResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1529/strict-echo/issue1529.gen.go b/internal/test/issues/issue-1529/strict-echo/issue1529.gen.go index e85c0b1bf2..349d34a553 100644 --- a/internal/test/issues/issue-1529/strict-echo/issue1529.gen.go +++ b/internal/test/issues/issue-1529/strict-echo/issue1529.gen.go @@ -194,6 +194,26 @@ type TestResponse struct { ApplicationjsonProfileFoo200 *Test } +// GetJSON200 returns JSON200 +func (r TestResponse) GetJSON200() *Test { + return r.JSON200 +} + +// GetApplicationjsonProfileBar200 returns ApplicationjsonProfileBar200 +func (r TestResponse) GetApplicationjsonProfileBar200() *Test { + return r.ApplicationjsonProfileBar200 +} + +// GetApplicationjsonProfileFoo200 returns ApplicationjsonProfileFoo200 +func (r TestResponse) GetApplicationjsonProfileFoo200() *Test { + return r.ApplicationjsonProfileFoo200 +} + +// GetBody returns the raw response body bytes (Body) +func (r TestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r TestResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1529/strict-fiber/issue1529.gen.go b/internal/test/issues/issue-1529/strict-fiber/issue1529.gen.go index 5a9b77e70a..81bb0fad22 100644 --- a/internal/test/issues/issue-1529/strict-fiber/issue1529.gen.go +++ b/internal/test/issues/issue-1529/strict-fiber/issue1529.gen.go @@ -194,6 +194,26 @@ type TestResponse struct { ApplicationjsonProfileFoo200 *Test } +// GetJSON200 returns JSON200 +func (r TestResponse) GetJSON200() *Test { + return r.JSON200 +} + +// GetApplicationjsonProfileBar200 returns ApplicationjsonProfileBar200 +func (r TestResponse) GetApplicationjsonProfileBar200() *Test { + return r.ApplicationjsonProfileBar200 +} + +// GetApplicationjsonProfileFoo200 returns ApplicationjsonProfileFoo200 +func (r TestResponse) GetApplicationjsonProfileFoo200() *Test { + return r.ApplicationjsonProfileFoo200 +} + +// GetBody returns the raw response body bytes (Body) +func (r TestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r TestResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1529/strict-iris/issue1529.gen.go b/internal/test/issues/issue-1529/strict-iris/issue1529.gen.go index e630e0fe63..69478c9163 100644 --- a/internal/test/issues/issue-1529/strict-iris/issue1529.gen.go +++ b/internal/test/issues/issue-1529/strict-iris/issue1529.gen.go @@ -194,6 +194,26 @@ type TestResponse struct { ApplicationjsonProfileFoo200 *Test } +// GetJSON200 returns JSON200 +func (r TestResponse) GetJSON200() *Test { + return r.JSON200 +} + +// GetApplicationjsonProfileBar200 returns ApplicationjsonProfileBar200 +func (r TestResponse) GetApplicationjsonProfileBar200() *Test { + return r.ApplicationjsonProfileBar200 +} + +// GetApplicationjsonProfileFoo200 returns ApplicationjsonProfileFoo200 +func (r TestResponse) GetApplicationjsonProfileFoo200() *Test { + return r.ApplicationjsonProfileFoo200 +} + +// GetBody returns the raw response body bytes (Body) +func (r TestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r TestResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-1914/client.gen.go b/internal/test/issues/issue-1914/client.gen.go index 7af86aac02..4417fe5a8d 100644 --- a/internal/test/issues/issue-1914/client.gen.go +++ b/internal/test/issues/issue-1914/client.gen.go @@ -297,6 +297,11 @@ type PostPetResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostPetResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostPetResponse) Status() string { if r.HTTPResponse != nil { @@ -326,6 +331,11 @@ type PostPet1234Response struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostPet1234Response) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostPet1234Response) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-2031/prefer/issue2031.gen.go b/internal/test/issues/issue-2031/prefer/issue2031.gen.go index 936ac9f762..e37c69d6a1 100644 --- a/internal/test/issues/issue-2031/prefer/issue2031.gen.go +++ b/internal/test/issues/issue-2031/prefer/issue2031.gen.go @@ -214,6 +214,11 @@ type GetTestResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetTestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetTestResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-2190/issue2190.gen.go b/internal/test/issues/issue-2190/issue2190.gen.go index db31e6c1c3..cddf869b5d 100644 --- a/internal/test/issues/issue-2190/issue2190.gen.go +++ b/internal/test/issues/issue-2190/issue2190.gen.go @@ -188,6 +188,16 @@ type GetTestResponse struct { JSON200 *Success } +// GetJSON200 returns JSON200 +func (r GetTestResponse) GetJSON200() *Success { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetTestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetTestResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-2238/issue2238.gen.go b/internal/test/issues/issue-2238/issue2238.gen.go index 16e923002c..11d329f7d4 100644 --- a/internal/test/issues/issue-2238/issue2238.gen.go +++ b/internal/test/issues/issue-2238/issue2238.gen.go @@ -220,6 +220,11 @@ type GetTestResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetTestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetTestResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-2329/issue2329.gen.go b/internal/test/issues/issue-2329/issue2329.gen.go index 06e9baa719..0248c2fd11 100644 --- a/internal/test/issues/issue-2329/issue2329.gen.go +++ b/internal/test/issues/issue-2329/issue2329.gen.go @@ -396,6 +396,11 @@ type ListThingsResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r ListThingsResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r ListThingsResponse) Status() string { if r.HTTPResponse != nil { @@ -425,6 +430,11 @@ type CreateThingResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r CreateThingResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r CreateThingResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-312/issue.gen.go b/internal/test/issues/issue-312/issue.gen.go index 71fa081088..25763f9374 100644 --- a/internal/test/issues/issue-312/issue.gen.go +++ b/internal/test/issues/issue-312/issue.gen.go @@ -295,6 +295,16 @@ type GetPetResponse struct { JSON200 *Pet } +// GetJSON200 returns JSON200 +func (r GetPetResponse) GetJSON200() *Pet { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetPetResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetPetResponse) Status() string { if r.HTTPResponse != nil { @@ -326,6 +336,21 @@ type ValidatePetsResponse struct { JSONDefault *Error } +// GetJSON200 returns JSON200 +func (r ValidatePetsResponse) GetJSON200() *[]Pet { + return r.JSON200 +} + +// GetJSONDefault returns JSONDefault +func (r ValidatePetsResponse) GetJSONDefault() *Error { + return r.JSONDefault +} + +// GetBody returns the raw response body bytes (Body) +func (r ValidatePetsResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r ValidatePetsResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-52/issue.gen.go b/internal/test/issues/issue-52/issue.gen.go index 9fb77c6726..5e0a502a4c 100644 --- a/internal/test/issues/issue-52/issue.gen.go +++ b/internal/test/issues/issue-52/issue.gen.go @@ -203,6 +203,16 @@ type ExampleGetResponse struct { JSON200 *Document } +// GetJSON200 returns JSON200 +func (r ExampleGetResponse) GetJSON200() *Document { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r ExampleGetResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r ExampleGetResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-grab_import_names/issue.gen.go b/internal/test/issues/issue-grab_import_names/issue.gen.go index 480b01aca8..08e66b4fcb 100644 --- a/internal/test/issues/issue-grab_import_names/issue.gen.go +++ b/internal/test/issues/issue-grab_import_names/issue.gen.go @@ -225,6 +225,16 @@ type GetFooResponse struct { JSON200 *string } +// GetJSON200 returns JSON200 +func (r GetFooResponse) GetJSON200() *string { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetFooResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetFooResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue-illegal_enum_names/issue.gen.go b/internal/test/issues/issue-illegal_enum_names/issue.gen.go index e5f45d16b1..09859b13cd 100644 --- a/internal/test/issues/issue-illegal_enum_names/issue.gen.go +++ b/internal/test/issues/issue-illegal_enum_names/issue.gen.go @@ -234,6 +234,16 @@ type GetFooResponse struct { JSON200 *[]Bar } +// GetJSON200 returns JSON200 +func (r GetFooResponse) GetJSON200() *[]Bar { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetFooResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetFooResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue1799/client/out.gen.go b/internal/test/issues/issue1799/client/out.gen.go index 4e70c70ddb..3ad144a2c5 100644 --- a/internal/test/issues/issue1799/client/out.gen.go +++ b/internal/test/issues/issue1799/client/out.gen.go @@ -422,6 +422,21 @@ type GetGetMultibodyResponse struct { ApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams2200 *string } +// GetApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams200 returns ApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams200 +func (r GetGetMultibodyResponse) GetApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams200() *string { + return r.ApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams200 +} + +// GetApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams2200 returns ApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams2200 +func (r GetGetMultibodyResponse) GetApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams2200() *string { + return r.ApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams2200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetGetMultibodyResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetGetMultibodyResponse) Status() string { if r.HTTPResponse != nil { @@ -452,6 +467,16 @@ type GetObjectResponse struct { ApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams200 *string } +// GetApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams200 returns ApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams200 +func (r GetObjectResponse) GetApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams200() *string { + return r.ApplicationldJSONProfilehttpswwwW3Orgnsactivitystreams200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetObjectResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetObjectResponse) Status() string { if r.HTTPResponse != nil { @@ -481,6 +506,11 @@ type PostPostMultibodyResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostPostMultibodyResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostPostMultibodyResponse) Status() string { if r.HTTPResponse != nil { @@ -510,6 +540,11 @@ type PostPostObjectResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostPostObjectResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostPostObjectResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/issues/issue240/client.gen.go b/internal/test/issues/issue240/client.gen.go index 2ce39f4154..cf1055c485 100644 --- a/internal/test/issues/issue240/client.gen.go +++ b/internal/test/issues/issue240/client.gen.go @@ -232,6 +232,16 @@ type GetClientResponse struct { JSON200 *ClientType } +// GetJSON200 returns JSON200 +func (r GetClientResponse) GetJSON200() *ClientType { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetClientResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetClientResponse) Status() string { if r.HTTPResponse != nil { @@ -269,6 +279,18 @@ type UpdateClientResponse struct { } } +// GetJSON400 returns JSON400 +func (r UpdateClientResponse) GetJSON400() *struct { + Code string `json:"code"` +} { + return r.JSON400 +} + +// GetBody returns the raw response body bytes (Body) +func (r UpdateClientResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r UpdateClientResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/name_conflict_resolution/name_conflict_resolution.gen.go b/internal/test/name_conflict_resolution/name_conflict_resolution.gen.go index b97ae67fa3..1408a086d7 100644 --- a/internal/test/name_conflict_resolution/name_conflict_resolution.gen.go +++ b/internal/test/name_conflict_resolution/name_conflict_resolution.gen.go @@ -1889,6 +1889,19 @@ type ListEntitiesResponse struct { } } +// GetJSON200 returns JSON200 +func (r ListEntitiesResponse) GetJSON200() *struct { + Data *[]Widget `json:"data,omitempty"` + Metadata *Metadata `json:"metadata,omitempty"` +} { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r ListEntitiesResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r ListEntitiesResponse) Status() string { if r.HTTPResponse != nil { @@ -1919,6 +1932,16 @@ type PostFooResponse struct { JSON200 *BarResponse } +// GetJSON200 returns JSON200 +func (r PostFooResponse) GetJSON200() *BarResponse { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r PostFooResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostFooResponse) Status() string { if r.HTTPResponse != nil { @@ -1949,6 +1972,16 @@ type ListItemsResponse2 struct { JSON200 *ListItemsResponse } +// GetJSON200 returns JSON200 +func (r ListItemsResponse2) GetJSON200() *ListItemsResponse { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r ListItemsResponse2) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r ListItemsResponse2) Status() string { if r.HTTPResponse != nil { @@ -1979,6 +2012,16 @@ type CreateItemResponse2 struct { JSON200 *CreateItemResponse } +// GetJSON200 returns JSON200 +func (r CreateItemResponse2) GetJSON200() *CreateItemResponse { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r CreateItemResponse2) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r CreateItemResponse2) Status() string { if r.HTTPResponse != nil { @@ -2009,6 +2052,16 @@ type CreateOrderResponse struct { JSON200 *Order } +// GetJSON200 returns JSON200 +func (r CreateOrderResponse) GetJSON200() *Order { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r CreateOrderResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r CreateOrderResponse) Status() string { if r.HTTPResponse != nil { @@ -2039,6 +2092,16 @@ type GetOutcomeResponse struct { JSON200 *OutcomeResult } +// GetJSON200 returns JSON200 +func (r GetOutcomeResponse) GetJSON200() *OutcomeResult { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetOutcomeResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetOutcomeResponse) Status() string { if r.HTTPResponse != nil { @@ -2068,6 +2131,11 @@ type PostOutcomeResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostOutcomeResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostOutcomeResponse) Status() string { if r.HTTPResponse != nil { @@ -2098,6 +2166,16 @@ type SendPayloadResponse struct { JSON200 *Payload } +// GetJSON200 returns JSON200 +func (r SendPayloadResponse) GetJSON200() *Payload { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r SendPayloadResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r SendPayloadResponse) Status() string { if r.HTTPResponse != nil { @@ -2128,6 +2206,16 @@ type CreatePetResponse struct { JSON200 *Pet } +// GetJSON200 returns JSON200 +func (r CreatePetResponse) GetJSON200() *Pet { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r CreatePetResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r CreatePetResponse) Status() string { if r.HTTPResponse != nil { @@ -2158,6 +2246,16 @@ type QueryResponse2 struct { JSON200 *QueryResponse } +// GetJSON200 returns JSON200 +func (r QueryResponse2) GetJSON200() *QueryResponse { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r QueryResponse2) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r QueryResponse2) Status() string { if r.HTTPResponse != nil { @@ -2188,6 +2286,16 @@ type GetQuxResponse struct { JSON200 *QuxResponse } +// GetJSON200 returns JSON200 +func (r GetQuxResponse) GetJSON200() *QuxResponse { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetQuxResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetQuxResponse) Status() string { if r.HTTPResponse != nil { @@ -2217,6 +2325,11 @@ type PostQuxResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostQuxResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostQuxResponse) Status() string { if r.HTTPResponse != nil { @@ -2247,6 +2360,16 @@ type GetRenamedSchemaResponse struct { JSON200 *Renamer } +// GetJSON200 returns JSON200 +func (r GetRenamedSchemaResponse) GetJSON200() *Renamer { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetRenamedSchemaResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetRenamedSchemaResponse) Status() string { if r.HTTPResponse != nil { @@ -2276,6 +2399,11 @@ type PostRenamedSchemaResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostRenamedSchemaResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostRenamedSchemaResponse) Status() string { if r.HTTPResponse != nil { @@ -2309,6 +2437,31 @@ type PatchResourceResponse struct { ApplicationmergePatchJSON200 *N200ResourcePatchResponseJSON4ApplicationMergePatchPlusJSON } +// GetJSON200 returns JSON200 +func (r PatchResourceResponse) GetJSON200() *N200ResourcePatchResponseJSONApplicationJSON { + return r.JSON200 +} + +// GetApplicationjsonPatchJSON200 returns ApplicationjsonPatchJSON200 +func (r PatchResourceResponse) GetApplicationjsonPatchJSON200() *N200ResourcePatchResponseJSON2ApplicationJSONPatchPlusJSON { + return r.ApplicationjsonPatchJSON200 +} + +// GetApplicationjsonPatchQueryJSON200 returns ApplicationjsonPatchQueryJSON200 +func (r PatchResourceResponse) GetApplicationjsonPatchQueryJSON200() *N200ResourcePatchResponseJSON3ApplicationJSONPatchQueryPlusJSON { + return r.ApplicationjsonPatchQueryJSON200 +} + +// GetApplicationmergePatchJSON200 returns ApplicationmergePatchJSON200 +func (r PatchResourceResponse) GetApplicationmergePatchJSON200() *N200ResourcePatchResponseJSON4ApplicationMergePatchPlusJSON { + return r.ApplicationmergePatchJSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r PatchResourceResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PatchResourceResponse) Status() string { if r.HTTPResponse != nil { @@ -2339,6 +2492,16 @@ type GetStatusResponse2 struct { JSON200 *GetStatusResponse } +// GetJSON200 returns JSON200 +func (r GetStatusResponse2) GetJSON200() *GetStatusResponse { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetStatusResponse2) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetStatusResponse2) Status() string { if r.HTTPResponse != nil { @@ -2369,6 +2532,16 @@ type GetZapResponse struct { JSON200 *ZapResponse } +// GetJSON200 returns JSON200 +func (r GetZapResponse) GetJSON200() *ZapResponse { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetZapResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetZapResponse) Status() string { if r.HTTPResponse != nil { @@ -2398,6 +2571,11 @@ type PostZapResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r PostZapResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r PostZapResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/outputoptions/name-normalizer/to-camel-case-with-additional-initialisms/name_normalizer.gen.go b/internal/test/outputoptions/name-normalizer/to-camel-case-with-additional-initialisms/name_normalizer.gen.go index 5e5d1f4d81..8796ba4b3a 100644 --- a/internal/test/outputoptions/name-normalizer/to-camel-case-with-additional-initialisms/name_normalizer.gen.go +++ b/internal/test/outputoptions/name-normalizer/to-camel-case-with-additional-initialisms/name_normalizer.gen.go @@ -293,6 +293,16 @@ type GetHTTPPetResponse struct { JSON200 *Pet } +// GetJSON200 returns JSON200 +func (r GetHTTPPetResponse) GetJSON200() *Pet { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetHTTPPetResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetHTTPPetResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/outputoptions/name-normalizer/to-camel-case-with-digits/name_normalizer.gen.go b/internal/test/outputoptions/name-normalizer/to-camel-case-with-digits/name_normalizer.gen.go index ee65dae6ac..071a7a7386 100644 --- a/internal/test/outputoptions/name-normalizer/to-camel-case-with-digits/name_normalizer.gen.go +++ b/internal/test/outputoptions/name-normalizer/to-camel-case-with-digits/name_normalizer.gen.go @@ -293,6 +293,16 @@ type GetHttpPetResponse struct { JSON200 *Pet } +// GetJSON200 returns JSON200 +func (r GetHttpPetResponse) GetJSON200() *Pet { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetHttpPetResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetHttpPetResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/outputoptions/name-normalizer/to-camel-case-with-initialisms/name_normalizer.gen.go b/internal/test/outputoptions/name-normalizer/to-camel-case-with-initialisms/name_normalizer.gen.go index 6d924715f5..5ed20a5756 100644 --- a/internal/test/outputoptions/name-normalizer/to-camel-case-with-initialisms/name_normalizer.gen.go +++ b/internal/test/outputoptions/name-normalizer/to-camel-case-with-initialisms/name_normalizer.gen.go @@ -293,6 +293,16 @@ type GetHTTPPetResponse struct { JSON200 *Pet } +// GetJSON200 returns JSON200 +func (r GetHTTPPetResponse) GetJSON200() *Pet { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetHTTPPetResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetHTTPPetResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/outputoptions/name-normalizer/to-camel-case/name_normalizer.gen.go b/internal/test/outputoptions/name-normalizer/to-camel-case/name_normalizer.gen.go index e9913ca86c..08c90baded 100644 --- a/internal/test/outputoptions/name-normalizer/to-camel-case/name_normalizer.gen.go +++ b/internal/test/outputoptions/name-normalizer/to-camel-case/name_normalizer.gen.go @@ -293,6 +293,16 @@ type GetHttpPetResponse struct { JSON200 *Pet } +// GetJSON200 returns JSON200 +func (r GetHttpPetResponse) GetJSON200() *Pet { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetHttpPetResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetHttpPetResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/outputoptions/name-normalizer/unset/name_normalizer.gen.go b/internal/test/outputoptions/name-normalizer/unset/name_normalizer.gen.go index b511d10eb3..cbdde2a4ef 100644 --- a/internal/test/outputoptions/name-normalizer/unset/name_normalizer.gen.go +++ b/internal/test/outputoptions/name-normalizer/unset/name_normalizer.gen.go @@ -293,6 +293,16 @@ type GetHttpPetResponse struct { JSON200 *Pet } +// GetJSON200 returns JSON200 +func (r GetHttpPetResponse) GetJSON200() *Pet { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetHttpPetResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetHttpPetResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/outputoptions/response-body-getters/enabled/config.yaml b/internal/test/outputoptions/response-body-getters/enabled/config.yaml new file mode 100644 index 0000000000..a6cf561aef --- /dev/null +++ b/internal/test/outputoptions/response-body-getters/enabled/config.yaml @@ -0,0 +1,7 @@ +# yaml-language-server: $schema=../../../../../configuration-schema.json +package: enabled +generate: + client: true + models: true +output: response_body_getters.gen.go +# `skip-response-body-getters` is left unset — getters should be generated by default. diff --git a/internal/test/outputoptions/response-body-getters/enabled/generate.go b/internal/test/outputoptions/response-body-getters/enabled/generate.go new file mode 100644 index 0000000000..65f76d2547 --- /dev/null +++ b/internal/test/outputoptions/response-body-getters/enabled/generate.go @@ -0,0 +1,3 @@ +package enabled + +//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml ../spec.yaml diff --git a/internal/test/outputoptions/response-body-getters/enabled/response_body_getters.gen.go b/internal/test/outputoptions/response-body-getters/enabled/response_body_getters.gen.go new file mode 100644 index 0000000000..28f7addd07 --- /dev/null +++ b/internal/test/outputoptions/response-body-getters/enabled/response_body_getters.gen.go @@ -0,0 +1,286 @@ +// Package enabled provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.0.0-00010101000000-000000000000 DO NOT EDIT. +package enabled + +import ( + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + + "github.com/oapi-codegen/runtime" +) + +// Error defines model for Error. +type Error struct { + Code int32 `json:"code"` + Message string `json:"message"` +} + +// Thing defines model for Thing. +type Thing struct { + Id string `json:"id"` + Name string `json:"name"` +} + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) error + +// Doer performs HTTP requests. +// +// The standard http.Client implements this interface. +type HttpRequestDoer interface { + Do(req *http.Request) (*http.Response, error) +} + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client HttpRequestDoer + + // A list of callbacks for modifying requests which are generated before sending over + // the network. + RequestEditors []RequestEditorFn +} + +// ClientOption allows setting custom parameters during construction +type ClientOption func(*Client) error + +// Creates a new Client, with reasonable defaults +func NewClient(server string, opts ...ClientOption) (*Client, error) { + // create a client with sane default values + client := Client{ + Server: server, + } + // mutate client and add all optional params + for _, o := range opts { + if err := o(&client); err != nil { + return nil, err + } + } + // ensure the server URL always has a trailing slash + if !strings.HasSuffix(client.Server, "/") { + client.Server += "/" + } + // create httpClient, if not already present + if client.Client == nil { + client.Client = &http.Client{} + } + return &client, nil +} + +// WithHTTPClient allows overriding the default Doer, which is +// automatically created using http.Client. This is useful for tests. +func WithHTTPClient(doer HttpRequestDoer) ClientOption { + return func(c *Client) error { + c.Client = doer + return nil + } +} + +// WithRequestEditorFn allows setting up a callback function, which will be +// called right before sending the request. This can be used to mutate the request. +func WithRequestEditorFn(fn RequestEditorFn) ClientOption { + return func(c *Client) error { + c.RequestEditors = append(c.RequestEditors, fn) + return nil + } +} + +// The interface specification for the client above. +type ClientInterface interface { + // GetThing request + GetThing(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) GetThing(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetThingRequest(c.Server, id) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +// NewGetThingRequest generates requests for GetThing +func NewGetThingRequest(server string, id string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/things/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { + for _, r := range c.RequestEditors { + if err := r(ctx, req); err != nil { + return err + } + } + for _, r := range additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on ClientInterface to offer response payloads +type ClientWithResponses struct { + ClientInterface +} + +// NewClientWithResponses creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { + client, err := NewClient(server, opts...) + if err != nil { + return nil, err + } + return &ClientWithResponses{client}, nil +} + +// WithBaseURL overrides the baseURL. +func WithBaseURL(baseURL string) ClientOption { + return func(c *Client) error { + newBaseURL, err := url.Parse(baseURL) + if err != nil { + return err + } + c.Server = newBaseURL.String() + return nil + } +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // GetThingWithResponse request + GetThingWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetThingResponse, error) +} + +type GetThingResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Thing + JSONDefault *Error +} + +// GetJSON200 returns JSON200 +func (r GetThingResponse) GetJSON200() *Thing { + return r.JSON200 +} + +// GetJSONDefault returns JSONDefault +func (r GetThingResponse) GetJSONDefault() *Error { + return r.JSONDefault +} + +// GetBody returns the raw response body bytes (Body) +func (r GetThingResponse) GetBody() []byte { + return r.Body +} + +// Status returns HTTPResponse.Status +func (r GetThingResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetThingResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r GetThingResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +// GetThingWithResponse request returning *GetThingResponse +func (c *ClientWithResponses) GetThingWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetThingResponse, error) { + rsp, err := c.GetThing(ctx, id, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetThingResponse(rsp) +} + +// ParseGetThingResponse parses an HTTP response from a GetThingWithResponse call +func ParseGetThingResponse(rsp *http.Response) (*GetThingResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetThingResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Thing + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSONDefault = &dest + + } + + return response, nil +} diff --git a/internal/test/outputoptions/response-body-getters/enabled/response_body_getters_test.go b/internal/test/outputoptions/response-body-getters/enabled/response_body_getters_test.go new file mode 100644 index 0000000000..e8ae57a20a --- /dev/null +++ b/internal/test/outputoptions/response-body-getters/enabled/response_body_getters_test.go @@ -0,0 +1,50 @@ +package enabled + +import ( + "net/http" + "reflect" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// When `skip-response-body-getters` is unset (default), the generated response +// type must expose `GetBody()` and a typed getter for each response field. +func TestResponseBodyGettersGenerated(t *testing.T) { + respType := reflect.TypeOf(GetThingResponse{}) + + t.Run("GetBody returns the raw body", func(t *testing.T) { + m, ok := respType.MethodByName("GetBody") + require.True(t, ok, "GetBody method should be generated") + + // signature: func (r GetThingResponse) GetBody() []byte + require.Equal(t, 1, m.Type.NumOut()) + assert.Equal(t, reflect.TypeOf([]byte(nil)), m.Type.Out(0)) + + body := []byte("hello") + r := GetThingResponse{Body: body, HTTPResponse: &http.Response{}} + assert.Equal(t, body, r.GetBody()) + }) + + t.Run("typed JSON200 getter returns the decoded payload", func(t *testing.T) { + m, ok := respType.MethodByName("GetJSON200") + require.True(t, ok, "GetJSON200 method should be generated") + + // signature: func (r GetThingResponse) GetJSON200() *Thing + require.Equal(t, 1, m.Type.NumOut()) + assert.Equal(t, reflect.TypeOf(&Thing{}), m.Type.Out(0)) + + thing := &Thing{Id: "1", Name: "rock"} + r := GetThingResponse{JSON200: thing} + assert.Same(t, thing, r.GetJSON200()) + }) + + t.Run("typed JSONDefault getter returns the decoded error payload", func(t *testing.T) { + m, ok := respType.MethodByName("GetJSONDefault") + require.True(t, ok, "GetJSONDefault method should be generated") + + require.Equal(t, 1, m.Type.NumOut()) + assert.Equal(t, reflect.TypeOf(&Error{}), m.Type.Out(0)) + }) +} diff --git a/internal/test/outputoptions/response-body-getters/skipped/config.yaml b/internal/test/outputoptions/response-body-getters/skipped/config.yaml new file mode 100644 index 0000000000..e637348f02 --- /dev/null +++ b/internal/test/outputoptions/response-body-getters/skipped/config.yaml @@ -0,0 +1,8 @@ +# yaml-language-server: $schema=../../../../../configuration-schema.json +package: skipped +generate: + client: true + models: true +output: response_body_getters.gen.go +output-options: + skip-response-body-getters: true diff --git a/internal/test/outputoptions/response-body-getters/skipped/generate.go b/internal/test/outputoptions/response-body-getters/skipped/generate.go new file mode 100644 index 0000000000..5ecbce0b91 --- /dev/null +++ b/internal/test/outputoptions/response-body-getters/skipped/generate.go @@ -0,0 +1,3 @@ +package skipped + +//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml ../spec.yaml diff --git a/internal/test/outputoptions/response-body-getters/skipped/response_body_getters.gen.go b/internal/test/outputoptions/response-body-getters/skipped/response_body_getters.gen.go new file mode 100644 index 0000000000..e071efe847 --- /dev/null +++ b/internal/test/outputoptions/response-body-getters/skipped/response_body_getters.gen.go @@ -0,0 +1,271 @@ +// Package skipped provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.0.0-00010101000000-000000000000 DO NOT EDIT. +package skipped + +import ( + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + + "github.com/oapi-codegen/runtime" +) + +// Error defines model for Error. +type Error struct { + Code int32 `json:"code"` + Message string `json:"message"` +} + +// Thing defines model for Thing. +type Thing struct { + Id string `json:"id"` + Name string `json:"name"` +} + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) error + +// Doer performs HTTP requests. +// +// The standard http.Client implements this interface. +type HttpRequestDoer interface { + Do(req *http.Request) (*http.Response, error) +} + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client HttpRequestDoer + + // A list of callbacks for modifying requests which are generated before sending over + // the network. + RequestEditors []RequestEditorFn +} + +// ClientOption allows setting custom parameters during construction +type ClientOption func(*Client) error + +// Creates a new Client, with reasonable defaults +func NewClient(server string, opts ...ClientOption) (*Client, error) { + // create a client with sane default values + client := Client{ + Server: server, + } + // mutate client and add all optional params + for _, o := range opts { + if err := o(&client); err != nil { + return nil, err + } + } + // ensure the server URL always has a trailing slash + if !strings.HasSuffix(client.Server, "/") { + client.Server += "/" + } + // create httpClient, if not already present + if client.Client == nil { + client.Client = &http.Client{} + } + return &client, nil +} + +// WithHTTPClient allows overriding the default Doer, which is +// automatically created using http.Client. This is useful for tests. +func WithHTTPClient(doer HttpRequestDoer) ClientOption { + return func(c *Client) error { + c.Client = doer + return nil + } +} + +// WithRequestEditorFn allows setting up a callback function, which will be +// called right before sending the request. This can be used to mutate the request. +func WithRequestEditorFn(fn RequestEditorFn) ClientOption { + return func(c *Client) error { + c.RequestEditors = append(c.RequestEditors, fn) + return nil + } +} + +// The interface specification for the client above. +type ClientInterface interface { + // GetThing request + GetThing(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) GetThing(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetThingRequest(c.Server, id) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +// NewGetThingRequest generates requests for GetThing +func NewGetThingRequest(server string, id string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/things/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { + for _, r := range c.RequestEditors { + if err := r(ctx, req); err != nil { + return err + } + } + for _, r := range additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on ClientInterface to offer response payloads +type ClientWithResponses struct { + ClientInterface +} + +// NewClientWithResponses creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { + client, err := NewClient(server, opts...) + if err != nil { + return nil, err + } + return &ClientWithResponses{client}, nil +} + +// WithBaseURL overrides the baseURL. +func WithBaseURL(baseURL string) ClientOption { + return func(c *Client) error { + newBaseURL, err := url.Parse(baseURL) + if err != nil { + return err + } + c.Server = newBaseURL.String() + return nil + } +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // GetThingWithResponse request + GetThingWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetThingResponse, error) +} + +type GetThingResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Thing + JSONDefault *Error +} + +// Status returns HTTPResponse.Status +func (r GetThingResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetThingResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r GetThingResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +// GetThingWithResponse request returning *GetThingResponse +func (c *ClientWithResponses) GetThingWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetThingResponse, error) { + rsp, err := c.GetThing(ctx, id, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetThingResponse(rsp) +} + +// ParseGetThingResponse parses an HTTP response from a GetThingWithResponse call +func ParseGetThingResponse(rsp *http.Response) (*GetThingResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetThingResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Thing + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSONDefault = &dest + + } + + return response, nil +} diff --git a/internal/test/outputoptions/response-body-getters/skipped/response_body_getters_test.go b/internal/test/outputoptions/response-body-getters/skipped/response_body_getters_test.go new file mode 100644 index 0000000000..e852ee45b8 --- /dev/null +++ b/internal/test/outputoptions/response-body-getters/skipped/response_body_getters_test.go @@ -0,0 +1,24 @@ +package skipped + +import ( + "reflect" + "testing" + + "github.com/stretchr/testify/assert" +) + +// When `skip-response-body-getters: true`, the response type must NOT expose +// `GetBody()` or any of the typed getters that the default template emits. +func TestResponseBodyGettersSkipped(t *testing.T) { + respType := reflect.TypeOf(GetThingResponse{}) + + for _, name := range []string{"GetBody", "GetJSON200", "GetJSONDefault"} { + _, ok := respType.MethodByName(name) + assert.Falsef(t, ok, "method %s should not be generated when skip-response-body-getters is true", name) + } + + // Sanity check that the response type itself is still generated — only the + // getters are skipped, not the struct. + _, ok := respType.FieldByName("Body") + assert.True(t, ok, "Body field should still be present on the response struct") +} diff --git a/internal/test/outputoptions/response-body-getters/spec.yaml b/internal/test/outputoptions/response-body-getters/spec.yaml new file mode 100644 index 0000000000..3ad817ffe0 --- /dev/null +++ b/internal/test/outputoptions/response-body-getters/spec.yaml @@ -0,0 +1,51 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Example code for the `skip-response-body-getters` output option +paths: + /things/{id}: + get: + summary: Get a thing by id + operationId: getThing + parameters: + - name: id + in: path + required: true + schema: + type: string + responses: + '200': + description: a thing + content: + application/json: + schema: + $ref: '#/components/schemas/Thing' + default: + description: error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' +components: + schemas: + Thing: + type: object + required: + - id + - name + properties: + id: + type: string + name: + type: string + Error: + type: object + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string diff --git a/internal/test/parameters/client/gen/client.gen.go b/internal/test/parameters/client/gen/client.gen.go index d92fda1dc7..0baa386b1f 100644 --- a/internal/test/parameters/client/gen/client.gen.go +++ b/internal/test/parameters/client/gen/client.gen.go @@ -2063,6 +2063,11 @@ type GetContentObjectResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetContentObjectResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetContentObjectResponse) Status() string { if r.HTTPResponse != nil { @@ -2092,6 +2097,11 @@ type GetCookieResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetCookieResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetCookieResponse) Status() string { if r.HTTPResponse != nil { @@ -2121,6 +2131,11 @@ type EnumParamsResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r EnumParamsResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r EnumParamsResponse) Status() string { if r.HTTPResponse != nil { @@ -2150,6 +2165,11 @@ type GetHeaderResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetHeaderResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetHeaderResponse) Status() string { if r.HTTPResponse != nil { @@ -2179,6 +2199,11 @@ type GetLabelExplodeArrayResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetLabelExplodeArrayResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetLabelExplodeArrayResponse) Status() string { if r.HTTPResponse != nil { @@ -2208,6 +2233,11 @@ type GetLabelExplodeObjectResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetLabelExplodeObjectResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetLabelExplodeObjectResponse) Status() string { if r.HTTPResponse != nil { @@ -2237,6 +2267,11 @@ type GetLabelExplodePrimitiveResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetLabelExplodePrimitiveResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetLabelExplodePrimitiveResponse) Status() string { if r.HTTPResponse != nil { @@ -2266,6 +2301,11 @@ type GetLabelNoExplodeArrayResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetLabelNoExplodeArrayResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetLabelNoExplodeArrayResponse) Status() string { if r.HTTPResponse != nil { @@ -2295,6 +2335,11 @@ type GetLabelNoExplodeObjectResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetLabelNoExplodeObjectResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetLabelNoExplodeObjectResponse) Status() string { if r.HTTPResponse != nil { @@ -2324,6 +2369,11 @@ type GetLabelPrimitiveResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetLabelPrimitiveResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetLabelPrimitiveResponse) Status() string { if r.HTTPResponse != nil { @@ -2353,6 +2403,11 @@ type GetMatrixExplodeArrayResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetMatrixExplodeArrayResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetMatrixExplodeArrayResponse) Status() string { if r.HTTPResponse != nil { @@ -2382,6 +2437,11 @@ type GetMatrixExplodeObjectResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetMatrixExplodeObjectResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetMatrixExplodeObjectResponse) Status() string { if r.HTTPResponse != nil { @@ -2411,6 +2471,11 @@ type GetMatrixExplodePrimitiveResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetMatrixExplodePrimitiveResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetMatrixExplodePrimitiveResponse) Status() string { if r.HTTPResponse != nil { @@ -2440,6 +2505,11 @@ type GetMatrixNoExplodeArrayResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetMatrixNoExplodeArrayResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetMatrixNoExplodeArrayResponse) Status() string { if r.HTTPResponse != nil { @@ -2469,6 +2539,11 @@ type GetMatrixNoExplodeObjectResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetMatrixNoExplodeObjectResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetMatrixNoExplodeObjectResponse) Status() string { if r.HTTPResponse != nil { @@ -2498,6 +2573,11 @@ type GetMatrixPrimitiveResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetMatrixPrimitiveResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetMatrixPrimitiveResponse) Status() string { if r.HTTPResponse != nil { @@ -2527,6 +2607,11 @@ type GetPassThroughResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetPassThroughResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetPassThroughResponse) Status() string { if r.HTTPResponse != nil { @@ -2556,6 +2641,11 @@ type GetDeepObjectResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetDeepObjectResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetDeepObjectResponse) Status() string { if r.HTTPResponse != nil { @@ -2585,6 +2675,11 @@ type GetQueryDelimitedResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetQueryDelimitedResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetQueryDelimitedResponse) Status() string { if r.HTTPResponse != nil { @@ -2614,6 +2709,11 @@ type GetQueryFormResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetQueryFormResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetQueryFormResponse) Status() string { if r.HTTPResponse != nil { @@ -2643,6 +2743,11 @@ type GetSimpleExplodeArrayResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetSimpleExplodeArrayResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetSimpleExplodeArrayResponse) Status() string { if r.HTTPResponse != nil { @@ -2672,6 +2777,11 @@ type GetSimpleExplodeObjectResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetSimpleExplodeObjectResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetSimpleExplodeObjectResponse) Status() string { if r.HTTPResponse != nil { @@ -2701,6 +2811,11 @@ type GetSimpleExplodePrimitiveResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetSimpleExplodePrimitiveResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetSimpleExplodePrimitiveResponse) Status() string { if r.HTTPResponse != nil { @@ -2730,6 +2845,11 @@ type GetSimpleNoExplodeArrayResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetSimpleNoExplodeArrayResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetSimpleNoExplodeArrayResponse) Status() string { if r.HTTPResponse != nil { @@ -2759,6 +2879,11 @@ type GetSimpleNoExplodeObjectResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetSimpleNoExplodeObjectResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetSimpleNoExplodeObjectResponse) Status() string { if r.HTTPResponse != nil { @@ -2788,6 +2913,11 @@ type GetSimplePrimitiveResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetSimplePrimitiveResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetSimplePrimitiveResponse) Status() string { if r.HTTPResponse != nil { @@ -2817,6 +2947,11 @@ type GetStartingWithNumberResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r GetStartingWithNumberResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetStartingWithNumberResponse) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/pathalias/client.gen.go b/internal/test/pathalias/client.gen.go index 1339886349..bf291c3cee 100644 --- a/internal/test/pathalias/client.gen.go +++ b/internal/test/pathalias/client.gen.go @@ -227,6 +227,16 @@ type GetTestResponse struct { JSON200 *B } +// GetJSON200 returns JSON200 +func (r GetTestResponse) GetJSON200() *B { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetTestResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetTestResponse) Status() string { if r.HTTPResponse != nil { @@ -257,6 +267,16 @@ type GetTestAlias0Response struct { JSON200 *B } +// GetJSON200 returns JSON200 +func (r GetTestAlias0Response) GetJSON200() *B { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetTestAlias0Response) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetTestAlias0Response) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/schemas/schemas.gen.go b/internal/test/schemas/schemas.gen.go index 9568743929..05562de26b 100644 --- a/internal/test/schemas/schemas.gen.go +++ b/internal/test/schemas/schemas.gen.go @@ -812,6 +812,24 @@ type EnsureEverythingIsReferencedResponse struct { } } +// GetJSON200 returns JSON200 +func (r EnsureEverythingIsReferencedResponse) GetJSON200() *struct { + AnyType1 *AnyType1 `json:"anyType1,omitempty"` + + // AnyType2 AnyType2 represents any type. + // + // This should be an interface{} + AnyType2 *AnyType2 `json:"anyType2,omitempty"` + CustomStringType *CustomStringType `foo:"bar" json:"customStringType,omitempty"` +} { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r EnsureEverythingIsReferencedResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r EnsureEverythingIsReferencedResponse) Status() string { if r.HTTPResponse != nil { @@ -843,6 +861,21 @@ type Issue1051Response struct { ApplicationvndSomethingV1JSON200 *map[string]interface{} } +// GetJSON200 returns JSON200 +func (r Issue1051Response) GetJSON200() *map[string]interface{} { + return r.JSON200 +} + +// GetApplicationvndSomethingV1JSON200 returns ApplicationvndSomethingV1JSON200 +func (r Issue1051Response) GetApplicationvndSomethingV1JSON200() *map[string]interface{} { + return r.ApplicationvndSomethingV1JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r Issue1051Response) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r Issue1051Response) Status() string { if r.HTTPResponse != nil { @@ -876,6 +909,31 @@ type Issue127Response struct { JSONDefault *GenericObject } +// GetJSON200 returns JSON200 +func (r Issue127Response) GetJSON200() *GenericObject { + return r.JSON200 +} + +// GetXML200 returns XML200 +func (r Issue127Response) GetXML200() *GenericObject { + return r.XML200 +} + +// GetYAML200 returns YAML200 +func (r Issue127Response) GetYAML200() *GenericObject { + return r.YAML200 +} + +// GetJSONDefault returns JSONDefault +func (r Issue127Response) GetJSONDefault() *GenericObject { + return r.JSONDefault +} + +// GetBody returns the raw response body bytes (Body) +func (r Issue127Response) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r Issue127Response) Status() string { if r.HTTPResponse != nil { @@ -905,6 +963,11 @@ type Issue185Response struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r Issue185Response) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r Issue185Response) Status() string { if r.HTTPResponse != nil { @@ -934,6 +997,11 @@ type Issue209Response struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r Issue209Response) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r Issue209Response) Status() string { if r.HTTPResponse != nil { @@ -963,6 +1031,11 @@ type Issue30Response struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r Issue30Response) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r Issue30Response) Status() string { if r.HTTPResponse != nil { @@ -993,6 +1066,16 @@ type GetIssues375Response struct { JSON200 *EnumInObjInArray } +// GetJSON200 returns JSON200 +func (r GetIssues375Response) GetJSON200() *EnumInObjInArray { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r GetIssues375Response) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r GetIssues375Response) Status() string { if r.HTTPResponse != nil { @@ -1022,6 +1105,11 @@ type Issue41Response struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r Issue41Response) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r Issue41Response) Status() string { if r.HTTPResponse != nil { @@ -1051,6 +1139,11 @@ type Issue9Response struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r Issue9Response) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r Issue9Response) Status() string { if r.HTTPResponse != nil { @@ -1081,6 +1174,16 @@ type Issue975Response struct { JSON200 *DeprecatedProperty } +// GetJSON200 returns JSON200 +func (r Issue975Response) GetJSON200() *DeprecatedProperty { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r Issue975Response) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r Issue975Response) Status() string { if r.HTTPResponse != nil { diff --git a/internal/test/strict-server/client/client.gen.go b/internal/test/strict-server/client/client.gen.go index e9888963f1..a076eddef0 100644 --- a/internal/test/strict-server/client/client.gen.go +++ b/internal/test/strict-server/client/client.gen.go @@ -1304,6 +1304,16 @@ type JSONExampleResponse struct { JSON200 *Example } +// GetJSON200 returns JSON200 +func (r JSONExampleResponse) GetJSON200() *Example { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r JSONExampleResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r JSONExampleResponse) Status() string { if r.HTTPResponse != nil { @@ -1333,6 +1343,11 @@ type MultipartExampleResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r MultipartExampleResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r MultipartExampleResponse) Status() string { if r.HTTPResponse != nil { @@ -1362,6 +1377,11 @@ type MultipartRelatedExampleResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r MultipartRelatedExampleResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r MultipartRelatedExampleResponse) Status() string { if r.HTTPResponse != nil { @@ -1392,6 +1412,16 @@ type MultipleRequestAndResponseTypesResponse struct { JSON200 *Example } +// GetJSON200 returns JSON200 +func (r MultipleRequestAndResponseTypesResponse) GetJSON200() *Example { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r MultipleRequestAndResponseTypesResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r MultipleRequestAndResponseTypesResponse) Status() string { if r.HTTPResponse != nil { @@ -1421,6 +1451,11 @@ type NoContentHeadersResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r NoContentHeadersResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r NoContentHeadersResponse) Status() string { if r.HTTPResponse != nil { @@ -1451,6 +1486,16 @@ type RequiredJSONBodyResponse struct { JSON200 *Example } +// GetJSON200 returns JSON200 +func (r RequiredJSONBodyResponse) GetJSON200() *Example { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r RequiredJSONBodyResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r RequiredJSONBodyResponse) Status() string { if r.HTTPResponse != nil { @@ -1480,6 +1525,11 @@ type RequiredTextBodyResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r RequiredTextBodyResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r RequiredTextBodyResponse) Status() string { if r.HTTPResponse != nil { @@ -1509,6 +1559,11 @@ type ReservedGoKeywordParametersResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r ReservedGoKeywordParametersResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r ReservedGoKeywordParametersResponse) Status() string { if r.HTTPResponse != nil { @@ -1539,6 +1594,16 @@ type ReusableResponsesResponse struct { JSON200 *Reusableresponse } +// GetJSON200 returns JSON200 +func (r ReusableResponsesResponse) GetJSON200() *Reusableresponse { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r ReusableResponsesResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r ReusableResponsesResponse) Status() string { if r.HTTPResponse != nil { @@ -1568,6 +1633,11 @@ type TextExampleResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r TextExampleResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r TextExampleResponse) Status() string { if r.HTTPResponse != nil { @@ -1597,6 +1667,11 @@ type UnknownExampleResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r UnknownExampleResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r UnknownExampleResponse) Status() string { if r.HTTPResponse != nil { @@ -1626,6 +1701,11 @@ type UnspecifiedContentTypeResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r UnspecifiedContentTypeResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r UnspecifiedContentTypeResponse) Status() string { if r.HTTPResponse != nil { @@ -1655,6 +1735,11 @@ type URLEncodedExampleResponse struct { HTTPResponse *http.Response } +// GetBody returns the raw response body bytes (Body) +func (r URLEncodedExampleResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r URLEncodedExampleResponse) Status() string { if r.HTTPResponse != nil { @@ -1685,6 +1770,16 @@ type HeadersExampleResponse struct { JSON200 *Example } +// GetJSON200 returns JSON200 +func (r HeadersExampleResponse) GetJSON200() *Example { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r HeadersExampleResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r HeadersExampleResponse) Status() string { if r.HTTPResponse != nil { @@ -1716,6 +1811,21 @@ type UnionExampleResponse struct { JSON200 *UnionExample200JSONResponseBody } +// GetApplicationalternativeJSON200 returns ApplicationalternativeJSON200 +func (r UnionExampleResponse) GetApplicationalternativeJSON200() *Example { + return r.ApplicationalternativeJSON200 +} + +// GetJSON200 returns JSON200 +func (r UnionExampleResponse) GetJSON200() *UnionExample200JSONResponseBody { + return r.JSON200 +} + +// GetBody returns the raw response body bytes (Body) +func (r UnionExampleResponse) GetBody() []byte { + return r.Body +} + // Status returns HTTPResponse.Status func (r UnionExampleResponse) Status() string { if r.HTTPResponse != nil { diff --git a/pkg/codegen/configuration.go b/pkg/codegen/configuration.go index f2cc4c0162..dbcb0a6874 100644 --- a/pkg/codegen/configuration.go +++ b/pkg/codegen/configuration.go @@ -351,6 +351,9 @@ type OutputOptions struct { // "array" DisableTypeAliasesForType []string `yaml:"disable-type-aliases-for-type"` + // SkipResponseBodyGetters decides whether to generate getter methods for response bodies. + SkipResponseBodyGetters bool `yaml:"skip-response-body-getters,omitempty"` + // NameNormalizer is the method used to normalize Go names and types, for instance converting the text `MyApi` to `MyAPI`. Corresponds with the constants defined for `codegen.NameNormalizerFunction` NameNormalizer string `yaml:"name-normalizer,omitempty"` diff --git a/pkg/codegen/templates/client-with-responses.tmpl b/pkg/codegen/templates/client-with-responses.tmpl index 68ad3d4355..b2c9546639 100644 --- a/pkg/codegen/templates/client-with-responses.tmpl +++ b/pkg/codegen/templates/client-with-responses.tmpl @@ -53,6 +53,20 @@ type {{genResponseTypeName $opid | ucFirst}} struct { {{- end}} } +{{ if not opts.OutputOptions.SkipResponseBodyGetters }} +{{- range $responseTypeDefinitions}} + // Get{{.TypeName}} returns {{.TypeName}} + func (r {{genResponseTypeName $opid | ucFirst}}) Get{{.TypeName}}() *{{.Schema.TypeDecl}} { + return r.{{.TypeName}} + } +{{- end}} + +// GetBody returns the raw response body bytes (Body) +func (r {{genResponseTypeName $opid | ucFirst}}) GetBody() []byte { + return r.Body +} +{{end}} + // Status returns HTTPResponse.Status func (r {{genResponseTypeName $opid | ucFirst}}) Status() string { if r.HTTPResponse != nil {