mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2025-12-13 17:10:36 +00:00
Fixed linting
This commit is contained in:
parent
d188f49126
commit
23e2db1496
@ -1,11 +1,12 @@
|
|||||||
package openapi
|
package openapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bitechdev/ResolveSpec/pkg/modelregistry"
|
|
||||||
"github.com/bitechdev/ResolveSpec/pkg/restheadspec"
|
|
||||||
"github.com/bitechdev/ResolveSpec/pkg/resolvespec"
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"github.com/bitechdev/ResolveSpec/pkg/modelregistry"
|
||||||
|
"github.com/bitechdev/ResolveSpec/pkg/resolvespec"
|
||||||
|
"github.com/bitechdev/ResolveSpec/pkg/restheadspec"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExampleRestheadSpec shows how to configure OpenAPI generation for RestheadSpec
|
// ExampleRestheadSpec shows how to configure OpenAPI generation for RestheadSpec
|
||||||
@ -25,11 +26,11 @@ func ExampleRestheadSpec(db *gorm.DB) {
|
|||||||
// 3. Configure OpenAPI generator
|
// 3. Configure OpenAPI generator
|
||||||
handler.SetOpenAPIGenerator(func() (string, error) {
|
handler.SetOpenAPIGenerator(func() (string, error) {
|
||||||
generator := NewGenerator(GeneratorConfig{
|
generator := NewGenerator(GeneratorConfig{
|
||||||
Title: "My API",
|
Title: "My API",
|
||||||
Description: "API documentation for my application",
|
Description: "API documentation for my application",
|
||||||
Version: "1.0.0",
|
Version: "1.0.0",
|
||||||
BaseURL: "http://localhost:8080",
|
BaseURL: "http://localhost:8080",
|
||||||
Registry: registry,
|
Registry: registry,
|
||||||
IncludeRestheadSpec: true,
|
IncludeRestheadSpec: true,
|
||||||
IncludeResolveSpec: false,
|
IncludeResolveSpec: false,
|
||||||
IncludeFuncSpec: false,
|
IncludeFuncSpec: false,
|
||||||
@ -66,11 +67,11 @@ func ExampleResolveSpec(db *gorm.DB) {
|
|||||||
// 3. Configure OpenAPI generator
|
// 3. Configure OpenAPI generator
|
||||||
handler.SetOpenAPIGenerator(func() (string, error) {
|
handler.SetOpenAPIGenerator(func() (string, error) {
|
||||||
generator := NewGenerator(GeneratorConfig{
|
generator := NewGenerator(GeneratorConfig{
|
||||||
Title: "My API",
|
Title: "My API",
|
||||||
Description: "API documentation for my application",
|
Description: "API documentation for my application",
|
||||||
Version: "1.0.0",
|
Version: "1.0.0",
|
||||||
BaseURL: "http://localhost:8080",
|
BaseURL: "http://localhost:8080",
|
||||||
Registry: registry,
|
Registry: registry,
|
||||||
IncludeRestheadSpec: false,
|
IncludeRestheadSpec: false,
|
||||||
IncludeResolveSpec: true,
|
IncludeResolveSpec: true,
|
||||||
IncludeFuncSpec: false,
|
IncludeFuncSpec: false,
|
||||||
@ -110,11 +111,11 @@ func ExampleBothSpecs(db *gorm.DB) {
|
|||||||
// Configure OpenAPI generator for both
|
// Configure OpenAPI generator for both
|
||||||
generatorFunc := func() (string, error) {
|
generatorFunc := func() (string, error) {
|
||||||
generator := NewGenerator(GeneratorConfig{
|
generator := NewGenerator(GeneratorConfig{
|
||||||
Title: "My Unified API",
|
Title: "My Unified API",
|
||||||
Description: "Complete API documentation with both RestheadSpec and ResolveSpec endpoints",
|
Description: "Complete API documentation with both RestheadSpec and ResolveSpec endpoints",
|
||||||
Version: "1.0.0",
|
Version: "1.0.0",
|
||||||
BaseURL: "http://localhost:8080",
|
BaseURL: "http://localhost:8080",
|
||||||
Registry: sharedRegistry,
|
Registry: sharedRegistry,
|
||||||
IncludeRestheadSpec: true,
|
IncludeRestheadSpec: true,
|
||||||
IncludeResolveSpec: true,
|
IncludeResolveSpec: true,
|
||||||
IncludeFuncSpec: false,
|
IncludeFuncSpec: false,
|
||||||
@ -165,11 +166,11 @@ func ExampleWithFuncSpec() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generator := NewGenerator(GeneratorConfig{
|
generator := NewGenerator(GeneratorConfig{
|
||||||
Title: "My API with Custom Queries",
|
Title: "My API with Custom Queries",
|
||||||
Description: "API with FuncSpec custom SQL endpoints",
|
Description: "API with FuncSpec custom SQL endpoints",
|
||||||
Version: "1.0.0",
|
Version: "1.0.0",
|
||||||
BaseURL: "http://localhost:8080",
|
BaseURL: "http://localhost:8080",
|
||||||
Registry: modelregistry.NewModelRegistry(),
|
Registry: modelregistry.NewModelRegistry(),
|
||||||
IncludeRestheadSpec: false,
|
IncludeRestheadSpec: false,
|
||||||
IncludeResolveSpec: false,
|
IncludeResolveSpec: false,
|
||||||
IncludeFuncSpec: true,
|
IncludeFuncSpec: true,
|
||||||
@ -197,11 +198,11 @@ func ExampleCustomization() {
|
|||||||
// Advanced configuration - create generator function
|
// Advanced configuration - create generator function
|
||||||
generatorFunc := func() (string, error) {
|
generatorFunc := func() (string, error) {
|
||||||
generator := NewGenerator(GeneratorConfig{
|
generator := NewGenerator(GeneratorConfig{
|
||||||
Title: "My Advanced API",
|
Title: "My Advanced API",
|
||||||
Description: "Comprehensive API documentation with custom configuration",
|
Description: "Comprehensive API documentation with custom configuration",
|
||||||
Version: "2.1.0",
|
Version: "2.1.0",
|
||||||
BaseURL: "https://api.myapp.com",
|
BaseURL: "https://api.myapp.com",
|
||||||
Registry: registry,
|
Registry: registry,
|
||||||
IncludeRestheadSpec: true,
|
IncludeRestheadSpec: true,
|
||||||
IncludeResolveSpec: true,
|
IncludeResolveSpec: true,
|
||||||
IncludeFuncSpec: false,
|
IncludeFuncSpec: false,
|
||||||
|
|||||||
@ -20,9 +20,9 @@ type OpenAPISpec struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Info struct {
|
type Info struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Contact *Contact `json:"contact,omitempty"`
|
Contact *Contact `json:"contact,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,22 +47,22 @@ type PathItem struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Operation struct {
|
type Operation struct {
|
||||||
Summary string `json:"summary,omitempty"`
|
Summary string `json:"summary,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
OperationID string `json:"operationId,omitempty"`
|
OperationID string `json:"operationId,omitempty"`
|
||||||
Tags []string `json:"tags,omitempty"`
|
Tags []string `json:"tags,omitempty"`
|
||||||
Parameters []Parameter `json:"parameters,omitempty"`
|
Parameters []Parameter `json:"parameters,omitempty"`
|
||||||
RequestBody *RequestBody `json:"requestBody,omitempty"`
|
RequestBody *RequestBody `json:"requestBody,omitempty"`
|
||||||
Responses map[string]Response `json:"responses"`
|
Responses map[string]Response `json:"responses"`
|
||||||
Security []map[string][]string `json:"security,omitempty"`
|
Security []map[string][]string `json:"security,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Parameter struct {
|
type Parameter struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
In string `json:"in"` // "query", "header", "path", "cookie"
|
In string `json:"in"` // "query", "header", "path", "cookie"
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Required bool `json:"required,omitempty"`
|
Required bool `json:"required,omitempty"`
|
||||||
Schema *Schema `json:"schema,omitempty"`
|
Schema *Schema `json:"schema,omitempty"`
|
||||||
Example interface{} `json:"example,omitempty"`
|
Example interface{} `json:"example,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,21 +103,21 @@ type Schema struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SecurityScheme struct {
|
type SecurityScheme struct {
|
||||||
Type string `json:"type"` // "apiKey", "http", "oauth2", "openIdConnect"
|
Type string `json:"type"` // "apiKey", "http", "oauth2", "openIdConnect"
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Name string `json:"name,omitempty"` // For apiKey
|
Name string `json:"name,omitempty"` // For apiKey
|
||||||
In string `json:"in,omitempty"` // For apiKey: "query", "header", "cookie"
|
In string `json:"in,omitempty"` // For apiKey: "query", "header", "cookie"
|
||||||
Scheme string `json:"scheme,omitempty"` // For http: "basic", "bearer"
|
Scheme string `json:"scheme,omitempty"` // For http: "basic", "bearer"
|
||||||
BearerFormat string `json:"bearerFormat,omitempty"` // For http bearer
|
BearerFormat string `json:"bearerFormat,omitempty"` // For http bearer
|
||||||
}
|
}
|
||||||
|
|
||||||
// GeneratorConfig holds configuration for OpenAPI spec generation
|
// GeneratorConfig holds configuration for OpenAPI spec generation
|
||||||
type GeneratorConfig struct {
|
type GeneratorConfig struct {
|
||||||
Title string
|
Title string
|
||||||
Description string
|
Description string
|
||||||
Version string
|
Version string
|
||||||
BaseURL string
|
BaseURL string
|
||||||
Registry *modelregistry.DefaultModelRegistry
|
Registry *modelregistry.DefaultModelRegistry
|
||||||
IncludeRestheadSpec bool
|
IncludeRestheadSpec bool
|
||||||
IncludeResolveSpec bool
|
IncludeResolveSpec bool
|
||||||
IncludeFuncSpec bool
|
IncludeFuncSpec bool
|
||||||
@ -234,8 +234,8 @@ func (g *Generator) addCommonSchemas(spec *OpenAPISpec) {
|
|||||||
spec.Components.Schemas["Response"] = Schema{
|
spec.Components.Schemas["Response"] = Schema{
|
||||||
Type: "object",
|
Type: "object",
|
||||||
Properties: map[string]*Schema{
|
Properties: map[string]*Schema{
|
||||||
"success": {Type: "boolean", Description: "Indicates if the operation was successful"},
|
"success": {Type: "boolean", Description: "Indicates if the operation was successful"},
|
||||||
"data": {Description: "The response data"},
|
"data": {Description: "The response data"},
|
||||||
"metadata": {Ref: "#/components/schemas/Metadata"},
|
"metadata": {Ref: "#/components/schemas/Metadata"},
|
||||||
"error": {Ref: "#/components/schemas/APIError"},
|
"error": {Ref: "#/components/schemas/APIError"},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -22,12 +22,12 @@ type FallbackHandler func(w common.ResponseWriter, r common.Request, params map[
|
|||||||
|
|
||||||
// Handler handles API requests using database and model abstractions
|
// Handler handles API requests using database and model abstractions
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
db common.Database
|
db common.Database
|
||||||
registry common.ModelRegistry
|
registry common.ModelRegistry
|
||||||
nestedProcessor *common.NestedCUDProcessor
|
nestedProcessor *common.NestedCUDProcessor
|
||||||
hooks *HookRegistry
|
hooks *HookRegistry
|
||||||
fallbackHandler FallbackHandler
|
fallbackHandler FallbackHandler
|
||||||
openAPIGenerator func() (string, error)
|
openAPIGenerator func() (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHandler creates a new API handler with database and registry abstractions
|
// NewHandler creates a new API handler with database and registry abstractions
|
||||||
@ -1464,7 +1464,10 @@ func (h *Handler) HandleOpenAPI(w common.ResponseWriter, r common.Request) {
|
|||||||
|
|
||||||
w.SetHeader("Content-Type", "application/json")
|
w.SetHeader("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte(spec))
|
_, err = w.Write([]byte(spec))
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("Error sending OpenAPI spec response: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOpenAPIGenerator sets the OpenAPI generator function
|
// SetOpenAPIGenerator sets the OpenAPI generator function
|
||||||
|
|||||||
@ -24,12 +24,12 @@ type FallbackHandler func(w common.ResponseWriter, r common.Request, params map[
|
|||||||
// Handler handles API requests using database and model abstractions
|
// Handler handles API requests using database and model abstractions
|
||||||
// This handler reads filters, columns, and options from HTTP headers
|
// This handler reads filters, columns, and options from HTTP headers
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
db common.Database
|
db common.Database
|
||||||
registry common.ModelRegistry
|
registry common.ModelRegistry
|
||||||
hooks *HookRegistry
|
hooks *HookRegistry
|
||||||
nestedProcessor *common.NestedCUDProcessor
|
nestedProcessor *common.NestedCUDProcessor
|
||||||
fallbackHandler FallbackHandler
|
fallbackHandler FallbackHandler
|
||||||
openAPIGenerator func() (string, error)
|
openAPIGenerator func() (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHandler creates a new API handler with database and registry abstractions
|
// NewHandler creates a new API handler with database and registry abstractions
|
||||||
@ -2413,7 +2413,10 @@ func (h *Handler) HandleOpenAPI(w common.ResponseWriter, r common.Request) {
|
|||||||
|
|
||||||
w.SetHeader("Content-Type", "application/json")
|
w.SetHeader("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte(spec))
|
_, err = w.Write([]byte(spec))
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("Error sending OpenAPI spec response: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOpenAPIGenerator sets the OpenAPI generator function
|
// SetOpenAPIGenerator sets the OpenAPI generator function
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user