Skip to content

Commit 84ad214

Browse files
dylanhittccoVeille
andcommitted
chore: json -> JSON & url -> URL
Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
1 parent c8418ea commit 84ad214

File tree

7 files changed

+55
-55
lines changed

7 files changed

+55
-55
lines changed

engine.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ type EngineOpenAPIConfig struct {
3636
// If true, the engine will not save the OpenAPI JSON spec locally
3737
DisableLocalSave bool
3838
// Local path to save the OpenAPI JSON spec
39-
JsonFilePath string
39+
JSONFilePath string
4040
// Pretty prints the OpenAPI spec with proper JSON indentation
41-
PrettyFormatJson bool
41+
PrettyFormatJSON bool
4242
}
4343

4444
func WithOpenAPIConfig(config OpenAPIConfig) func(*Engine) {
4545
return func(e *Engine) {
46-
if config.JsonUrl != "" {
47-
e.OpenAPIConfig.JsonUrl = config.JsonUrl
46+
if config.JsonURL != "" {
47+
e.OpenAPIConfig.JsonURL = config.JsonURL
4848
}
4949

50-
if config.SwaggerUrl != "" {
51-
e.OpenAPIConfig.SwaggerUrl = config.SwaggerUrl
50+
if config.SwaggerURL != "" {
51+
e.OpenAPIConfig.SwaggerURL = config.SwaggerURL
5252
}
5353

54-
if config.JsonFilePath != "" {
55-
e.OpenAPIConfig.JsonFilePath = config.JsonFilePath
54+
if config.JSONFilePath != "" {
55+
e.OpenAPIConfig.JSONFilePath = config.JSONFilePath
5656
}
5757

5858
if config.UIHandler != nil {
@@ -62,15 +62,15 @@ func WithOpenAPIConfig(config OpenAPIConfig) func(*Engine) {
6262
e.OpenAPIConfig.DisableSwagger = config.DisableSwagger
6363
e.OpenAPIConfig.DisableSwaggerUI = config.DisableSwaggerUI
6464
e.OpenAPIConfig.DisableLocalSave = config.DisableLocalSave
65-
e.OpenAPIConfig.PrettyFormatJson = config.PrettyFormatJson
65+
e.OpenAPIConfig.PrettyFormatJSON = config.PrettyFormatJSON
6666

67-
if !validateJsonSpecUrl(e.OpenAPIConfig.JsonUrl) {
68-
slog.Error("Error serving openapi json spec. Value of 's.OpenAPIConfig.JsonSpecUrl' option is not valid", "url", e.OpenAPIConfig.JsonUrl)
67+
if !validateJsonSpecUrl(e.OpenAPIConfig.JsonURL) {
68+
slog.Error("Error serving openapi json spec. Value of 's.OpenAPIConfig.JsonSpecUrl' option is not valid", "url", e.OpenAPIConfig.JsonURL)
6969
return
7070
}
7171

72-
if !validateSwaggerUrl(e.OpenAPIConfig.SwaggerUrl) {
73-
slog.Error("Error serving swagger ui. Value of 's.OpenAPIConfig.SwaggerUrl' option is not valid", "url", e.OpenAPIConfig.SwaggerUrl)
72+
if !validateSwaggerUrl(e.OpenAPIConfig.SwaggerURL) {
73+
slog.Error("Error serving swagger ui. Value of 's.OpenAPIConfig.SwaggerUrl' option is not valid", "url", e.OpenAPIConfig.SwaggerURL)
7474
return
7575
}
7676
}
@@ -93,9 +93,9 @@ func (e *Engine) OutputOpenAPISpec() []byte {
9393
}
9494

9595
if !e.OpenAPIConfig.DisableLocalSave {
96-
err := e.saveOpenAPIToFile(e.OpenAPIConfig.JsonFilePath, jsonSpec)
96+
err := e.saveOpenAPIToFile(e.OpenAPIConfig.JSONFilePath, jsonSpec)
9797
if err != nil {
98-
slog.Error("Error saving spec to local path", "error", err, "path", e.OpenAPIConfig.JsonFilePath)
98+
slog.Error("Error saving spec to local path", "error", err, "path", e.OpenAPIConfig.JSONFilePath)
9999
}
100100
}
101101
return jsonSpec
@@ -125,7 +125,7 @@ func (e *Engine) saveOpenAPIToFile(jsonSpecLocalPath string, jsonSpec []byte) er
125125
}
126126

127127
func (s *Engine) marshalSpec() ([]byte, error) {
128-
if s.OpenAPIConfig.PrettyFormatJson {
128+
if s.OpenAPIConfig.PrettyFormatJSON {
129129
return json.MarshalIndent(s.OpenAPI.Description(), "", " ")
130130
}
131131
return json.Marshal(s.OpenAPI.Description())

examples/generate-opengraph-image/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func main() {
2424
fuego.WithEngineOptions(
2525
fuego.WithOpenAPIConfig(fuego.OpenAPIConfig{
2626
EngineOpenAPIConfig: fuego.EngineOpenAPIConfig{
27-
PrettyFormatJson: true,
27+
PrettyFormatJSON: true,
2828
},
2929
}),
3030
),

examples/petstore/lib/server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ func TestPetstoreOpenAPIGeneration(t *testing.T) {
1717
fuego.WithEngineOptions(
1818
fuego.WithOpenAPIConfig(fuego.OpenAPIConfig{
1919
EngineOpenAPIConfig: fuego.EngineOpenAPIConfig{
20-
JsonFilePath: "testdata/doc/openapi.json",
21-
PrettyFormatJson: true,
20+
JSONFilePath: "testdata/doc/openapi.json",
21+
PrettyFormatJSON: true,
2222
},
2323
}),
2424
),

openapi.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,24 @@ func (s *Server) OutputOpenAPISpec() openapi3.T {
116116

117117
// Registers the routes to serve the OpenAPI spec and Swagger UI.
118118
func (s *Server) registerOpenAPIRoutes(jsonSpec []byte) {
119-
GetStd(s, s.OpenAPIConfig.JsonUrl, func(w http.ResponseWriter, r *http.Request) {
119+
GetStd(s, s.OpenAPIConfig.JsonURL, func(w http.ResponseWriter, r *http.Request) {
120120
w.Header().Set("Content-Type", "application/json")
121121
_, _ = w.Write(jsonSpec)
122122
})
123-
s.printOpenAPIMessage(fmt.Sprintf("JSON spec: %s%s", s.url(), s.OpenAPIConfig.JsonUrl))
123+
s.printOpenAPIMessage(fmt.Sprintf("JSON spec: %s%s", s.url(), s.OpenAPIConfig.JsonURL))
124124

125125
if !s.OpenAPIConfig.DisableSwaggerUI {
126126
Registers(s.Engine, netHttpRouteRegisterer[any, any]{
127127
s: s,
128128
route: Route[any, any]{
129129
BaseRoute: BaseRoute{
130130
Method: http.MethodGet,
131-
Path: s.OpenAPIConfig.SwaggerUrl + "/",
131+
Path: s.OpenAPIConfig.SwaggerURL + "/",
132132
},
133133
},
134-
controller: s.OpenAPIConfig.UIHandler(s.OpenAPIConfig.JsonUrl),
134+
controller: s.OpenAPIConfig.UIHandler(s.OpenAPIConfig.JsonURL),
135135
})
136-
s.printOpenAPIMessage(fmt.Sprintf("OpenAPI UI: %s%s/index.html", s.url(), s.OpenAPIConfig.SwaggerUrl))
136+
s.printOpenAPIMessage(fmt.Sprintf("OpenAPI UI: %s%s/index.html", s.url(), s.OpenAPIConfig.SwaggerURL))
137137
}
138138
}
139139

openapi_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func TestServer_OutputOpenApiSpec(t *testing.T) {
249249
WithOpenAPIConfig(
250250
OpenAPIConfig{
251251
EngineOpenAPIConfig: EngineOpenAPIConfig{
252-
JsonFilePath: docPath,
252+
JSONFilePath: docPath,
253253
},
254254
},
255255
),
@@ -274,7 +274,7 @@ func TestServer_OutputOpenApiSpec(t *testing.T) {
274274
WithOpenAPIConfig(
275275
OpenAPIConfig{
276276
EngineOpenAPIConfig: EngineOpenAPIConfig{
277-
JsonFilePath: docPath,
277+
JSONFilePath: docPath,
278278
DisableLocalSave: true,
279279
},
280280
},
@@ -298,7 +298,7 @@ func TestServer_OutputOpenApiSpec(t *testing.T) {
298298
WithOpenAPIConfig(
299299
OpenAPIConfig{
300300
EngineOpenAPIConfig: EngineOpenAPIConfig{
301-
JsonFilePath: docPath,
301+
JSONFilePath: docPath,
302302
DisableLocalSave: true,
303303
},
304304
DisableSwagger: true,
@@ -324,8 +324,8 @@ func TestServer_OutputOpenApiSpec(t *testing.T) {
324324
WithOpenAPIConfig(
325325
OpenAPIConfig{
326326
EngineOpenAPIConfig: EngineOpenAPIConfig{
327-
JsonFilePath: docPath,
328-
PrettyFormatJson: true,
327+
JSONFilePath: docPath,
328+
PrettyFormatJSON: true,
329329
},
330330
},
331331
),

server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ type OpenAPIConfig struct {
2121
// If true, the server will not serve the Swagger UI
2222
DisableSwaggerUI bool
2323
// URL to serve the swagger UI
24-
SwaggerUrl string
24+
SwaggerURL string
2525
// Handler to serve the OpenAPI UI from spec URL
2626
UIHandler func(specURL string) http.Handler
2727
// URL to serve the OpenAPI JSON spec
28-
JsonUrl string
28+
JsonURL string
2929
}
3030

3131
var defaultOpenAPIConfig = OpenAPIConfig{
32-
SwaggerUrl: "/swagger",
33-
JsonUrl: "/swagger/openapi.json",
32+
SwaggerURL: "/swagger",
33+
JsonURL: "/swagger/openapi.json",
3434
UIHandler: DefaultOpenAPIHandler,
3535
EngineOpenAPIConfig: EngineOpenAPIConfig{
36-
JsonFilePath: "doc/openapi.json",
36+
JSONFilePath: "doc/openapi.json",
3737
},
3838
}
3939

server_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,45 +76,45 @@ func TestWithOpenAPIConfig(t *testing.T) {
7676
),
7777
)
7878

79-
require.Equal(t, "/swagger", s.OpenAPIConfig.SwaggerUrl)
80-
require.Equal(t, "/swagger/openapi.json", s.OpenAPIConfig.JsonUrl)
81-
require.Equal(t, "doc/openapi.json", s.OpenAPIConfig.JsonFilePath)
82-
require.False(t, s.OpenAPIConfig.PrettyFormatJson)
79+
require.Equal(t, "/swagger", s.OpenAPIConfig.SwaggerURL)
80+
require.Equal(t, "/swagger/openapi.json", s.OpenAPIConfig.JsonURL)
81+
require.Equal(t, "doc/openapi.json", s.OpenAPIConfig.JSONFilePath)
82+
require.False(t, s.OpenAPIConfig.PrettyFormatJSON)
8383
})
8484

8585
t.Run("with custom values", func(t *testing.T) {
8686
s := NewServer(
8787
WithEngineOptions(
8888
WithOpenAPIConfig(OpenAPIConfig{
89-
SwaggerUrl: "/api",
90-
JsonUrl: "/api/openapi.json",
89+
SwaggerURL: "/api",
90+
JsonURL: "/api/openapi.json",
9191
DisableSwagger: true,
9292
EngineOpenAPIConfig: EngineOpenAPIConfig{
93-
JsonFilePath: "openapi.json",
93+
JSONFilePath: "openapi.json",
9494
DisableLocalSave: true,
95-
PrettyFormatJson: true,
95+
PrettyFormatJSON: true,
9696
},
9797
}),
9898
),
9999
)
100100

101-
require.Equal(t, "/api", s.OpenAPIConfig.SwaggerUrl)
102-
require.Equal(t, "/api/openapi.json", s.OpenAPIConfig.JsonUrl)
103-
require.Equal(t, "openapi.json", s.OpenAPIConfig.JsonFilePath)
101+
require.Equal(t, "/api", s.OpenAPIConfig.SwaggerURL)
102+
require.Equal(t, "/api/openapi.json", s.OpenAPIConfig.JsonURL)
103+
require.Equal(t, "openapi.json", s.OpenAPIConfig.JSONFilePath)
104104
require.True(t, s.OpenAPIConfig.DisableSwagger)
105105
require.True(t, s.OpenAPIConfig.DisableLocalSave)
106-
require.True(t, s.OpenAPIConfig.PrettyFormatJson)
106+
require.True(t, s.OpenAPIConfig.PrettyFormatJSON)
107107
})
108108

109109
t.Run("with invalid local path values", func(t *testing.T) {
110110
t.Run("with invalid path", func(t *testing.T) {
111111
NewServer(
112112
WithEngineOptions(
113113
WithOpenAPIConfig(OpenAPIConfig{
114-
SwaggerUrl: "p i",
115-
JsonUrl: "pi/op enapi.json",
114+
SwaggerURL: "p i",
115+
JsonURL: "pi/op enapi.json",
116116
EngineOpenAPIConfig: EngineOpenAPIConfig{
117-
JsonFilePath: "path/to/jsonSpec",
117+
JSONFilePath: "path/to/jsonSpec",
118118
},
119119
}),
120120
),
@@ -124,10 +124,10 @@ func TestWithOpenAPIConfig(t *testing.T) {
124124
NewServer(
125125
WithEngineOptions(
126126
WithOpenAPIConfig(OpenAPIConfig{
127-
JsonUrl: "pi/op enapi.json",
128-
SwaggerUrl: "p i",
127+
JsonURL: "pi/op enapi.json",
128+
SwaggerURL: "p i",
129129
EngineOpenAPIConfig: EngineOpenAPIConfig{
130-
JsonFilePath: "path/to/jsonSpec.json",
130+
JSONFilePath: "path/to/jsonSpec.json",
131131
},
132132
}),
133133
),
@@ -138,10 +138,10 @@ func TestWithOpenAPIConfig(t *testing.T) {
138138
NewServer(
139139
WithEngineOptions(
140140
WithOpenAPIConfig(OpenAPIConfig{
141-
JsonUrl: "/api/openapi.json",
142-
SwaggerUrl: "invalid path",
141+
JsonURL: "/api/openapi.json",
142+
SwaggerURL: "invalid path",
143143
EngineOpenAPIConfig: EngineOpenAPIConfig{
144-
JsonFilePath: "path/to/jsonSpec.json",
144+
JSONFilePath: "path/to/jsonSpec.json",
145145
},
146146
}),
147147
),

0 commit comments

Comments
 (0)