Skip to main content

Interface responses

OpenAPI allows to define multiple responses by using HTTP codes and content types.

Multiple responses schema
      responses:
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input

To represents them, ogen generates an interface-based sum type (or tagged union) of different response types.

addPet operation response interface
type AddPetRes interface {
addPetRes()
}
addPet operation response variants
// AddPetMethodNotAllowed is response for AddPet operation.
type AddPetMethodNotAllowed struct{}

func (*AddPetMethodNotAllowed) addPetRes() {}

// Ref: #/components/schemas/Pet
type Pet struct {
ID OptInt64 `json:"id"`
Name string `json:"name"`
Category OptCategory `json:"category"`
PhotoUrls []string `json:"photoUrls"`
Tags []Tag `json:"tags"`
// Pet status in the store.
Status OptPetStatus `json:"status"`
}

func (*Pet) addPetRes() {}