swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.19k stars 1.16k forks source link

Display ethereum address in scientific notation instead of string #1176

Open readygo67 opened 2 years ago

readygo67 commented 2 years ago

when I try to generate API doc for the following code, the from's example value is displayed in scientific notation. I hope it displayed as string.

Anybody knows how to display the ethereum address as string?

` package main

import "github.com/gin-gonic/gin"

type TransferParam struct { From string json:"from" example:"0x29a97C6EfFB8A411DABc6aDEEfaa84f5067C8bbe" To string json:"to" example:"0xb064b8b8244414d9ba172e9d9120bcfd70bd8f1a" Amount string json:"amount" example:"1000.12" Name string json:"name" example:"mario" }

// transfer godoc // @Summary transfer native token // @Description transfer native token // @Tags // @Accept json // @Produce json // @Param param body TransferParam false "TransferParam" // @Success 200 // @Router /accounts [get] func transfer(ctx *gin.Context) {

}

`

image

I think when swaggo convert comments to yaml, it should embrace 0x29a97C6EfFB8A411DABc6aDEEfaa84f5067C8bbe with Quotation marks。

ericlingit commented 2 years ago

I can't reproduce your problem:

My main.go:

type taskResponse struct {
    Id string `json:"id" example:"0x29a97C6EfFB8A411DABc6aDEEfaa84f5067C8bbe"`
}

// @Summary      Create a new task
// @Description  description_xxx
// @Tags         task
// @Router       /task/ [post]
// @Accept       json
// @Produce      json
// @Success      201  {object}  taskResponse
// @Failure      400  {string}  error
// @Security     ApiKeyAuth
func (db *database) createTaskHandler(c *gin.Context) {
...
}

My swagger.yaml:

definitions:
  main.taskResponse:
    properties:
      id:
        example: 0x29a97C6EfFB8A411DABc6aDEEfaa84f5067C8bbe
        type: string
    type: object

Screenshot from 2022-04-20 17-08-29