Skip to content

Commit f2fb2cb

Browse files
authored
Merge pull request #715 from marle3003/develop
Develop
2 parents e661078 + 2723d55 commit f2fb2cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3813
-212
lines changed

acceptance/cmd_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"mokapi/server/cert"
2222
"mokapi/version"
2323

24-
"github.com/pkg/errors"
2524
log "github.com/sirupsen/logrus"
2625
)
2726

@@ -34,10 +33,6 @@ type Cmd struct {
3433
func Start(cfg *static.Config) (*Cmd, error) {
3534
log.SetLevel(log.DebugLevel)
3635

37-
if len(cfg.Services) > 0 {
38-
return nil, errors.New("static configuration Services are no longer supported. Use patching instead.")
39-
}
40-
4136
feature.Enable(cfg.Features)
4237

4338
registerDynamicTypes()

api/handler_http.go

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -211,44 +211,46 @@ func (h *handler) getHttpService(w http.ResponseWriter, r *http.Request, m *moni
211211
op.Parameters = getParameters(p.Value.Parameters)
212212
op.Parameters = append(op.Parameters, getParameters(o.Parameters)...)
213213

214-
for it := o.Responses.Iter(); it.Next(); {
215-
statusCode := it.Key()
216-
r := it.Value()
217-
if r.Value == nil {
218-
continue
219-
}
220-
res := response{
221-
StatusCode: statusCode,
222-
Description: r.Value.Description,
223-
}
224-
if len(r.Description) > 0 {
225-
res.Description = r.Description
226-
}
227-
228-
for ct, r := range r.Value.Content {
229-
res.Contents = append(res.Contents, mediaType{
230-
Type: ct,
231-
Schema: r.Schema,
232-
})
233-
}
234-
for name, h := range r.Value.Headers {
235-
if h.Value == nil {
214+
if o.Responses != nil {
215+
for it := o.Responses.Iter(); it.Next(); {
216+
statusCode := it.Key()
217+
r := it.Value()
218+
if r.Value == nil {
236219
continue
237220
}
221+
res := response{
222+
StatusCode: statusCode,
223+
Description: r.Value.Description,
224+
}
225+
if len(r.Description) > 0 {
226+
res.Description = r.Description
227+
}
238228

239-
hi := header{
240-
Name: name,
241-
Description: h.Value.Description,
242-
Schema: h.Value.Schema,
229+
for ct, r := range r.Value.Content {
230+
res.Contents = append(res.Contents, mediaType{
231+
Type: ct,
232+
Schema: r.Schema,
233+
})
243234
}
244-
if len(h.Description) > 0 {
245-
hi.Description = h.Description
235+
for name, h := range r.Value.Headers {
236+
if h.Value == nil {
237+
continue
238+
}
239+
240+
hi := header{
241+
Name: name,
242+
Description: h.Value.Description,
243+
Schema: h.Value.Schema,
244+
}
245+
if len(h.Description) > 0 {
246+
hi.Description = h.Description
247+
}
248+
249+
res.Headers = append(res.Headers, hi)
246250
}
247251

248-
res.Headers = append(res.Headers, hi)
252+
op.Responses = append(op.Responses, res)
249253
}
250-
251-
op.Responses = append(op.Responses, res)
252254
}
253255

254256
requirements := append(o.Security, s.Security...)

api/handler_schema.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (h *handler) getExampleData(w http.ResponseWriter, r *http.Request) {
6666
case *openApiSchema.Schema:
6767
s = openApiSchema.ConvertToJsonSchema(t)
6868
case *avro.Schema:
69-
s = t.Convert()
69+
s = avro.ConvertToJsonSchema(t)
7070
default:
7171
var ok bool
7272
s, ok = t.(*jsonSchema.Schema)
@@ -151,7 +151,7 @@ func encodeExample(v interface{}, schema interface{}, schemaFormat string, conte
151151
case *avro.Schema:
152152
switch {
153153
case ct.Subtype == "json":
154-
data, err = encoding.NewEncoder(t.Convert()).Write(v, ct)
154+
data, err = encoding.NewEncoder(avro.ConvertToJsonSchema(t)).Write(v, ct)
155155
case ct.Key() == "avro/binary" || ct.Key() == "application/avro" || ct.Key() == "application/octet-stream":
156156
data, err = t.Marshal(v)
157157
default:

api/handler_schema_asyncapi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func getAsyncApiExample(w http.ResponseWriter, r *http.Request, cfg *asyncapi3.C
5959
case *openApiSchema.Schema:
6060
s = openApiSchema.ConvertToJsonSchema(t)
6161
case *avro.Schema:
62-
s = t.Convert()
62+
s = avro.ConvertToJsonSchema(t)
6363
default:
6464
var ok bool
6565
s, ok = t.(*jsonSchema.Schema)
@@ -85,7 +85,7 @@ func getAsyncApiExample(w http.ResponseWriter, r *http.Request, cfg *asyncapi3.C
8585
case *avro.Schema:
8686
switch {
8787
case ct.Subtype == "json":
88-
data, err = encoding.NewEncoder(t.Convert()).Write(rnd, ct)
88+
data, err = encoding.NewEncoder(avro.ConvertToJsonSchema(t)).Write(rnd, ct)
8989
case ct.Key() == "avro/binary" || ct.Key() == "application/avro" || ct.Key() == "application/octet-stream":
9090
data, err = t.Marshal(rnd)
9191
default:

cmd/mokapi/main.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ func main() {
6666

6767
fmt.Printf(logo, version.BuildVersion, strings.Repeat(" ", 17-len(versionString)))
6868

69-
if len(cfg.Services) > 0 {
70-
fmt.Println("static configuration Services are no longer supported. Use patching instead.")
71-
return
72-
}
73-
7469
configureLogging(cfg)
7570
registerDynamicTypes()
7671

@@ -139,19 +134,17 @@ func createServer(cfg *static.Config) (*server.Server, error) {
139134
func configureLogging(cfg *static.Config) {
140135
stdlog.SetFlags(stdlog.Lshortfile | stdlog.LstdFlags)
141136

142-
if cfg.Log != nil {
143-
level, err := log.ParseLevel(cfg.Log.Level)
144-
if err != nil {
145-
log.WithField("logLevel", cfg.Log.Level).Errorf("error parsing log level: %v", err.Error())
146-
}
147-
log.SetLevel(level)
137+
level, err := log.ParseLevel(cfg.Log.Level)
138+
if err != nil {
139+
log.WithField("logLevel", cfg.Log.Level).Errorf("error parsing log level: %v", err.Error())
140+
}
141+
log.SetLevel(level)
148142

149-
if strings.ToLower(cfg.Log.Format) == "json" {
150-
log.SetFormatter(&log.JSONFormatter{})
151-
} else {
152-
formatter := &log.TextFormatter{DisableColors: false, FullTimestamp: true, DisableSorting: true}
153-
log.SetFormatter(formatter)
154-
}
143+
if strings.ToLower(cfg.Log.Format) == "json" {
144+
log.SetFormatter(&log.JSONFormatter{})
145+
} else {
146+
formatter := &log.TextFormatter{DisableColors: false, FullTimestamp: true, DisableSorting: true}
147+
log.SetFormatter(formatter)
155148
}
156149
}
157150

cmd/mokapi/main_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ providers:
3434
file:
3535
filenames: []
3636
directories: []
37-
skipprefix:
37+
skipPrefix:
3838
- _
3939
include: []
4040
git:
@@ -59,11 +59,8 @@ api:
5959
dashboard: true
6060
search:
6161
enabled: false
62-
types: []
6362
rootCaCert: ""
6463
rootCaKey: ""
65-
js:
66-
globalfolders: []
6764
configs: []
6865
event:
6966
store:
@@ -83,7 +80,7 @@ data-gen:
8380
require.Equal(t, `file:
8481
filenames: []
8582
directories: []
86-
skipprefix:
83+
skipPrefix:
8784
- _
8885
include: []
8986
git:

config/dynamic/provider/file/file.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (p *Provider) Read(u *url.URL) (*dynamic.Config, error) {
8383
if err != nil {
8484
return nil, err
8585
}
86+
config.Info.Url = u
8687
config.SourceType = dynamic.SourceReference
8788

8889
p.watchPath(file)

config/static/static_config.go

Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ import (
1212
)
1313

1414
type Config struct {
15-
Log *MokApiLog `json:"log" yaml:"log"`
16-
ConfigFile string `json:"-" yaml:"-"`
15+
Log MokApiLog `json:"log" yaml:"log"`
16+
ConfigFile string `json:"-" yaml:"-" flag:"-"`
1717
Providers Providers `json:"providers" yaml:"providers"`
1818
Api Api `json:"api" yaml:"api"`
19-
RootCaCert tls.FileOrContent `json:"rootCaCert" yaml:"rootCaCert"`
20-
RootCaKey tls.FileOrContent `json:"rootCaKey" yaml:"rootCaKey"`
21-
Services Services `json:"-" yaml:"-"`
22-
Js JsConfig `json:"js" yaml:"js"`
19+
RootCaCert tls.FileOrContent `json:"rootCaCert" yaml:"rootCaCert" name:"root-ca-cert"`
20+
RootCaKey tls.FileOrContent `json:"rootCaKey" yaml:"rootCaKey" name:"root-ca-cert"`
2321
Configs Configs `json:"configs" yaml:"configs" explode:"config"`
2422
Help bool `json:"-" yaml:"-" aliases:"h"`
2523
GenerateSkeleton interface{} `json:"-" yaml:"-" flag:"generate-cli-skeleton"`
@@ -33,7 +31,7 @@ type Config struct {
3331

3432
func NewConfig() *Config {
3533
cfg := &Config{}
36-
cfg.Log = &MokApiLog{Level: "info", Format: "text"}
34+
cfg.Log = MokApiLog{Level: "info", Format: "text"}
3735

3836
cfg.Api.Port = "8080"
3937
cfg.Api.Dashboard = true
@@ -67,37 +65,31 @@ type Api struct {
6765

6866
type Search struct {
6967
Enabled bool
70-
Types []string
71-
}
72-
73-
type NgramAnalyzer struct {
74-
Min int
75-
Max int
7668
}
7769

7870
type FileProvider struct {
7971
Filenames []string `explode:"filename"`
8072
Directories []string `explode:"directory"`
81-
SkipPrefix []string `flag:"skip-prefix"`
73+
SkipPrefix []string `yaml:"skipPrefix" json:"skipPrefix" flag:"skip-prefix"`
8274
Include []string
8375
}
8476

8577
type GitProvider struct {
8678
Urls []string `explode:"url"`
87-
PullInterval string `yaml:"pullInterval" name:"pull-interval"`
88-
TempDir string `yaml:"tempDir" name:"temp-dir"`
79+
PullInterval string `yaml:"pullInterval" json:"pullInterval" name:"pull-interval"`
80+
TempDir string `yaml:"tempDir" json:"tempDir" name:"temp-dir"`
8981

9082
Repositories []GitRepo `explode:"repository"`
9183
}
9284

9385
type GitRepo struct {
9486
Url string
9587
// Specifies an allow list of files to include in mokapi
96-
Files []string
88+
Files []string `explode:"file"`
9789
// Specifies an array of filenames pr pattern to include in mokapi
9890
Include []string
9991
Auth *GitAuth
100-
PullInterval string `yaml:"pullInterval"`
92+
PullInterval string `yaml:"pullInterval" name:"pull-interval"`
10193
}
10294

10395
type GitAuth struct {
@@ -112,15 +104,15 @@ type GitHubAuth struct {
112104

113105
type HttpProvider struct {
114106
Urls []string `explode:"url"`
115-
PollInterval string `yaml:"pollInterval" flag:"poll-interval"`
116-
PollTimeout string `yaml:"pollTimeout" flag:"poll-timeout"`
107+
PollInterval string `yaml:"pollInterval" name:"poll-interval"`
108+
PollTimeout string `yaml:"pollTimeout" name:"poll-timeout"`
117109
Proxy string
118110
TlsSkipVerify bool `yaml:"tlsSkipVerify" flag:"tls-skip-verify"`
119111
Ca tls.FileOrContent `yaml:"ca"`
120112
}
121113

122114
type NpmProvider struct {
123-
GlobalFolders []string `yaml:"globalFolders" flag:"global-folders"`
115+
GlobalFolders []string `yaml:"globalFolders" name:"global-folders" explode:"global-folders"`
124116
Packages []NpmPackage `explode:"package"`
125117
}
126118

@@ -132,36 +124,6 @@ type NpmPackage struct {
132124
Include []string
133125
}
134126

135-
type Services map[string]*Service
136-
137-
func (s Services) GetByName(name string) *Service {
138-
key := strings.ReplaceAll(name, " ", "-")
139-
key = strings.ToLower(key)
140-
return s[key]
141-
}
142-
143-
type Service struct {
144-
Config ServiceConfig
145-
Http *HttpService
146-
}
147-
148-
type ServiceConfig struct {
149-
File string
150-
Url string
151-
}
152-
153-
type HttpService struct {
154-
Servers []HttpServer
155-
}
156-
157-
type HttpServer struct {
158-
Url string
159-
}
160-
161-
type JsConfig struct {
162-
GlobalFolders []string
163-
}
164-
165127
type Event struct {
166128
Store map[string]Store
167129
}
@@ -182,7 +144,7 @@ type Certificate struct {
182144
}
183145

184146
type DataGen struct {
185-
OptionalProperties string `yaml:"optionalProperties" json:"optionalProperties"`
147+
OptionalProperties string `yaml:"optionalProperties" json:"optionalProperties" name:"optional-properties"`
186148
}
187149

188150
func (c *Configs) UnmarshalJSON(b []byte) error {

engine/kafka.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func createValue(r *asyncapi3.SchemaRef) (value interface{}, err error) {
206206
case *openapi.Schema:
207207
value, err = openapi.CreateValue(v)
208208
case *avro.Schema:
209-
jsSchema := v.Convert()
209+
jsSchema := avro.ConvertToJsonSchema(v)
210210
value, err = generator.New(&generator.Request{Schema: jsSchema})
211211
default:
212212
err = fmt.Errorf("schema format not supported: %v", r.Value.Format)
@@ -289,7 +289,7 @@ func valueMatchMessagePayload(value any, msg *asyncapi3.Message) bool {
289289
_, err := v.Marshal(value, media.ParseContentType("application/json"))
290290
return err == nil
291291
case *avro.Schema:
292-
jsSchema := v.Convert()
292+
jsSchema := avro.ConvertToJsonSchema(v)
293293
_, err := encoding.NewEncoder(jsSchema).Write(value, media.ParseContentType("application/json"))
294294
return err == nil
295295
default:

engine/scripts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (l *DefaultScriptLoader) Load(file *dynamic.Config, host common.Host) (comm
3535
filename := file.Info.Path()
3636
switch filepath.Ext(filename) {
3737
case ".js", ".cjs", ".mjs", ".ts":
38-
return js.New(file, host, l.config.Js)
38+
return js.New(file, host)
3939
case ".lua":
4040
return lua.New(getScriptPath(file.Info.Url), s, host)
4141
default:

0 commit comments

Comments
 (0)