danielgtaylor / danielgtaylor/huma

Add the ability to set a custom schema for sse.Register

Open
#1,043 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
4.4k
Forks
285
Avg merge
40m
Merged PRs (30d)
1

Description

I'm using [hey-api](https://github.com/hey-api/openapi-ts) to generate some client side bindings to work with SSE from huma.

It appears as the spec in hey-api wants the events specified as singles (otherwise each item is typed as a list). I was able to make this work by patching the following line to only use the autogenerated schema if `Content["text/event-stream"]` was `nil`, this way users can set a custom `text/event-stream` schema ahead of time in the `huma.Operation`:

https://github.com/danielgtaylor/huma/blob/2b690545335bfc3ee2ae704109ec9c03480f9840/sse/sse.go#L124-L126

My internal changes also only conditionally generated the schema if `Content["text/event-stream"]` was `nil`, I didn't see a need to generate it it was going to be thrown away.

I'm happy to open a PR to allow overriding the schema in the `sse.Register` call. If there are other ways this schema can be overridden I’m happy to investigate those too!

NOTE: from my reading, I'm not sure either project is "incorrect" here, just that it seems like there are a few different flavours to specifying how SSE are described so being able to set a custom schema would work with all.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.