From 1bc04418dbb9df31db96e55fed764bc7438dc894 Mon Sep 17 00:00:00 2001 From: Dave Shanley Date: Sun, 26 Mar 2023 06:04:11 -0400 Subject: [PATCH] More coverage tuning --- datamodel/document_config.go | 2 +- datamodel/document_config_test.go | 21 +++++++++++++++++++++ what-changed/what_changed.go | 21 --------------------- what-changed/what_changed_test.go | 2 -- 4 files changed, 22 insertions(+), 24 deletions(-) create mode 100644 datamodel/document_config_test.go diff --git a/datamodel/document_config.go b/datamodel/document_config.go index 04cc44a..dac840d 100644 --- a/datamodel/document_config.go +++ b/datamodel/document_config.go @@ -16,7 +16,7 @@ type DocumentConfiguration struct { BaseURL *url.URL // If resolving locally, the BasePath will be the root from which relative references will be resolved from. - // It usually location of the root specification. + // It's usually the location of the root specification. BasePath string // set the Base Path for resolving relative references if the spec is exploded. // AllowFileReferences will allow the index to locate relative file references. This is disabled by default. diff --git a/datamodel/document_config_test.go b/datamodel/document_config_test.go new file mode 100644 index 0000000..89a7136 --- /dev/null +++ b/datamodel/document_config_test.go @@ -0,0 +1,21 @@ +// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley +// SPDX-License-Identifier: MIT + +package datamodel + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestNewClosedDocumentConfiguration(t *testing.T) { + cfg := NewClosedDocumentConfiguration() + assert.False(t, cfg.AllowRemoteReferences) + assert.False(t, cfg.AllowFileReferences) +} + +func TestNewOpenDocumentConfiguration(t *testing.T) { + cfg := NewOpenDocumentConfiguration() + assert.True(t, cfg.AllowRemoteReferences) + assert.True(t, cfg.AllowFileReferences) +} diff --git a/what-changed/what_changed.go b/what-changed/what_changed.go index ad94cf3..e8c1871 100644 --- a/what-changed/what_changed.go +++ b/what-changed/what_changed.go @@ -19,7 +19,6 @@ import ( "github.com/pb33f/libopenapi/datamodel/low/v2" "github.com/pb33f/libopenapi/datamodel/low/v3" "github.com/pb33f/libopenapi/what-changed/model" - "reflect" ) // CompareOpenAPIDocuments will compare left (original) and right (updated) OpenAPI 3+ documents and extract every change @@ -34,24 +33,4 @@ func CompareOpenAPIDocuments(original, updated *v3.Document) *model.DocumentChan // or removed and which of those changes were breaking. func CompareSwaggerDocuments(original, updated *v2.Swagger) *model.DocumentChanges { return model.CompareDocuments(original, updated) -} - -func ExtractFlatChanges(changes *model.DocumentChanges) []*model.Change { - return extractChanges(changes) -} - -func extractChanges(anything any) []*model.Change { - - vo := reflect.ValueOf(anything) - switch vo.Kind() { - case reflect.Ptr: - extractChanges(vo.Elem().Interface()) - case reflect.Slice: - - panic("slice not supported") - - case reflect.Struct: - extractChanges(vo.Elem().Interface()) - } - return nil } \ No newline at end of file diff --git a/what-changed/what_changed_test.go b/what-changed/what_changed_test.go index 3e69fd8..2f13ac9 100644 --- a/what-changed/what_changed_test.go +++ b/what-changed/what_changed_test.go @@ -26,10 +26,8 @@ func TestCompareOpenAPIDocuments(t *testing.T) { changes := CompareOpenAPIDocuments(origDoc, modDoc) assert.Equal(t, 72, changes.TotalChanges()) assert.Equal(t, 17, changes.TotalBreakingChanges()) - // //out, _ := json.MarshalIndent(changes, "", " ") //_ = ioutil.WriteFile("outputv3.json", out, 0776) - } func TestCompareSwaggerDocuments(t *testing.T) {