openapi

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: Unlicense Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Ok = OKs{
	Ok: func(
		a *Operations, eid eventId.Ider, format string, params ...any,
	) (err error) {
		return nil
	},
	AuthRequired: func(
		a *Operations, eid eventId.Ider, format string, params ...any,
	) (err error) {
		return huma.Error401Unauthorized(
			string(
				reason.AuthRequired.F(format, params...),
			),
		)
	},
	PoW: func(
		a *Operations, _ eventId.Ider, format string, params ...any,
	) (err error) {
		return huma.Error406NotAcceptable(
			string(
				reason.PoW.F(format, params...),
			),
		)
	},
	Duplicate: func(
		a *Operations, _ eventId.Ider, format string, params ...any,
	) (err error) {
		return huma.Error422UnprocessableEntity(
			string(
				reason.Duplicate.F(format, params...),
			),
		)
	},
	Blocked: func(
		a *Operations, _ eventId.Ider, format string, params ...any,
	) (err error) {
		return huma.Error406NotAcceptable(
			string(
				reason.Blocked.F(format, params...),
			),
		)
	},
	RateLimited: func(
		a *Operations, _ eventId.Ider, format string, params ...any,
	) (err error) {
		return huma.Error400BadRequest(
			string(
				reason.RateLimited.F(format, params...),
			),
		)
	},
	Invalid: func(
		a *Operations, _ eventId.Ider, format string, params ...any,
	) (err error) {
		return huma.Error422UnprocessableEntity(
			string(
				reason.Invalid.F(format, params...),
			),
		)
	},
	Error: func(
		a *Operations, _ eventId.Ider, format string, params ...any,
	) (err error) {
		return huma.Error500InternalServerError(
			string(
				reason.Error.F(format, params...),
			),
		)
	},
	Unsupported: func(
		a *Operations, _ eventId.Ider, format string, params ...any,
	) (err error) {
		return huma.Error400BadRequest(
			string(
				reason.Unsupported.F(format, params...),
			),
		)
	},
	Restricted: func(
		a *Operations, _ eventId.Ider, format string, params ...any,
	) (err error) {
		return huma.Error403Forbidden(
			string(
				reason.Restricted.F(format, params...),
			),
		)
	},
}

Ok provides a collection of handler functions for managing different types of operational outcomes, each corresponding to specific error or status conditions such as authentication requirements, rate limiting, and invalid inputs.

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 server.I, 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 EventInput added in v0.2.14

type EventInput struct {
	Auth   string `header:"Authorization" doc:"nostr nip-98 (and expiring variant)" required:"false"`
	Accept string `header:"Accept" default:"application/nostr+json"`
	Body   string `doc:"event JSON"`
}

EventInput is the parameters for the Event HTTP API method.

type EventOutput added in v0.2.14

type EventOutput struct{ Body string }

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

type ExportInput added in v0.2.11

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 added in v0.2.11

type ExportOutput struct{ RawBody []byte }

ExportOutput is the return value of Export. It usually will be line structured JSON.

type ImportInput added in v0.2.12

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 added in v0.2.12

type ImportOutput struct{}

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

type OK added in v0.2.14

type OK func(
	a *Operations, env eventId.Ider, format string, params ...any,
) (err error)

OK represents a function that processes events or operations, using provided parameters to generate formatted messages and return errors if any issues occur during processing.

type OKs added in v0.2.14

type OKs struct {
	Ok           OK
	AuthRequired OK
	PoW          OK
	Duplicate    OK
	Blocked      OK
	RateLimited  OK
	Invalid      OK
	Error        OK
	Unsupported  OK
	Restricted   OK
}

OKs provides a collection of handler functions for managing different types of operational outcomes, each corresponding to specific error or status conditions such as authentication requirements, rate limiting, and invalid inputs.

type Operations

type Operations struct {
	server.I

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

func (*Operations) RegisterEvent added in v0.2.14

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

RegisterEvent is the implementation of the HTTP API Event method.

func (*Operations) RegisterExport added in v0.2.11

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

RegisterExport implements the Export HTTP API method.

func (*Operations) RegisterImport added in v0.2.12

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

RegisterImport is the implementation of the Import operation.

Jump to

Keyboard shortcuts

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