Skip to content

Commit 9ed7ae4

Browse files
authored
Merge pull request #216 from kaleido-io/open-api-version
expose option for openapi version
2 parents 5775c95 + 50bebf5 commit 9ed7ae4

2 files changed

Lines changed: 35 additions & 17 deletions

File tree

pkg/ffapi/openapi3.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ type SwaggerGenOptions struct {
4444
Version string
4545
Description string
4646

47+
OpenAPIVersion string
48+
4749
// descriptions for the route parameters are parsed from the ffstruct tags
4850
// when set this flag to true, if a description is not found, the generator will panic
4951
// this is useful to ensure that all fields are documented
@@ -113,8 +115,13 @@ func (sg *SwaggerGen) Generate(ctx context.Context, routes []*Route) *openapi3.T
113115
}
114116
}
115117

118+
openAPIVersion := "3.0.2"
119+
if sg.options.OpenAPIVersion != "" {
120+
openAPIVersion = sg.options.OpenAPIVersion
121+
}
122+
116123
doc := &openapi3.T{
117-
OpenAPI: "3.0.2",
124+
OpenAPI: openAPIVersion,
118125
Servers: openapi3.Servers{
119126
server,
120127
},

pkg/ffapi/openapi3_test.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,16 @@ var testRoutes = []*Route{
208208
Tag: example2TagName,
209209
},
210210
{
211-
Name: "op8",
212-
Path: "example8",
213-
Method: http.MethodGet,
214-
PathParams: nil,
215-
QueryParams: nil,
216-
Description: ExampleDesc,
217-
JSONInputValue: func() interface{} { return nil},
211+
Name: "op8",
212+
Path: "example8",
213+
Method: http.MethodGet,
214+
PathParams: nil,
215+
QueryParams: nil,
216+
Description: ExampleDesc,
217+
JSONInputValue: func() interface{} { return nil },
218218
JSONOutputValue: func() interface{} { return &TestExtensions{} },
219219
JSONOutputCodes: []int{http.StatusOK},
220220
},
221-
222221
}
223222

224223
type TestInOutType struct {
@@ -608,10 +607,10 @@ func TestExcludeFromOpenAPI(t *testing.T) {
608607
func TestExtensionsBadEncodingFail(t *testing.T) {
609608
routes := []*Route{
610609
{
611-
Name: "badEncoding",
612-
Path: "extensions",
613-
Method: http.MethodGet,
614-
JSONInputValue: func() interface{} { return nil },
610+
Name: "badEncoding",
611+
Path: "extensions",
612+
Method: http.MethodGet,
613+
JSONInputValue: func() interface{} { return nil },
615614
JSONOutputValue: func() interface{} { return &TestExtensionsBadEncoding{} },
616615
JSONOutputCodes: []int{http.StatusOK},
617616
},
@@ -629,10 +628,10 @@ func TestExtensionsBadEncodingFail(t *testing.T) {
629628
func TestExtensionsBadKeyFail(t *testing.T) {
630629
routes := []*Route{
631630
{
632-
Name: "bad3",
633-
Path: "extensions",
634-
Method: http.MethodGet,
635-
JSONInputValue: func() interface{} { return nil },
631+
Name: "bad3",
632+
Path: "extensions",
633+
Method: http.MethodGet,
634+
JSONInputValue: func() interface{} { return nil },
636635
JSONOutputValue: func() interface{} { return &TestExtensionsBadKey{} },
637636
JSONOutputCodes: []int{http.StatusOK},
638637
},
@@ -646,3 +645,15 @@ func TestExtensionsBadKeyFail(t *testing.T) {
646645
}).Generate(context.Background(), routes)
647646
})
648647
}
648+
649+
func TestOpenAPIVersion(t *testing.T) {
650+
doc := NewSwaggerGen(&SwaggerGenOptions{
651+
Title: "UnitTest",
652+
Version: "1.0",
653+
OpenAPIVersion: "3.1.1",
654+
BaseURL: "http://localhost:12345/api/v1",
655+
}).Generate(context.Background(), testRoutes)
656+
err := doc.Validate(context.Background())
657+
assert.NoError(t, err)
658+
assert.Equal(t, "3.1.1", doc.OpenAPI)
659+
}

0 commit comments

Comments
 (0)