Skip to content

Commit

Permalink
fix: openapi spec generation
Browse files Browse the repository at this point in the history
  • Loading branch information
lvlcn-t committed Jun 9, 2024
1 parent 3d44eed commit c07e4f0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/checks/oapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func TestOpenapiFromPerfData(t *testing.T) {
args: args[string]{perfData: "hello world"},
want: &openapi3.SchemaRef{
Value: openapi3.NewObjectSchema().WithProperties(map[string]*openapi3.Schema{
"data": {Type: "string"},
"data": {Type: openapi3.NewStringSchema().Type},
"timestamp": {
Type: "string",
Type: openapi3.NewStringSchema().Type,
Format: "date-time",
},
}),
Expand Down
18 changes: 11 additions & 7 deletions pkg/sparrow/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ var oapiBoilerplate = openapi3.T{
Name: "CaaS Team",
},
},
Paths: make(openapi3.Paths),
Paths: &openapi3.Paths{
Extensions: make(map[string]any),
},
Extensions: make(map[string]any),
Components: &openapi3.Components{
Schemas: make(openapi3.Schemas),
Expand All @@ -202,16 +204,18 @@ func (cc *ChecksController) GenerateCheckSpecs(ctx context.Context) (openapi3.T,

routeDesc := fmt.Sprintf("Returns the performance data for check %s", name)
bodyDesc := fmt.Sprintf("Metrics for check %s", name)
doc.Paths["/v1/metrics/"+name] = &openapi3.PathItem{
doc.Paths.Extensions["/v1/metrics/"+name] = &openapi3.PathItem{
Description: name,
Get: &openapi3.Operation{
Description: routeDesc,
Tags: []string{"Metrics", name},
Responses: openapi3.Responses{
fmt.Sprint(http.StatusOK): &openapi3.ResponseRef{
Value: &openapi3.Response{
Description: &bodyDesc,
Content: openapi3.NewContentWithSchemaRef(ref, []string{"application/json"}),
Responses: &openapi3.Responses{
Extensions: map[string]any{
fmt.Sprint(http.StatusOK): &openapi3.ResponseRef{
Value: &openapi3.Response{
Description: &bodyDesc,
Content: openapi3.NewContentWithSchemaRef(ref, []string{"application/json"}),
},
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/sparrow/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func TestGenerateCheckSpecs(t *testing.T) {
name string
}
res := CheckResultSpec{name: "check1"}
return checks.OpenapiFromPerfData[CheckResultSpec](res)
return checks.OpenapiFromPerfData(res)
},
},
&checks.CheckMock{
Expand All @@ -315,16 +315,16 @@ func TestGenerateCheckSpecs(t *testing.T) {
name string
}
res := CheckResultSpec{name: "check2"}
return checks.OpenapiFromPerfData[CheckResultSpec](res)
return checks.OpenapiFromPerfData(res)
},
},
},
wantErr: false,
validate: func(t *testing.T, doc openapi3.T) {
if _, ok := doc.Paths["/v1/metrics/check1"]; !ok {
if _, ok := doc.Paths.Extensions["/v1/metrics/check1"]; !ok {
t.Errorf("Expected path '/v1/metrics/check1' not found")
}
if _, ok := doc.Paths["/v1/metrics/check2"]; !ok {
if _, ok := doc.Paths.Extensions["/v1/metrics/check2"]; !ok {
t.Errorf("Expected path '/v1/metrics/check2' not found")
}
},
Expand Down

0 comments on commit c07e4f0

Please sign in to comment.