Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline doc description for struct fields #429

Open
jc-fireball opened this issue May 3, 2024 · 0 comments
Open

Multiline doc description for struct fields #429

jc-fireball opened this issue May 3, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@jc-fireball
Copy link

jc-fireball commented May 3, 2024

I am migrating my existing services to huma. Part of the job is to move openapi API doc along with the code so we don't need to maintain code and doc yaml.

Right now we have one challenge which is multiline description for struct field. More specifically this is for the enum types. In the API doc, we want to not only list out all enum values but also add descriptions for each of the values (kind like a table) .

Few options:

  1. Go tag: Go tag must be oneline. If we make the table into oneline but it will be difficult to maintain for developers.
  2. custom Enum type:
type Status string

var FailStatus Status = "fail"
var SuccessStatus Status = "success"

func (s Status) Schema(r huma.Registry) *huma.Schema {
	des := `The status value
| Enum Value        | Description |
|-----|-----------|
| fail   | fail status |
| success  |  success status |
`
	return &huma.Schema{
		Type:        "string",
		Description: des,
		Enum:        []any{FailStatus, SuccessStatus},
	}
}

type Request struct {
  Body struct {
     Status Status `json:"status"`
  }
}

This works well to list out all enums. But the description from Status schema isn't passed to Status field in request body. I checked the code of Huma, it basically only use the doc tag from the Status field. line: https://github.com/danielgtaylor/huma/blob/main/schema.go#L491

I am wondering if Huma can add some support to inherit or reference the doc/description from custom type to the struct field so that it can resolve 90% large field description issue.

@danielgtaylor danielgtaylor added the enhancement New feature or request label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants