Skip to content

Register an api description without handler #366

Closed Answered by danielgtaylor
clintjedwards asked this question in Q&A
Discussion options

You must be logged in to vote

@clintjedwards you have full access to the OpenAPI so can modify it as needed. Here's a quick runnable example: https://go.dev/play/p/GGkYMi3Cn26

api.OpenAPI().Paths["/demo"] = &huma.PathItem{
	Get: &huma.Operation{
		OperationID: "get-demo",
		Summary:     "Get a demo",
		Responses: map[string]*huma.Response{
			"200": {
				Description: "OK",
				Content: map[string]*huma.MediaType{
					"application/json": {
						Schema: &huma.Schema{Type: huma.TypeString},
					},
				},
			},
		},
	},
}

It's a little extra work, but you can manually describe any operation registered with the underlying router that way. You can also use the schema registry at api.OpenAPI().Components.Schemas to get s…

Replies: 8 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@clintjedwards
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by clintjedwards
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants