openapi

package
v1.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2025 License: Unlicense Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const Type = "openapi"

Variables

This section is empty.

Functions

func ExposeMiddleware

func ExposeMiddleware(ctx huma.Context, next func(huma.Context))

ExposeMiddleware adds the http.Request and http.ResponseWriter to the context for the Operations handler.

func New

func New(s interfaces.Server, name, version, description string, path string,
	sm *servemux.S)

New creates a new openapi.Operations and registers its methods.

func NewHuma

func NewHuma(router *servemux.S, name, version, description string) (api huma.API)

NewHuma creates a new huma.API with a Scalar docs UI, and a middleware that allows methods to access the http.Request and http.ResponseWriter.

Types

type ConfigurationGetInput

type ConfigurationGetInput struct {
	Auth   string `header:"Authorization" doc:"nostr nip-98 (and expiring variant)" required:"true"`
	Accept string `header:"Accept" default:"application/json" enum:"application/json" required:"true"`
}

ConfigurationGetInput is the parameters for HTTP API method to get Configuration.

type ConfigurationGetOutput

type ConfigurationGetOutput struct {
	Body config.C `doc:"the current configuration"`
}

ConfigurationGetOutput is the result of getting Configuration.

type ConfigurationSetInput

type ConfigurationSetInput struct {
	Auth   string   `header:"Authorization" doc:"nostr nip-98 (and expiring variant)" required:"true"`
	Body   config.C `doc:"the new configuration"`
	Accept string   `header:"Accept" default:"application/json" required:"false"`
}

ConfigurationSetInput is the parameters for HTTP API method to set Configuration.

type EventCountOutput

type EventCountOutput struct{ Body uint64 }

type EventIdsBySerialInput

type EventIdsBySerialInput struct {
	Start uint64 `path:"start" doc:"fetch events by their database serial beginning at this number" required:"true"`
	Count int    `path:"count" doc:"maximum number of events to return (max 1000)" required:"true"`
}

type EventIdsBySerialOutput

type EventIdsBySerialOutput struct {
	Body []eventidserial.E `doc:"event serials andIDs"`
}

type EventIdsBySerialOutputBody

type EventIdsBySerialOutputBody struct {
	Events []eventidserial.E `doc:"event serials andIDs"`
}

type EventInput

type EventInput struct {
	Auth    string `header:"Authorization" doc:"nostr nip-98 (and expiring variant)" required:"false"`
	Accept  string `header:"Accept" default:"application/nostr+json;q=0.9,application/x-realy-event:q=0.1"`
	RawBody []byte
}

EventInput is the parameters for the Event HTTP API method.

type EventOutput

type EventOutput struct{ Body string }

EventOutput is the return parameters for the HTTP API Event method.

type EventsInput

type EventsInput struct {
	Auth   string   `header:"Authorization" doc:"nostr nip-98 (and expiring variant)" required:"false"`
	Accept string   `` /* 215-byte string literal not displayed */
	Body   []string `doc:"list of event Ids"`
}

EventsInput is the parameters for an Events HTTP API method. Basically an array of eventid.T.

type EventsOutput added in v1.18.0

type EventsOutput struct {
	Limit int `header:"X-Limit" default:"1000" doc:"informs client maximum number of events that they can request"`
}

type ExportInput

type ExportInput struct {
	Auth string `header:"Authorization" doc:"nostr nip-98 (and expiring variant)" required:"true"`
}

ExportInput is the parameters for the HTTP API Export method.

type ExportOutput

type ExportOutput struct{ RawBody []byte }

ExportOutput is the return value of Export. It usually will be line structured JSON. In future there may be more output formats.

type FilterInput

type FilterInput struct {
	Auth  string       `header:"Authorization" doc:"nostr nip-98 (and expiring variant)" required:"false"`
	Since int64        `query:"since" doc:"timestamp of the oldest events to return (inclusive)"`
	Until int64        `query:"until" doc:"timestamp of the newest events to return (inclusive)"`
	Limit uint         `query:"limit" doc:"maximum number of results to return"`
	Sort  string       `query:"sort" enum:"asc,desc" default:"desc" doc:"sort order by created_at timestamp"`
	Body  SimpleFilter `body:"filter" doc:"filter criteria to match for events to return"`
}

FilterInput is the parameters for a Filter HTTP API call.

func (FilterInput) ToFilter

func (fi FilterInput) ToFilter() (f *filter.T, err error)

ToFilter converts a SimpleFilter input to a regular nostr filter.T.

type FilterOutput

type FilterOutput struct {
	Body []string `doc:"list of event Ids that mach the query in the sort order requested"`
}

FilterOutput is a list of event Ids that match the query in the sort order requested.

type H

type H struct {
	// Ctx is the http.Request context of the subscriber, this enables garbage
	// collecting the subscriptions from http.
	Ctx context.T
	// Receiver is a channel that the listener sends subscription events to for http
	// subscribe endpoint.
	Receiver event.C
	// Pubkey is the pubkey authed to this subscription
	Pubkey []byte
	// Filter is the filter associated with the http subscription
	Filter *filter.T
}

H is the control structure for a HTTP SSE subscription, including the filter, authed pubkey and a channel to send the events to.

func (*H) Type

func (h *H) Type() string

type ImportInput

type ImportInput struct {
	Auth string `header:"Authorization" doc:"nostr nip-98 token for authentication" required:"true"`
}

ImportInput is the parameters of an import operation, authentication and the stream of line structured JSON events.

type ImportOutput

type ImportOutput struct{}

ImportOutput is nothing, basically, a 204 or 200 status is expected.

type Map

type Map map[*H]struct{}

Map is a collection of H TTP subscriptions.

type NukeInput

type NukeInput struct {
	Auth    string `header:"Authorization" doc:"nostr nip-98 (and expiring variant)" required:"true"`
	Confirm string `header:"X-Confirm" doc:"must put 'Yes I Am Sure' in this field as confirmation"`
}

NukeInput is the parameters for the HTTP API method nuke. Note that it has a confirmation header that must be provided to prevent accidental invocation of this method.

type NukeOutput

type NukeOutput struct{}

NukeOutput is basically nothing, a 200 or 204 HTTP status response is normal.

type Operations

type Operations struct {
	interfaces.Server

	*servemux.S
	// contains filtered or unexported fields
}

func (*Operations) RegisterConfigurationGet

func (x *Operations) RegisterConfigurationGet(api huma.API)

RegisterConfigurationGet implements the HTTP API for getting the Configuration.

func (*Operations) RegisterConfigurationSet

func (x *Operations) RegisterConfigurationSet(api huma.API)

RegisterConfigurationSet implements the HTTP API for setting Configuration.

func (*Operations) RegisterEvent

func (x *Operations) RegisterEvent(api huma.API)

RegisterEvent is the implementatino of the HTTP API Event method.

func (*Operations) RegisterEventCount

func (x *Operations) RegisterEventCount(api huma.API)

func (*Operations) RegisterEventIdsBySerial

func (x *Operations) RegisterEventIdsBySerial(api huma.API)

RegisterEventIdsBySerial is a query that allows fetching of events based on their internal serial number, enabling simple synchronisation of the database of events in the order they were stored.

If the event doesn't exist, the next largest one that does is the start and the count parameter says how many.

Results are a json object with keys as stringified versions of the serial numbers, in ascending order.

Serials are guaranteed to be stable and either refer to the same event or not exist anymore if the event was deleted, and start at zero and count up monotonically, and atomically.

Requests are limited to 512 events per request, and the next number after the last result will refer to the next event in the sequence of serial numbers of events that exist.

func (*Operations) RegisterEvents

func (x *Operations) RegisterEvents(api huma.API)

RegisterEvents is the implementation of the HTTP API for Events.

func (*Operations) RegisterExport

func (x *Operations) RegisterExport(api huma.API)

RegisterExport implements the Export HTTP API method.

func (*Operations) RegisterFilter

func (x *Operations) RegisterFilter(api huma.API)

RegisterFilter is the implementation of the HTTP API Filter method.

func (*Operations) RegisterImport

func (x *Operations) RegisterImport(api huma.API)

RegisterImport is the implementation of the Import operation.

func (*Operations) RegisterNuke

func (x *Operations) RegisterNuke(api huma.API)

RegisterNuke is the implementation of the Nuke HTTP API method.

func (*Operations) RegisterRelay

func (x *Operations) RegisterRelay(api huma.API)

RegisterRelay is the implementatino of the HTTP API Relay method.

func (*Operations) RegisterRescan

func (x *Operations) RegisterRescan(api huma.API)

func (*Operations) RegisterShutdown

func (x *Operations) RegisterShutdown(api huma.API)

func (*Operations) RegisterSubscribe

func (x *Operations) RegisterSubscribe(api huma.API)

type RelayInput

type RelayInput struct {
	Auth    string `header:"Authorization" doc:"nostr nip-98 (and expiring variant)" required:"false"`
	RawBody []byte
}

RelayInput is the parameters for the Event HTTP API method.

type RelayOutput

type RelayOutput struct{ Body string }

RelayOutput is the return parameters for the HTTP API Relay method.

type RescanInput

type RescanInput struct {
	Auth string `header:"Authorization" doc:"nostr nip-98 (and expiring variant)" required:"true"`
}

type RescanOutput

type RescanOutput struct{}

type S

type S struct {
	// Map is the map of subscriptions from the http api.
	Map
	// HLock is the mutex that locks the Map.
	Mx sync.Mutex
}

func NewPublisher

func NewPublisher() *S

func (*S) Deliver

func (p *S) Deliver(authRequired, publicReadable bool, ev *event.T)

func (*S) Receive

func (p *S) Receive(msg typer.T)

func (*S) Type

func (p *S) Type() string

type ServeMux

type ServeMux struct {
	*http.ServeMux
}

func NewServeMux

func NewServeMux() *ServeMux

func (*ServeMux) ServeHTTP

func (c *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ShutdownInput

type ShutdownInput struct {
	Auth string `header:"Authorization" doc:"nostr nip-98 (and expiring variant)" required:"true"`
}

type ShutdownOutput

type ShutdownOutput struct{}

type SimpleFilter

type SimpleFilter struct {
	Kinds   []int      `json:"kinds,omitempty" doc:"array of kind numbers to match on"`
	Authors []string   `json:"authors,omitempty" doc:"array of author pubkeys to match on (hex encoded)"`
	Tags    [][]string `` /* 136-byte string literal not displayed */
}

SimpleFilter is the main parts of a filter.T that relate to event store indexes.

type SubscribeInput

type SubscribeInput struct {
	Auth   string `header:"Authorization" doc:"nostr nip-98 (and expiring variant)" required:"false"`
	Accept string `header:"Accept" default:"text/event-stream" enum:"text/event-stream" required:"true"`
	// ContentType string       `header:"Content-Type" default:"text/event-stream" enum:"text/event-stream" required:"true"`
	Body SimpleFilter `body:"filter" doc:"filter criteria to match for events to return"`
}

func (SubscribeInput) ToFilter

func (fi SubscribeInput) ToFilter() (f *filter.T, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL