option

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: MIT Imports: 4 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithOpenAPIConfig added in v0.1.2

func WithOpenAPIConfig(opts ...OpenAPIOption) *openapi.Config

WithOpenAPIConfig creates a new OpenAPI configuration with the provided options. It initializes the configuration with default values and applies the provided options.

Types

type ContentConfig

type ContentConfig struct {
	Structure   any
	ContentType string

	// HTTPStatus can have values 100-599 for single status, or 1-5 for status families (e.g. 2XX)
	HTTPStatus int
}

ContentConfig defines the structure for OpenAPI content configuration.

type ContentOption

type ContentOption func(cu *ContentConfig)

ContentOption is a function that modifies the ContentConfig.

func WithContentType

func WithContentType(contentType string) ContentOption

WithContentType sets the content type for the OpenAPI content.

type OpenAPIOption

type OpenAPIOption func(*openapi.Config)

OpenAPIOption defines a function that modifies the OpenAPI configuration.

func WithBaseURL

func WithBaseURL(baseURL string) OpenAPIOption

WithBaseURL sets the base URL for the OpenAPI documentation.

func WithContact added in v0.1.2

func WithContact(contact openapi.Contact) OpenAPIOption

WithContact sets the contact information for the OpenAPI documentation.

func WithDebug

func WithDebug(debug ...bool) OpenAPIOption

WithDebug enables or disables debug logging for OpenAPI operations.

func WithDescription

func WithDescription(description string) OpenAPIOption

WithDescription sets the description for the OpenAPI documentation.

func WithDisableOpenAPI

func WithDisableOpenAPI(disable ...bool) OpenAPIOption

WithDisableOpenAPI disables the OpenAPI documentation generation. By default, OpenAPI documentation generation is enabled. If set to true, the OpenAPI documentation will not be generated.

This can be useful in production environments where you want to disable the documentation.

func WithDocsPath

func WithDocsPath(path string) OpenAPIOption

WithDocsPath sets the path for the OpenAPI documentation.

This is the path where the OpenAPI documentation will be served. The default path is "/docs".

func WithExternalDocs added in v0.1.2

func WithExternalDocs(url string, description ...string) OpenAPIOption

WithExternalDocs sets the external documentation for the OpenAPI documentation.

func WithLicense added in v0.1.2

func WithLicense(license openapi.License) OpenAPIOption

WithLicense sets the license information for the OpenAPI documentation.

func WithOpenAPIVersion

func WithOpenAPIVersion(version string) OpenAPIOption

WithOpenAPIVersion sets the OpenAPI version for the documentation. The default version is "3.1.0". Supported versions are "3.0.0" and "3.1.0".

func WithReflectorConfig added in v0.1.2

func WithReflectorConfig(opts ...ReflectorOption) OpenAPIOption

WithReflectorConfig applies custom configurations to the OpenAPI reflector.

func WithSecurity

func WithSecurity(name string, opts ...SecurityOption) OpenAPIOption

WithSecurity adds a security scheme to the OpenAPI documentation.

It can be used to define API key or HTTP Bearer authentication schemes.

func WithServer

func WithServer(url string, opts ...ServerOption) OpenAPIOption

WithServer adds a server to the OpenAPI documentation.

func WithSwaggerConfig

func WithSwaggerConfig(cfg ...openapi.SwaggerConfig) OpenAPIOption

WithSwagger sets the configuration for Swagger UI.

This allows customization of the Swagger UI appearance and behavior.

func WithTags added in v0.1.2

func WithTags(tags ...openapi.Tag) OpenAPIOption

WithTags adds tags to the OpenAPI documentation.

func WithTitle

func WithTitle(title string) OpenAPIOption

WithTitle sets the title for the OpenAPI documentation.

func WithVersion

func WithVersion(version string) OpenAPIOption

WithVersion sets the version for the OpenAPI documentation.

type OperationConfig

type OperationConfig struct {
	Hide        bool
	OperationID string
	Description string
	Summary     string
	Deprecated  bool
	Tags        []string
	Security    []RouteSecurityConfig

	Requests  []*ContentConfig
	Responses []*ContentConfig
}

OperationConfig holds the configuration for an OpenAPI operation.

type OperationOption

type OperationOption func(*OperationConfig)

Operation is a function that configures an OpenAPI operation.

func Deprecated

func Deprecated(deprecated ...bool) OperationOption

Deprecated marks the operation as deprecated in the OpenAPI documentation.

func Description

func Description(description string) OperationOption

Description sets the description for the OpenAPI operation.

func Hide

func Hide(hide ...bool) OperationOption

Hide marks the operation as hidden in the OpenAPI documentation. This is useful for operations that should not be exposed to the public API.

func OperationID added in v0.1.2

func OperationID(id string) OperationOption

OperationID sets the operation ID for the OpenAPI operation.

func Request

func Request(structure any, options ...ContentOption) OperationOption

Request adds a request structure to the OpenAPI operation.

func Response

func Response(httpStatus int, structure any, options ...ContentOption) OperationOption

Response adds a response structure to the OpenAPI operation.

func Security

func Security(securityName string, scopes ...string) OperationOption

Security adds security requirements to the OpenAPI operation.

func Summary

func Summary(summary string) OperationOption

Summary sets the summary for the OpenAPI operation.

func Tags

func Tags(tags ...string) OperationOption

Tags adds tags to the OpenAPI operation.

type ReflectorOption added in v0.1.2

type ReflectorOption func(*openapi.ReflectorConfig)

ReflectorOption defines a function that modifies the OpenAPI reflector configuration.

func InlineRefs added in v0.1.2

func InlineRefs() ReflectorOption

InlineRefs sets whether to inline references in the OpenAPI documentation.

func InterceptDefNameFunc added in v0.1.2

func InterceptDefNameFunc(fn openapi.InterceptDefNameFunc) ReflectorOption

InterceptDefNameFunc sets a function to customize schema definition names.

This function will be called with the type and the default definition name. It should return the desired definition name.

func InterceptPropFunc added in v0.1.2

func InterceptPropFunc(fn openapi.InterceptPropFunc) ReflectorOption

InterceptPropFunc sets a function to intercept property schema generation.

This function will be called with the parameters needed to generate the property schema.

func InterceptSchemaFunc added in v0.1.2

func InterceptSchemaFunc(fn openapi.InterceptSchemaFunc) ReflectorOption

InterceptSchemaFunc sets a function to intercept schema generation.

This function will be called with the parameters needed to generate the schema. It can be used to modify the schema before it is added to the OpenAPI specification.

func RequiredPropByValidateTag added in v0.1.2

func RequiredPropByValidateTag(seps ...string) ReflectorOption

RequiredPropByValidateTag sets a function to mark properties as required based on the "validate" tag.

If the "validate" tag contains "required", the property will be added to the required list of the parent schema. This is useful for automatically generating required properties based on validation tags.

func RootNullable added in v0.1.2

func RootNullable() ReflectorOption

RootNullable sets whether to allow root schemas to be nullable in the OpenAPI documentation.

func RootRef added in v0.1.2

func RootRef() ReflectorOption

RootRef sets whether to use a root reference in the OpenAPI documentation.

func StripDefNamePrefix added in v0.1.2

func StripDefNamePrefix(prefixes ...string) ReflectorOption

StripDefNamePrefix sets prefixes to strip from definition names in the OpenAPI documentation.

func TypeMapping added in v0.1.2

func TypeMapping(src, dst any) ReflectorOption

TypeMapping adds a type mapping for OpenAPI generation.

Example usage:

option.WithReflectorConfig(
	option.TypeMapping(types.NullString{}, new(string)),
)

type RouteConfig

type RouteConfig struct {
	Tags     []string
	Security []RouteSecurityConfig
	Hide     bool
}

Operation is a function that configures an OpenAPI operation.

type RouteOption

type RouteOption func(*RouteConfig)

RouteOption is a function that applies configuration to a RouteConfig.

func RouteHide

func RouteHide(hide ...bool) RouteOption

RouteHide marks the route as hidden in the OpenAPI documentation. This is useful for routes that should not be exposed to the public API.

It will hide all routes in the sub-router. If you want to hide only specific routes, use the `With` method on the route

func RouteSecurity

func RouteSecurity(securityName string, scopes ...string) RouteOption

RouteSecurity adds security schemes to the route.

It will add security schemes to all routes in the sub-router.

func RouteTags

func RouteTags(tags ...string) RouteOption

RouteTags adds tags to the route.

It will add tags to all routes in the sub-router.

type RouteSecurityConfig

type RouteSecurityConfig struct {
	Name   string
	Scopes []string
}

RouteSecurityConfig holds the security configuration for a route.

type SecurityOption

type SecurityOption func(*securityConfig)

SecurityOption is a function that applies configuration to a securityConfig.

func SecurityAPIKey

func SecurityAPIKey(name string, in openapi.SecuritySchemeAPIKeyIn) SecurityOption

SecurityAPIKey creates a security scheme for API key authentication.

func SecurityDescription

func SecurityDescription(description string) SecurityOption

SecurityDescription sets the description for the security scheme.

func SecurityHTTPBearer

func SecurityHTTPBearer(scheme string, bearerFormat ...string) SecurityOption

SecurityHTTPBearer creates a security scheme for HTTP Bearer authentication.

func SecurityOAuth2

func SecurityOAuth2(flows openapi.OAuthFlows) SecurityOption

SecurityOAuth2 creates a security scheme for OAuth 2.0 authentication.

type ServerOption

type ServerOption func(*openapi.Server)

func ServerDescription

func ServerDescription(description string) ServerOption

func ServerVariables

func ServerVariables(variables map[string]openapi.ServerVariable) ServerOption

Jump to

Keyboard shortcuts

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