Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewGenerator ¶
func NewGenerator(opts ...option.OpenAPIOption) spec.Generator
NewGenerator creates a new OpenAPI generator with the specified options.
It initializes the OpenAPI handler and sets up the necessary routes.
The generator can be used to define API endpoints and generate OpenAPI documentation.
Types ¶
type Generator ¶
type Generator interface {
Router
// Validate checks if the OpenAPI spec is valid.
Validate() error
// GenerateOpenAPISchema generates the OpenAPI schema in the specified format(s).
GenerateOpenAPISchema(format ...string) ([]byte, error)
// MarshalYAML marshals the OpenAPI specification to YAML format.
MarshalYAML() ([]byte, error)
// MarshalJSON marshals the OpenAPI specification to JSON format.
MarshalJSON() ([]byte, error)
// WriteSchemaTo writes the OpenAPI schema to the specified file path.
WriteSchemaTo(filepath string) error
}
Generator embeds Router and adds OpenAPI-specific methods.
func NewRouter ¶
func NewRouter(ginRouter gin.IRouter, opts ...option.OpenAPIOption) Generator
NewRouter creates a new Gin router with OpenAPI support.
It initializes the OpenAPI handler and sets up the necessary routes.
The router can be used to define API endpoints and generate OpenAPI documentation.
type Route ¶
type Route interface {
// With applies the specified options to the route.
With(opts ...option.OperationOption) Route
}
Route defines the interface for a single route.
type Router ¶
type Router interface {
// Handle registers a new route with the specified method and path, and returns a Route object.
Handle(method string, path string, handlers ...gin.HandlerFunc) Route
// GET registers a new GET route with the specified path and handlers.
GET(path string, handlers ...gin.HandlerFunc) Route
// POST registers a new POST route with the specified path and handlers.
POST(path string, handlers ...gin.HandlerFunc) Route
// DELETE registers a new DELETE route with the specified path and handlers.
DELETE(path string, handlers ...gin.HandlerFunc) Route
// PATCH registers a new PATCH route with the specified path and handlers.
PATCH(path string, handlers ...gin.HandlerFunc) Route
// PUT registers a new PUT route with the specified path and handlers.
PUT(path string, handlers ...gin.HandlerFunc) Route
// OPTIONS registers a new OPTIONS route with the specified path and handlers.
OPTIONS(path string, handlers ...gin.HandlerFunc) Route
// HEAD registers a new HEAD route with the specified path and handlers.
HEAD(path string, handlers ...gin.HandlerFunc) Route
// Group creates a new route group with the specified prefix and handlers.
Group(prefix string, handlers ...gin.HandlerFunc) Router
// Use adds middleware to the router.
Use(middlewares ...gin.HandlerFunc) Router
// StaticFile serves a single file at the specified path.
StaticFile(path string, filepath string) Router
// StaticFileFS serves a single file at the specified path using the provided file system.
StaticFileFS(path string, filepath string, fs http.FileSystem) Router
// Static serves static files from the specified root directory.
Static(path string, root string) Router
// StaticFS serves static files from the specified file system at the given path.
StaticFS(path string, fs http.FileSystem) Router
// With applies OpenAPI group-level options.
With(opts ...option.GroupOption) Router
}
Router defines the interface for a Gin router with OpenAPI support.
Click to show internal directories.
Click to hide internal directories.