-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocument_config.go
More file actions
80 lines (65 loc) · 2.56 KB
/
Copy pathdocument_config.go
File metadata and controls
80 lines (65 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2026 Princess Beef Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package libasyncapi
import (
"io/fs"
"log/slog"
"net/http"
"net/url"
"os"
"github.com/pb33f/libopenapi/datamodel"
)
// DocumentConfiguration holds configuration options for parsing AsyncAPI documents.
type DocumentConfiguration struct {
// BasePath is the base path for resolving relative file references.
// If empty, the current working directory is used.
BasePath string
// BaseURL is the base URL for resolving relative URL references.
BaseURL *url.URL
// AllowFileReferences enables resolution of file:// references.
// Defaults to false.
AllowFileReferences bool
// AllowRemoteReferences enables resolution of http:// and https:// references.
// Defaults to false.
AllowRemoteReferences bool
// RemoteURLHandler is a custom function for fetching remote references.
// If nil, the default http client is used.
RemoteURLHandler func(url string) (*http.Response, error)
// LocalFS is a custom filesystem for resolving local file references.
// If nil, the OS filesystem is used.
LocalFS fs.FS
// SkipCircularReferenceCheck disables circular reference detection.
// This can improve performance but may cause infinite loops if circular
// references exist in the specification.
SkipCircularReferenceCheck bool
// ExtractRefsSequentially processes references one at a time instead of
// in parallel. This is slower but can be useful for debugging.
ExtractRefsSequentially bool
// Logger is an optional structured logger for diagnostic messages.
Logger *slog.Logger
}
// NewDocumentConfiguration creates a new DocumentConfiguration with default values.
func NewDocumentConfiguration() *DocumentConfiguration {
return &DocumentConfiguration{
Logger: slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelError,
})),
}
}
// ToLibOpenAPIConfig converts this configuration to libopenapi's configuration format.
func (c *DocumentConfiguration) ToLibOpenAPIConfig() *datamodel.DocumentConfiguration {
if c == nil {
return datamodel.NewDocumentConfiguration()
}
return &datamodel.DocumentConfiguration{
BasePath: c.BasePath,
BaseURL: c.BaseURL,
AllowFileReferences: c.AllowFileReferences,
AllowRemoteReferences: c.AllowRemoteReferences,
SkipCircularReferenceCheck: c.SkipCircularReferenceCheck,
ExtractRefsSequentially: c.ExtractRefsSequentially,
Logger: c.Logger,
RemoteURLHandler: c.RemoteURLHandler,
LocalFS: c.LocalFS,
}
}