Skip to content

Generated client code prints a pointer in Error() func #2590

@sergerad

Description

@sergerad

Problem statement

Generated code tries to print a pointer instead of printing the value pointed to.

Client code generated via:

docker run --rm -it -u $(shell id -u):$(shell id -u) -e GOPATH=$(GOPATH):/go -v $(HOME):$(HOME) -w $(shell pwd) quay.io/goswagger/swagger:v0.27.0 generate client --name abc -f ./api/swagger.yaml

Example of generated client code in *_responses.go:

type CreateConflict struct {
	Payload *models.Error
}

func (o *CreateConflict) Error() string {
	return fmt.Sprintf("[POST /abc][%d] createConflict  %+v", 409, o.Payload)
}

Swagger specification

Relevant sections:

swagger: "2.0"
...
paths:
  /abc:
    post:
      tags:
        - "abc"
      summary: "Create a new ABC"
      description: ""
      operationId: "create"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - in: "body"
          name: "abc"
          required: true
          schema:
            $ref: "#/definitions/abc"
      responses:
        202:
          description: "Accepted"
          schema:
            $ref: '#/definitions/abc'
        400:
          $ref: '#/responses/BadRequest'
        404:
          $ref: '#/responses/NotFound'
        409:
          $ref: '#/responses/Conflict'
        500:
          $ref: '#/responses/InternalError'
...
definitions:
  Error:
    type: "object"
    properties:
      message:
        type: string
        x-nullable: false
        minLength: 1
    required:
      - message
responses:
  Unauthorized:
    description: "Unauthorized"
    schema:
      $ref: '#/definitions/Error'
  NotFound:
    description: "Not found"
    schema:
      $ref: '#/definitions/Error'
  InternalError:
    description: "Inernal Server Error"
    schema:
      $ref: '#/definitions/Error'
  BadRequest:
    description: "Bad Request"
    schema:
      $ref: '#/definitions/Error'
  Conflict:
    description: "Conflict"
    schema:
      $ref: '#/definitions/Error'

Environment

swagger version: quay.io/goswagger/swagger:v0.27.0 and 0.24.0 tested
go version: 1.15
OS: MacOS 11.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions