github.com/rzurga/go-swagger@v0.28.1-0.20211109195225-5d1f453ffa3a/generator/response_test.go (about)

     1  // Copyright 2015 go-swagger maintainers
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package generator
    16  
    17  import (
    18  	"bytes"
    19  	"fmt"
    20  	"path/filepath"
    21  	"testing"
    22  
    23  	"github.com/go-openapi/spec"
    24  	"github.com/stretchr/testify/assert"
    25  	"github.com/stretchr/testify/require"
    26  )
    27  
    28  func TestSimpleResponseRender(t *testing.T) {
    29  	b, err := opBuilder("updateTask", "../fixtures/codegen/todolist.responses.yml")
    30  	require.NoError(t, err)
    31  
    32  	op, err := b.MakeOperation()
    33  	require.NoError(t, err)
    34  
    35  	var buf bytes.Buffer
    36  	opts := opts()
    37  	require.NoError(t, templates.MustGet("serverResponses").Execute(&buf, op))
    38  
    39  	ff, err := opts.LanguageOpts.FormatContent("update_task_responses.go", buf.Bytes())
    40  	require.NoErrorf(t, err, buf.String())
    41  
    42  	assertInCode(t, "o.XErrorCode", string(ff))
    43  	assertInCode(t, "o.Payload", string(ff))
    44  }
    45  
    46  func TestDefaultResponseRender(t *testing.T) {
    47  	b, err := opBuilder("getAllParameters", "../fixtures/codegen/todolist.responses.yml")
    48  	require.NoError(t, err)
    49  
    50  	op, err := b.MakeOperation()
    51  	require.NoError(t, err)
    52  
    53  	var buf bytes.Buffer
    54  	opts := opts()
    55  	require.NoError(t, templates.MustGet("clientResponse").Execute(&buf, op))
    56  
    57  	ff, err := opts.LanguageOpts.FormatContent("get_all_parameters_responses.go", buf.Bytes())
    58  	require.NoErrorf(t, err, buf.String())
    59  
    60  	res := string(ff)
    61  	assertInCode(t, "type GetAllParametersDefault struct", res)
    62  	assertInCode(t, `if response.Code()/100 == 2`, res)
    63  	assertNotInCode(t, `switch response.Code()`, res)
    64  	assertNotInCode(t, "o.Payload", res)
    65  }
    66  
    67  func TestSimpleResponses(t *testing.T) {
    68  	b, err := opBuilder("updateTask", "../fixtures/codegen/todolist.responses.yml")
    69  	require.NoError(t, err)
    70  
    71  	_, _, op, ok := b.Analyzed.OperationForName("updateTask")
    72  	require.True(t, ok)
    73  	require.NotNil(t, op)
    74  	require.NotNil(t, op.Responses)
    75  
    76  	resolver := &typeResolver{ModelsPackage: b.ModelsPackage, Doc: b.Doc}
    77  	require.NotNil(t, op.Responses.Default)
    78  
    79  	resp, err := spec.ResolveResponse(b.Doc.Spec(), op.Responses.Default.Ref)
    80  	require.NoError(t, err)
    81  
    82  	defCtx := responseTestContext{
    83  		OpID: "updateTask",
    84  		Name: "default",
    85  	}
    86  	res, err := b.MakeResponse("a", defCtx.Name, false, resolver, -1, *resp)
    87  	require.NoError(t, err)
    88  
    89  	defCtx.Require(t, *resp, res)
    90  
    91  	for code, response := range op.Responses.StatusCodeResponses {
    92  		sucCtx := responseTestContext{
    93  			OpID:      "updateTask",
    94  			Name:      "success",
    95  			IsSuccess: code/100 == 2,
    96  		}
    97  		res, err := b.MakeResponse("a", sucCtx.Name, sucCtx.IsSuccess, resolver, code, response)
    98  		require.NoError(t, err)
    99  		sucCtx.Require(t, response, res)
   100  	}
   101  }
   102  
   103  func TestInlinedSchemaResponses(t *testing.T) {
   104  	b, err := opBuilder("getTasks", "../fixtures/codegen/todolist.responses.yml")
   105  	require.NoError(t, err)
   106  
   107  	_, _, op, ok := b.Analyzed.OperationForName("getTasks")
   108  	require.True(t, ok)
   109  	require.NotNil(t, op)
   110  	require.NotNil(t, op.Responses)
   111  
   112  	resolver := &typeResolver{ModelsPackage: b.ModelsPackage, Doc: b.Doc}
   113  	require.NotNil(t, op.Responses.Default)
   114  
   115  	resp := *op.Responses.Default
   116  	defCtx := responseTestContext{
   117  		OpID: "getTasks",
   118  		Name: "default",
   119  	}
   120  	res, err := b.MakeResponse("a", defCtx.Name, false, resolver, -1, resp)
   121  	require.NoError(t, err)
   122  
   123  	defCtx.Require(t, resp, res)
   124  
   125  	for code, response := range op.Responses.StatusCodeResponses {
   126  		sucCtx := responseTestContext{
   127  			OpID:      "getTasks",
   128  			Name:      "success",
   129  			IsSuccess: code/100 == 2,
   130  		}
   131  		res, err := b.MakeResponse("a", sucCtx.Name, sucCtx.IsSuccess, resolver, code, response)
   132  		require.NoError(t, err)
   133  		sucCtx.Require(t, response, res)
   134  		assert.Len(t, b.ExtraSchemas, 1)
   135  		// ExtraSchema is not a definition: it is rendered in current operations package
   136  		assert.Equal(t, "[]*SuccessBodyItems0", res.Schema.GoType)
   137  	}
   138  }
   139  
   140  type responseTestContext struct {
   141  	OpID      string
   142  	Name      string
   143  	IsSuccess bool
   144  }
   145  
   146  func (ctx *responseTestContext) Assert(t testing.TB, response spec.Response, res GenResponse) bool {
   147  	if !assert.Equal(t, ctx.IsSuccess, res.IsSuccess) {
   148  		return false
   149  	}
   150  
   151  	if !assert.Equal(t, ctx.Name, res.Name) {
   152  		return false
   153  	}
   154  
   155  	if !assert.Equal(t, response.Description, res.Description) {
   156  		return false
   157  	}
   158  
   159  	if len(response.Headers) > 0 {
   160  		for k, v := range response.Headers {
   161  			found := false
   162  			for _, h := range res.Headers {
   163  				if h.Name == k {
   164  					found = true
   165  					if k == "X-Last-Task-Id" {
   166  						hctx := &respHeaderTestContext{k, "swag.FormatInt64", "swag.ConvertInt64"}
   167  						if !hctx.Assert(t, v, h) {
   168  							return false
   169  						}
   170  						break
   171  					}
   172  					if k == "X-Error-Code" {
   173  						hctx := &respHeaderTestContext{k, "", ""}
   174  						if !hctx.Assert(t, v, h) {
   175  							return false
   176  						}
   177  					}
   178  
   179  					break
   180  				}
   181  			}
   182  			if !assert.True(t, found) {
   183  				return false
   184  			}
   185  		}
   186  	}
   187  
   188  	if response.Schema != nil {
   189  		if !assert.NotNil(t, res.Schema) {
   190  			return false
   191  		}
   192  	} else {
   193  		if !assert.Nil(t, res.Schema) {
   194  			return false
   195  		}
   196  	}
   197  
   198  	return true
   199  }
   200  
   201  func (ctx *responseTestContext) Require(t testing.TB, response spec.Response, res GenResponse) {
   202  	if !ctx.Assert(t, response, res) {
   203  		t.FailNow()
   204  	}
   205  }
   206  
   207  type respHeaderTestContext struct {
   208  	Name      string
   209  	Formatter string
   210  	Converter string
   211  }
   212  
   213  func (ctx *respHeaderTestContext) Assert(t testing.TB, header spec.Header, hdr GenHeader) bool {
   214  	if !assert.Equal(t, ctx.Name, hdr.Name) {
   215  		return false
   216  	}
   217  	if !assert.Equal(t, "a", hdr.ReceiverName) {
   218  		return false
   219  	}
   220  	if !assert.Equal(t, ctx.Formatter, hdr.Formatter) {
   221  		return false
   222  	}
   223  	if !assert.Equal(t, ctx.Converter, hdr.Converter) {
   224  		return false
   225  	}
   226  	if !assert.Equal(t, header.Description, hdr.Description) {
   227  		return false
   228  	}
   229  	if !assert.Equal(t, header.Minimum, hdr.Minimum) || !assert.Equal(t, header.ExclusiveMinimum, hdr.ExclusiveMinimum) {
   230  		return false
   231  	}
   232  	if !assert.Equal(t, header.Maximum, hdr.Maximum) || !assert.Equal(t, header.ExclusiveMaximum, hdr.ExclusiveMaximum) {
   233  		return false
   234  	}
   235  	if !assert.Equal(t, header.MinLength, hdr.MinLength) {
   236  		return false
   237  	}
   238  	if !assert.Equal(t, header.MaxLength, hdr.MaxLength) {
   239  		return false
   240  	}
   241  	if !assert.Equal(t, header.Pattern, hdr.Pattern) {
   242  		return false
   243  	}
   244  	if !assert.Equal(t, header.MaxItems, hdr.MaxItems) {
   245  		return false
   246  	}
   247  	if !assert.Equal(t, header.MinItems, hdr.MinItems) {
   248  		return false
   249  	}
   250  	if !assert.Equal(t, header.UniqueItems, hdr.UniqueItems) {
   251  		return false
   252  	}
   253  	if !assert.Equal(t, header.MultipleOf, hdr.MultipleOf) {
   254  		return false
   255  	}
   256  	if !assert.EqualValues(t, header.Enum, hdr.Enum) {
   257  		return false
   258  	}
   259  	if !assert.Equal(t, header.Type, hdr.SwaggerType) {
   260  		return false
   261  	}
   262  	if !assert.Equal(t, header.Format, hdr.SwaggerFormat) {
   263  		return false
   264  	}
   265  	return true
   266  }
   267  
   268  func TestGenResponses_Issue540(t *testing.T) {
   269  	b, err := opBuilder("postPet", "../fixtures/bugs/540/swagger.yml")
   270  	require.NoError(t, err)
   271  
   272  	op, err := b.MakeOperation()
   273  	require.NoError(t, err)
   274  
   275  	var buf bytes.Buffer
   276  	opts := opts()
   277  	require.NoError(t, templates.MustGet("serverResponses").Execute(&buf, op))
   278  
   279  	ff, err := opts.LanguageOpts.FormatContent("post_pet_responses.go", buf.Bytes())
   280  	require.NoErrorf(t, err, buf.String())
   281  
   282  	assertInCode(t, "func (o *PostPetOK) WithPayload(payload models.Pet) *PostPetOK {", string(ff))
   283  	assertInCode(t, "func (o *PostPetOK) SetPayload(payload models.Pet) {", string(ff))
   284  }
   285  
   286  func TestGenResponses_Issue718_NotRequired(t *testing.T) {
   287  	b, err := opBuilder("doEmpty", "../fixtures/codegen/todolist.simple.yml")
   288  	require.NoError(t, err)
   289  
   290  	op, err := b.MakeOperation()
   291  	require.NoError(t, err)
   292  
   293  	var buf bytes.Buffer
   294  	opts := opts()
   295  	require.NoError(t, templates.MustGet("serverResponses").Execute(&buf, op))
   296  
   297  	ff, err := opts.LanguageOpts.FormatContent("do_empty_responses.go", buf.Bytes())
   298  	require.NoErrorf(t, err, buf.String())
   299  
   300  	assertInCode(t, "if payload == nil", string(ff))
   301  	assertInCode(t, "payload = make([]models.Foo, 0, 50)", string(ff))
   302  }
   303  
   304  func TestGenResponses_Issue718_Required(t *testing.T) {
   305  	b, err := opBuilder("doEmpty", "../fixtures/codegen/todolist.simple.yml")
   306  	require.NoError(t, err)
   307  	op, err := b.MakeOperation()
   308  	require.NoError(t, err)
   309  	var buf bytes.Buffer
   310  	opts := opts()
   311  	require.NoError(t, templates.MustGet("serverResponses").Execute(&buf, op))
   312  	ff, err := opts.LanguageOpts.FormatContent("do_empty_responses.go", buf.Bytes())
   313  	if err != nil {
   314  		fmt.Println(buf.String())
   315  	}
   316  	require.NoError(t, err)
   317  	assertInCode(t, "if payload == nil", string(ff))
   318  	assertInCode(t, "payload = make([]models.Foo, 0, 50)", string(ff))
   319  }
   320  
   321  // Issue776 includes references that span multiple files. Flattening or Expanding is required
   322  func TestGenResponses_Issue776_Spec(t *testing.T) {
   323  	defer discardOutput()()
   324  
   325  	b, err := opBuilderWithFlatten("GetItem", "../fixtures/bugs/776/spec.yaml")
   326  	require.NoError(t, err)
   327  	op, err := b.MakeOperation()
   328  	require.NoError(t, err)
   329  	var buf bytes.Buffer
   330  	opts := opts()
   331  	require.NoError(t, templates.MustGet("serverResponses").Execute(&buf, op))
   332  	ff, err := opts.LanguageOpts.FormatContent("do_empty_responses.go", buf.Bytes())
   333  	if err != nil {
   334  		fmt.Println(buf.String())
   335  	}
   336  	require.NoError(t, err)
   337  	// This should be models.Item if flat works correctly
   338  	assertInCode(t, "Payload *models.Item", string(ff))
   339  	assertNotInCode(t, "type GetItemOKBody struct", string(ff))
   340  }
   341  
   342  func TestGenResponses_Issue776_SwaggerTemplate(t *testing.T) {
   343  	defer discardOutput()()
   344  
   345  	b, err := opBuilderWithFlatten("getHealthy", "../fixtures/bugs/776/swagger-template.yml")
   346  	require.NoError(t, err)
   347  	op, err := b.MakeOperation()
   348  	require.NoError(t, err)
   349  	var buf bytes.Buffer
   350  	opts := opts()
   351  	require.NoError(t, templates.MustGet("serverResponses").Execute(&buf, op))
   352  	ff, err := opts.LanguageOpts.FormatContent("do_empty_responses.go", buf.Bytes())
   353  	if err != nil {
   354  		fmt.Println(buf.String())
   355  	}
   356  	require.NoError(t, err)
   357  	assertInCode(t, "Payload *models.Error", string(ff))
   358  }
   359  
   360  func TestIssue846(t *testing.T) {
   361  	// do it 8 times, to ensure it's always in the same order
   362  	for i := 0; i < 8; i++ {
   363  		b, err := opBuilder("getFoo", "../fixtures/bugs/846/swagger.yml")
   364  		require.NoError(t, err)
   365  		op, err := b.MakeOperation()
   366  		require.NoError(t, err)
   367  		var buf bytes.Buffer
   368  		opts := opts()
   369  		require.NoError(t, templates.MustGet("clientResponse").Execute(&buf, op))
   370  		ff, err := opts.LanguageOpts.FormatContent("do_empty_responses.go", buf.Bytes())
   371  		if err != nil {
   372  			fmt.Println(buf.String())
   373  		}
   374  		require.NoError(t, err)
   375  		// sorted by code
   376  		assert.Regexp(t, "(?s)"+
   377  			"GetFooOK struct.+"+
   378  			"GetFooNotFound struct.+"+
   379  			"GetFooInternalServerError struct", string(ff))
   380  		// sorted by name
   381  		assert.Regexp(t, "(?s)"+
   382  			"GetFooInternalServerErrorBody struct.+"+
   383  			"GetFooNotFoundBody struct.+"+
   384  			"GetFooOKBody struct", string(ff))
   385  	}
   386  }
   387  
   388  func TestIssue881(t *testing.T) {
   389  	b, err := opBuilder("getFoo", "../fixtures/bugs/881/swagger.yml")
   390  	require.NoError(t, err)
   391  	op, err := b.MakeOperation()
   392  	require.NoError(t, err)
   393  	var buf bytes.Buffer
   394  	require.NoError(t, templates.MustGet("serverResponses").Execute(&buf, op))
   395  }
   396  
   397  func TestIssue881Deep(t *testing.T) {
   398  	b, err := opBuilder("getFoo", "../fixtures/bugs/881/deep.yml")
   399  	require.NoError(t, err)
   400  	op, err := b.MakeOperation()
   401  	require.NoError(t, err)
   402  	var buf bytes.Buffer
   403  	require.NoError(t, templates.MustGet("serverResponses").Execute(&buf, op))
   404  }
   405  
   406  func TestGenResponses_XGoName(t *testing.T) {
   407  	b, err := opBuilder("putTesting", "../fixtures/specs/response_name.json")
   408  	require.NoError(t, err)
   409  	op, err := b.MakeOperation()
   410  	require.NoError(t, err)
   411  	var buf bytes.Buffer
   412  	opts := opts()
   413  	require.NoError(t, templates.MustGet("serverResponses").Execute(&buf, op))
   414  	ff, err := opts.LanguageOpts.FormatContent("put_testing_responses.go", buf.Bytes())
   415  	if err != nil {
   416  		fmt.Println(buf.String())
   417  	}
   418  	require.NoError(t, err)
   419  	assertInCode(t, "const PutTestingAlternateNameCode int =", string(ff))
   420  	assertInCode(t, "type PutTestingAlternateName struct {", string(ff))
   421  	assertInCode(t, "func NewPutTestingAlternateName() *PutTestingAlternateName {", string(ff))
   422  	assertInCode(t, "func (o *PutTestingAlternateName) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {", string(ff))
   423  }
   424  
   425  func TestGenResponses_Issue892(t *testing.T) {
   426  	b, err := methodPathOpBuilder("get", "/media/search", "../fixtures/bugs/982/swagger.yaml")
   427  	require.NoError(t, err)
   428  
   429  	op, err := b.MakeOperation()
   430  	require.NoError(t, err)
   431  
   432  	var buf bytes.Buffer
   433  	opts := opts()
   434  	require.NoError(t, templates.MustGet("clientResponse").Execute(&buf, op))
   435  
   436  	ff, err := opts.LanguageOpts.FormatContent("get_media_search_responses.go", buf.Bytes())
   437  	require.NoErrorf(t, err, buf.String())
   438  
   439  	assertInCode(t, "o.Media = aO0", string(ff))
   440  }
   441  
   442  func TestGenResponses_Issue1013(t *testing.T) {
   443  	b, err := methodPathOpBuilder("get", "/test", "../fixtures/bugs/1013/fixture-1013.yaml")
   444  	require.NoError(t, err)
   445  
   446  	op, err := b.MakeOperation()
   447  	require.NoError(t, err)
   448  
   449  	var buf bytes.Buffer
   450  	opt := opts()
   451  	require.NoError(t, templates.MustGet("serverResponses").Execute(&buf, op))
   452  
   453  	ff, err := opt.LanguageOpts.FormatContent("foo.go", buf.Bytes())
   454  	require.NoErrorf(t, err, buf.String())
   455  	assertInCode(t, "Payload *models.Response `json:\"body,omitempty\"`", string(ff))
   456  
   457  	buf.Reset()
   458  	b, err = methodPathOpBuilder("get", "/test2", "../fixtures/bugs/1013/fixture-1013.yaml")
   459  	require.NoError(t, err)
   460  
   461  	op, err = b.MakeOperation()
   462  	require.NoError(t, err)
   463  
   464  	opt = opts()
   465  	require.NoError(t, templates.MustGet("serverResponses").Execute(&buf, op))
   466  	ff, err = opt.LanguageOpts.FormatContent("foo.go", buf.Bytes())
   467  	require.NoErrorf(t, err, buf.String())
   468  	assertInCode(t, "Payload *models.Response `json:\"body,omitempty\"`", string(ff))
   469  }
   470  
   471  func TestGenResponse_15362_WithExpand(t *testing.T) {
   472  	defer discardOutput()()
   473  
   474  	fixtureConfig := map[string]map[string][]string{
   475  		// load expectations for parameters in operation get_nested_required_responses.go
   476  		"getNestedRequired": { // fixture index
   477  			"serverResponses": { // executed template
   478  				// expected code lines
   479  				`const GetNestedRequiredOKCode int = 200`,
   480  				`type GetNestedRequiredOK struct {`,
   481  				"	Payload [][][][]*GetNestedRequiredOKBodyItems0 `json:\"body,omitempty\"`",
   482  				`func NewGetNestedRequiredOK() *GetNestedRequiredOK {`,
   483  				`	return &GetNestedRequiredOK{`,
   484  				`func (o *GetNestedRequiredOK) WithPayload(payload [][][][]*GetNestedRequiredOKBodyItems0) *GetNestedRequiredOK {`,
   485  				`func (o *GetNestedRequiredOK) SetPayload(payload [][][][]*GetNestedRequiredOKBodyItems0) {`,
   486  				`func (o *GetNestedRequiredOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {`,
   487  			},
   488  			"serverOperation": { // executed template
   489  				// expected code lines
   490  				`type GetNestedRequiredOKBodyItems0 struct {`,
   491  				"	Pkcs *string `json:\"pkcs\"`",
   492  				`func (o *GetNestedRequiredOKBodyItems0) Validate(formats strfmt.Registry) error {`,
   493  				`	if err := o.validatePkcs(formats); err != nil {`,
   494  				`		return errors.CompositeValidationError(res...`,
   495  				`func (o *GetNestedRequiredOKBodyItems0) validatePkcs(formats strfmt.Registry) error {`,
   496  				`	if err := validate.Required("pkcs", "body", o.Pkcs); err != nil {`,
   497  			},
   498  		},
   499  	}
   500  
   501  	// assertParams also works for responses
   502  	assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1536", "fixture-1536-2-responses.yaml"), true, false)
   503  }
   504  
   505  func TestGenResponse_1572(t *testing.T) {
   506  	defer discardOutput()()
   507  
   508  	// testing fixture-1572.yaml with minimal flatten
   509  	// edge cases for operations schemas
   510  
   511  	/*
   512  	        Run the following test caes and exercise the minimal flatten mode:
   513  	   - [x] nil schema in body param / response
   514  	   - [x] interface{} in body param /response
   515  	   - [x] additional schema reused from model (body param and response) (with maps or arrays)
   516  	   - [x] primitive body / response
   517  	   - [x] $ref'ed response and param (check that minimal flatten expands it)
   518  
   519  	*/
   520  
   521  	fixtureConfig := map[string]map[string][]string{
   522  
   523  		// load expectations for responses in operation get_interface_responses.go
   524  		"getInterface": { // fixture index
   525  			"serverResponses": { // executed template
   526  				// expected code lines
   527  				`const GetInterfaceOKCode int = 200`,
   528  				`type GetInterfaceOK struct {`,
   529  				"	Payload interface{} `json:\"body,omitempty\"`",
   530  				`func NewGetInterfaceOK() *GetInterfaceOK {`,
   531  				`	return &GetInterfaceOK{`,
   532  				`func (o *GetInterfaceOK) WithPayload(payload interface{}) *GetInterfaceOK {`,
   533  				`	o.Payload = payload`,
   534  				`	return o`,
   535  				`func (o *GetInterfaceOK) SetPayload(payload interface{}) {`,
   536  				`	o.Payload = payload`,
   537  				`func (o *GetInterfaceOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {`,
   538  				`	rw.WriteHeader(200`,
   539  				`	payload := o.Payload`,
   540  				`	if err := producer.Produce(rw, payload); err != nil {`,
   541  			},
   542  		},
   543  
   544  		// load expectations for responses in operation get_primitive_responses.go
   545  		"getPrimitive": { // fixture index
   546  			"serverResponses": { // executed template
   547  				// expected code lines
   548  				`const GetPrimitiveOKCode int = 200`,
   549  				`type GetPrimitiveOK struct {`,
   550  				"	Payload float32 `json:\"body,omitempty\"`",
   551  				`func NewGetPrimitiveOK() *GetPrimitiveOK {`,
   552  				`	return &GetPrimitiveOK{`,
   553  				`func (o *GetPrimitiveOK) WithPayload(payload float32) *GetPrimitiveOK {`,
   554  				`	o.Payload = payload`,
   555  				`	return o`,
   556  				`func (o *GetPrimitiveOK) SetPayload(payload float32) {`,
   557  				`	o.Payload = payload`,
   558  				`func (o *GetPrimitiveOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {`,
   559  				`	rw.WriteHeader(200`,
   560  				`	payload := o.Payload`,
   561  				`	if err := producer.Produce(rw, payload); err != nil {`,
   562  			},
   563  		},
   564  
   565  		// load expectations for responses in operation get_null_responses.go
   566  		"getNull": { // fixture index
   567  			"serverResponses": { // executed template
   568  				// expected code lines
   569  				`const GetNullOKCode int = 200`,
   570  				`type GetNullOK struct {`,
   571  				"	Payload interface{} `json:\"body,omitempty\"`",
   572  				`func NewGetNullOK() *GetNullOK {`,
   573  				`	return &GetNullOK{`,
   574  				`func (o *GetNullOK) WithPayload(payload interface{}) *GetNullOK {`,
   575  				`	o.Payload = payload`,
   576  				`	return o`,
   577  				`func (o *GetNullOK) SetPayload(payload interface{}) {`,
   578  				`	o.Payload = payload`,
   579  				`func (o *GetNullOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {`,
   580  				`	rw.WriteHeader(200`,
   581  				`	payload := o.Payload`,
   582  				`	if err := producer.Produce(rw, payload); err != nil {`,
   583  				`const GetNullRequestProcessedCode int = 203`,
   584  				`/*GetNullRequestProcessed OK`,
   585  				`swagger:response getNullRequestProcessed`,
   586  				`*/`,
   587  				`type GetNullRequestProcessed struct {`,
   588  				`func NewGetNullRequestProcessed() *GetNullRequestProcessed {`,
   589  				`	return &GetNullRequestProcessed{`,
   590  				`func (o *GetNullRequestProcessed) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {`,
   591  				`	rw.Header().Del(runtime.HeaderContentType`,
   592  				`	rw.WriteHeader(203`,
   593  			},
   594  		},
   595  
   596  		// load expectations for responses in operation get_model_interface_responses.go
   597  		"getModelInterface": { // fixture index
   598  			"serverResponses": { // executed template
   599  				// expected code lines
   600  				`const GetModelInterfaceOKCode int = 200`,
   601  				`type GetModelInterfaceOK struct {`,
   602  				"	Payload []models.ModelInterface `json:\"body,omitempty\"`",
   603  				`func NewGetModelInterfaceOK() *GetModelInterfaceOK {`,
   604  				`	return &GetModelInterfaceOK{`,
   605  				`func (o *GetModelInterfaceOK) WithPayload(payload []models.ModelInterface) *GetModelInterfaceOK {`,
   606  				`	o.Payload = payload`,
   607  				`	return o`,
   608  				`func (o *GetModelInterfaceOK) SetPayload(payload []models.ModelInterface) {`,
   609  				`	o.Payload = payload`,
   610  				`func (o *GetModelInterfaceOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {`,
   611  				`	rw.WriteHeader(200`,
   612  				`	payload := o.Payload`,
   613  				`	if payload == nil {`,
   614  				`		payload = make([]models.ModelInterface, 0, 50`,
   615  				`	if err := producer.Produce(rw, payload); err != nil {`,
   616  			},
   617  		},
   618  	}
   619  
   620  	// assertParams also works for responses
   621  	assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "enhancements", "1572", "fixture-1572.yaml"), true, false)
   622  }
   623  
   624  func TestGenResponse_1893(t *testing.T) {
   625  	defer discardOutput()()
   626  
   627  	fixtureConfig := map[string]map[string][]string{
   628  		// load expectations for parameters in operation get_nested_required_responses.go
   629  		"getRecords": { // fixture index
   630  			"clientResponse": { // executed template
   631  				// expected code lines
   632  				`type GetRecordsStatus512 struct {`,
   633  				`type GetRecordsStatus515 struct {`,
   634  			},
   635  			"serverResponses": { // executed template
   636  				// expected code lines
   637  				`type GetRecordsStatus512 struct {`,
   638  				`type GetRecordsStatus515 struct {`,
   639  			},
   640  		},
   641  	}
   642  	// assertParams also works for responses
   643  	assertParams(t, fixtureConfig, filepath.Join("..", "fixtures", "bugs", "1893", "fixture-1893.yaml"), true, false)
   644  }