mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-08 12:37:49 +00:00
More coverage tuning
This commit is contained in:
@@ -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.
|
||||
|
||||
21
datamodel/document_config_test.go
Normal file
21
datamodel/document_config_test.go
Normal file
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
@@ -35,23 +34,3 @@ func CompareOpenAPIDocuments(original, updated *v3.Document) *model.DocumentChan
|
||||
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
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user