Codebase list golang-github-go-openapi-analysis / 2eba222
ci update * re-enact golangci linter from ci * updated golangci config * fixed a few linting issue (on linters I didn't want to disable) Signed-off-by: Frederic BIDON <fredbi@yahoo.com> Frederic BIDON 3 years ago
9 changed file(s) with 57 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
77 maligned:
88 suggest-new: true
99 dupl:
10 threshold: 100
10 threshold: 150
1111 goconst:
1212 min-len: 2
1313 min-occurrences: 4
2929 - whitespace
3030 - wsl
3131 - funlen
32 - testpackage
33 - wrapcheck
34 - nlreturn
35 - gomnd
36 - goerr113
37 - exhaustivestruct
38 - errorlint
39 - nestif
40 - gofumpt
41 - godot
42 - gci
43 - dogsled
00 after_success:
11 - bash <(curl -s https://codecov.io/bash)
22 go:
3 - 1.13.x
43 - 1.14.x
4 - 1.x
55 arch:
66 - amd64
77 - ppc64le
211211 }
212212 }
213213 for path, pathItem := range s.AllPaths() {
214 s.analyzeOperations(path, &pathItem)
214 s.analyzeOperations(path, &pathItem) //#nosec
215215 }
216216
217217 for name, parameter := range s.spec.Parameters {
276276 for i, param := range op.Parameters {
277277 refPref := slashpath.Join("/paths", jsonpointer.Escape(path), "parameters", strconv.Itoa(i))
278278 if param.Ref.String() != "" {
279 s.references.addParamRef(refPref, &param)
279 s.references.addParamRef(refPref, &param) //#nosec
280280 }
281281 if param.Pattern != "" {
282282 s.patterns.addParameterPattern(refPref, param.Pattern)
334334 for i, param := range op.Parameters {
335335 refPref := slashpath.Join(prefix, "parameters", strconv.Itoa(i))
336336 if param.Ref.String() != "" {
337 s.references.addParamRef(refPref, &param)
337 s.references.addParamRef(refPref, &param) //#nosec
338338 }
339339 if param.Pattern != "" {
340340 s.patterns.addParameterPattern(refPref, param.Pattern)
367367 for k, res := range op.Responses.StatusCodeResponses {
368368 refPref := slashpath.Join(prefix, "responses", strconv.Itoa(k))
369369 if res.Ref.String() != "" {
370 s.references.addResponseRef(refPref, &res)
370 s.references.addResponseRef(refPref, &res) //#nosec
371371 }
372372 for k, v := range res.Headers {
373373 hRefPref := slashpath.Join(refPref, "headers", k)
664664 }
665665 for _, pi := range s.spec.Paths.Paths {
666666 if pi.Get != nil && pi.Get.ID == operationID {
667 return gatherParams(&pi, pi.Get)
667 return gatherParams(&pi, pi.Get) //#nosec
668668 }
669669 if pi.Head != nil && pi.Head.ID == operationID {
670 return gatherParams(&pi, pi.Head)
670 return gatherParams(&pi, pi.Head) //#nosec
671671 }
672672 if pi.Options != nil && pi.Options.ID == operationID {
673 return gatherParams(&pi, pi.Options)
673 return gatherParams(&pi, pi.Options) //#nosec
674674 }
675675 if pi.Post != nil && pi.Post.ID == operationID {
676 return gatherParams(&pi, pi.Post)
676 return gatherParams(&pi, pi.Post) //#nosec
677677 }
678678 if pi.Patch != nil && pi.Patch.ID == operationID {
679 return gatherParams(&pi, pi.Patch)
679 return gatherParams(&pi, pi.Patch) //#nosec
680680 }
681681 if pi.Put != nil && pi.Put.ID == operationID {
682 return gatherParams(&pi, pi.Put)
682 return gatherParams(&pi, pi.Put) //#nosec
683683 }
684684 if pi.Delete != nil && pi.Delete.ID == operationID {
685 return gatherParams(&pi, pi.Delete)
685 return gatherParams(&pi, pi.Delete) //#nosec
686686 }
687687 }
688688 return nil
290290 }
291291 }
292292
293 // nolint: unparam
293294 func assertRefExists(t testing.TB, data map[string]spec.Ref, key string) bool {
294295 if _, ok := data[key]; !ok {
295296 return assert.Fail(t, fmt.Sprintf("expected %q to exist in the ref bag", key))
297298 return true
298299 }
299300
301 // nolint: unparam
300302 func assertSchemaRefExists(t testing.TB, data map[string]SchemaRef, key string) bool {
301303 if _, ok := data[key]; !ok {
302304 return assert.Fail(t, fmt.Sprintf("expected %q to exist in schema ref bag", key))
339341 }
340342 }
341343
344 // nolint: unparam
342345 func assertPattern(t testing.TB, data map[string]string, key, pattern string) bool {
343346 if assert.Contains(t, data, key) {
344347 return assert.Equal(t, pattern, data[key])
422425 if assert.True(pt, ok) {
423426 pi.Parameters = pi.PathItemProps.Get.OperationProps.Parameters
424427 s.paramsAsMap(pi.Parameters, m, func(param spec.Parameter, err error) bool {
425 //pt.Logf("ERROR on %+v : %v", param, err)
428 // pt.Logf("ERROR on %+v : %v", param, err)
426429 e = append(e, err.Error())
427430 return true // Continue
428431 })
437440 if assert.True(pt, ok) {
438441 pi.Parameters = pi.PathItemProps.Get.OperationProps.Parameters
439442 s.paramsAsMap(pi.Parameters, m, func(param spec.Parameter, err error) bool {
440 //pt.Logf("ERROR on %+v : %v", param, err)
443 // pt.Logf("ERROR on %+v : %v", param, err)
441444 e = append(e, err.Error())
442445 return false // Bail out
443446 })
456459 if assert.True(pt, ok) {
457460 pi.Parameters = pi.PathItemProps.Get.OperationProps.Parameters
458461 s.paramsAsMap(pi.Parameters, m, func(param spec.Parameter, err error) bool {
459 //pt.Logf("ERROR on %+v : %v", param, err)
462 // pt.Logf("ERROR on %+v : %v", param, err)
460463 e = append(e, err.Error())
461464 return false // Bail out
462465 })
475478 if assert.True(pt, ok) {
476479 pi.Parameters = pi.PathItemProps.Get.OperationProps.Parameters
477480 s.paramsAsMap(pi.Parameters, m, func(param spec.Parameter, err error) bool {
478 //pt.Logf("ERROR on %+v : %v", param, err)
481 // pt.Logf("ERROR on %+v : %v", param, err)
479482 e = append(e, err.Error())
480483 return false // Bail out
481484 })
564567 pi, ok := s.spec.Paths.Paths["/fixture"]
565568 if ok {
566569 pi.Parameters = pi.PathItemProps.Get.OperationProps.Parameters
567 //func (s *Spec) ParametersFor(operationID string) []spec.Parameter {
570 // func (s *Spec) ParametersFor(operationID string) []spec.Parameter {
568571 s.ParametersFor("fixtureOp")
569572 }
570573 }
666669 require.Empty(t, reqs2[1][0].Scopes)
667670 require.Len(t, reqs2[2], 2)
668671 //
669 //require.Equal(t, reqs2[2][0].Name, "basic")
672 // require.Equal(t, reqs2[2][0].Name, "basic")
670673 require.Contains(t, reqs2[2], SecurityRequirement{Name: "basic", Scopes: []string{}})
671674 require.Empty(t, reqs2[2][0].Scopes)
672 //require.Equal(t, reqs2[2][1].Name, "apiKey")
675 // require.Equal(t, reqs2[2][1].Name, "apiKey")
673676 require.Contains(t, reqs2[2], SecurityRequirement{Name: "apiKey", Scopes: []string{}})
674677 require.Empty(t, reqs2[2][1].Scopes)
675678 }
813816
814817 schemaRefs := an.AllDefinitions()
815818 assert.Lenf(t, schemaRefs, 14, "Expected 14 schema definitions in this spec")
816 //for _, refs := range schemaRefs {
819 // for _, refs := range schemaRefs {
817820 // t.Logf("Schema Ref: %s (%s)", refs.Name, refs.Ref.String())
818 //}
821 // }
819822 schemaRefs = an.SchemasWithAllOf()
820823 assert.Lenf(t, schemaRefs, 1, "Expected 1 schema with AllOf definition in this spec")
821824
935938 }
936939 }
937940
941 // nolint: unparam
938942 func assertEnum(t testing.TB, data map[string][]interface{}, key string, enum []interface{}) bool {
939943 if assert.Contains(t, data, key) {
940944 return assert.Equal(t, enum, data[key])
4949 }
5050 }
5151 for k, v := range s.Responses {
52 FixEmptyDesc(&v)
52 FixEmptyDesc(&v) //#nosec
5353 s.Responses[k] = v
5454 }
5555 }
5959 func FixEmptyDescs(rs *spec.Responses) {
6060 FixEmptyDesc(rs.Default)
6161 for k, v := range rs.StatusCodeResponses {
62 FixEmptyDesc(&v)
62 FixEmptyDesc(&v) //#nosec
6363 rs.StatusCodeResponses[k] = v
6464 }
6565 }
10401040 return swag.ToJSONName(bn)
10411041 }
10421042 }
1043 return swag.ToJSONName(strings.Replace(u.Host, ".", " ", -1))
1043 return swag.ToJSONName(strings.ReplaceAll(u.Host, ".", " "))
10441044 }
10451045
10461046 func saveSchema(spec *swspec.Swagger, name string, schema *swspec.Schema) {
384384 assert.NoError(t, err)
385385
386386 bbb, _ := json.MarshalIndent(an.spec, "", " ")
387 //t.Logf("%s", string(bbb))
387 // t.Logf("%s", string(bbb))
388388 assert.JSONEq(t, `{
389389 "swagger": "2.0",
390390 "info": {
909909 spec.MustCreateRef("#/definitions/getSomeWhereIdDefaultBody"),
910910 },
911911 // maps:
912 //{"#/definitions/nestedThing/properties/record/items/2/allOf/1/additionalProperties",
913 //"#/definitions/nestedThingRecordItems2AllOf1/additionalProperties",
914 //spec.MustCreateRef("#/definitions/nestedThingRecordItems2AllOf1AdditionalProperties"),
912 // {"#/definitions/nestedThing/properties/record/items/2/allOf/1/additionalProperties",
913 // "#/definitions/nestedThingRecordItems2AllOf1/additionalProperties",
914 // spec.MustCreateRef("#/definitions/nestedThingRecordItems2AllOf1AdditionalProperties"),
915915 // },
916916
917 //{"#/definitions/nestedThing/properties/record/items/2/allOf/1",
918 //"#/definitions/nestedThingRecordItems2/allOf/1",
919 //spec.MustCreateRef("#/definitions/nestedThingRecordItems2AllOf1"),
920 //},
917 // {"#/definitions/nestedThing/properties/record/items/2/allOf/1",
918 // "#/definitions/nestedThingRecordItems2/allOf/1",
919 // spec.MustCreateRef("#/definitions/nestedThingRecordItems2AllOf1"),
920 // },
921921 {"#/definitions/nestedThing/properties/record/items/2/properties/name",
922922 "#/definitions/nestedThingRecordItems2/properties/name",
923923 spec.MustCreateRef("#/definitions/nestedThingRecordItems2Name"),
112112 if len(collisions) != 0 {
113113 t.Errorf("TestMixin: Expected 0 collisions, got %v\n%v", len(collisions), collisions)
114114 }
115 //bbb, _ := json.MarshalIndent(primary, "", " ")
116 //t.Log(string(bbb))
115 // bbb, _ := json.MarshalIndent(primary, "", " ")
116 // t.Log(string(bbb))
117117 }
118118
119119 func TestMixinFromNilPath(t *testing.T) {
132132 if len(primary.Paths.Paths) != 3 {
133133 t.Errorf("TestMixin: Expected 3 paths in merged, got %v\n", len(primary.Paths.Paths))
134134 }
135 //bbb, _ := json.MarshalIndent(primary.Paths.Paths, "", " ")
136 //t.Log(string(bbb))
135 // bbb, _ := json.MarshalIndent(primary.Paths.Paths, "", " ")
136 // t.Log(string(bbb))
137137 }
138138
139139 func TestMixinSwaggerProps(t *testing.T) {
149149 if len(collisions) != 1 {
150150 t.Errorf("TestMixin: Expected 1 collisions, got %v\n%v", len(collisions), collisions)
151151 }
152 //bbb, _ := json.MarshalIndent(primary, "", " ")
153 //t.Log(string(bbb))
152 // bbb, _ := json.MarshalIndent(primary, "", " ")
153 // t.Log(string(bbb))
154154 }
328328 _, err = Schema(SchemaOpts{Schema: &def, Root: sp, BasePath: bp})
329329 assert.Error(t, err, "expected an error here")
330330
331 //bbb, _ := json.MarshalIndent(def, "", " ")
332 //log.Printf(string(bbb))
331 // bbb, _ := json.MarshalIndent(def, "", " ")
332 // log.Printf(string(bbb))
333333 }
334334
335335 func TestSchemaAnalysis_EdgeCases(t *testing.T) {