Skip to content

DefaultResponse constructors have hardcoded 200 status codes #104

@wafer-bw

Description

@wafer-bw

Taking from the example in this repository, we can see that this spec's response status code is incorrectly 200. Perhaps these constructors could accept a status code?

petstore-expanded.yaml

post:
  summary: Creates a new pet
  description: Creates a new pet in the store. Duplicates are allowed
  operationId: addPet
  requestBody:
    description: Pet to add to the store
    required: true
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/NewPet'
  responses:
    '201':
      description: pet response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Pet'
    default:
      description: unexpected error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'

petstore.gen.go

// AddPetJSONDefaultResponse is a constructor method for a AddPet response.
// A *Response is returned with the configured status code and content type from the spec.
func AddPetJSONDefaultResponse(body Error) *Response {
	return &Response{
		body:        body,
		Code:        200,
		contentType: "application/json",
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions