mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-08 04:20:17 +00:00
More coverage tuning
This commit is contained in:
@@ -16,7 +16,7 @@ type DocumentConfiguration struct {
|
|||||||
BaseURL *url.URL
|
BaseURL *url.URL
|
||||||
|
|
||||||
// If resolving locally, the BasePath will be the root from which relative references will be resolved from.
|
// 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.
|
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.
|
// 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/v2"
|
||||||
"github.com/pb33f/libopenapi/datamodel/low/v3"
|
"github.com/pb33f/libopenapi/datamodel/low/v3"
|
||||||
"github.com/pb33f/libopenapi/what-changed/model"
|
"github.com/pb33f/libopenapi/what-changed/model"
|
||||||
"reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// CompareOpenAPIDocuments will compare left (original) and right (updated) OpenAPI 3+ documents and extract every change
|
// 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.
|
// or removed and which of those changes were breaking.
|
||||||
func CompareSwaggerDocuments(original, updated *v2.Swagger) *model.DocumentChanges {
|
func CompareSwaggerDocuments(original, updated *v2.Swagger) *model.DocumentChanges {
|
||||||
return model.CompareDocuments(original, updated)
|
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)
|
changes := CompareOpenAPIDocuments(origDoc, modDoc)
|
||||||
assert.Equal(t, 72, changes.TotalChanges())
|
assert.Equal(t, 72, changes.TotalChanges())
|
||||||
assert.Equal(t, 17, changes.TotalBreakingChanges())
|
assert.Equal(t, 17, changes.TotalBreakingChanges())
|
||||||
//
|
|
||||||
//out, _ := json.MarshalIndent(changes, "", " ")
|
//out, _ := json.MarshalIndent(changes, "", " ")
|
||||||
//_ = ioutil.WriteFile("outputv3.json", out, 0776)
|
//_ = ioutil.WriteFile("outputv3.json", out, 0776)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompareSwaggerDocuments(t *testing.T) {
|
func TestCompareSwaggerDocuments(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user