Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/ffapi/openapi3.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type SwaggerGenOptions struct {
Version string
Description string

OpenAPIVersion string

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

openAPIVersion := "3.0.2"
if sg.options.OpenAPIVersion != "" {
openAPIVersion = sg.options.OpenAPIVersion
}

doc := &openapi3.T{
OpenAPI: "3.0.2",
OpenAPI: openAPIVersion,
Servers: openapi3.Servers{
server,
},
Expand Down
43 changes: 27 additions & 16 deletions pkg/ffapi/openapi3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,16 @@ var testRoutes = []*Route{
Tag: example2TagName,
},
{
Name: "op8",
Path: "example8",
Method: http.MethodGet,
PathParams: nil,
QueryParams: nil,
Description: ExampleDesc,
JSONInputValue: func() interface{} { return nil},
Name: "op8",
Path: "example8",
Method: http.MethodGet,
PathParams: nil,
QueryParams: nil,
Description: ExampleDesc,
JSONInputValue: func() interface{} { return nil },
JSONOutputValue: func() interface{} { return &TestExtensions{} },
JSONOutputCodes: []int{http.StatusOK},
},

}

type TestInOutType struct {
Expand Down Expand Up @@ -608,10 +607,10 @@ func TestExcludeFromOpenAPI(t *testing.T) {
func TestExtensionsBadEncodingFail(t *testing.T) {
routes := []*Route{
{
Name: "badEncoding",
Path: "extensions",
Method: http.MethodGet,
JSONInputValue: func() interface{} { return nil },
Name: "badEncoding",
Path: "extensions",
Method: http.MethodGet,
JSONInputValue: func() interface{} { return nil },
JSONOutputValue: func() interface{} { return &TestExtensionsBadEncoding{} },
JSONOutputCodes: []int{http.StatusOK},
},
Expand All @@ -629,10 +628,10 @@ func TestExtensionsBadEncodingFail(t *testing.T) {
func TestExtensionsBadKeyFail(t *testing.T) {
routes := []*Route{
{
Name: "bad3",
Path: "extensions",
Method: http.MethodGet,
JSONInputValue: func() interface{} { return nil },
Name: "bad3",
Path: "extensions",
Method: http.MethodGet,
JSONInputValue: func() interface{} { return nil },
JSONOutputValue: func() interface{} { return &TestExtensionsBadKey{} },
JSONOutputCodes: []int{http.StatusOK},
},
Expand All @@ -646,3 +645,15 @@ func TestExtensionsBadKeyFail(t *testing.T) {
}).Generate(context.Background(), routes)
})
}

func TestOpenAPIVersion(t *testing.T) {
doc := NewSwaggerGen(&SwaggerGenOptions{
Title: "UnitTest",
Version: "1.0",
OpenAPIVersion: "3.1.1",
BaseURL: "http://localhost:12345/api/v1",
}).Generate(context.Background(), testRoutes)
err := doc.Validate(context.Background())
assert.NoError(t, err)
assert.Equal(t, "3.1.1", doc.OpenAPI)
}
Loading