From 9db542f36c106a8523b1838a1c50e52fa0266ff6 Mon Sep 17 00:00:00 2001 From: Dave Shanley Date: Mon, 18 Jul 2022 08:12:12 -0400 Subject: [PATCH] Renaming models to datamodel I over use this package name, it's going to create all kinds of conflicts in my apps, so this name is going to be slightly different. --- {model => datamodel}/model_utils.go | 2 +- {model => datamodel}/model_utils_test.go | 2 +- datamodel/reports/spectral.go | 23 ++++++++++++ {model => datamodel}/reports/statistics.go | 0 {model => datamodel}/schemas/oas3-schema.json | 0 .../schemas/swagger2-schema.json | 0 datamodel/spec.go | 35 +++++++++++++++++++ {model => datamodel}/spec_index.go | 4 +-- {model => datamodel}/spec_index_test.go | 2 +- model/reports/spectral.go | 23 ------------ model/spec.go | 35 ------------------- 11 files changed, 63 insertions(+), 63 deletions(-) rename {model => datamodel}/model_utils.go (99%) rename {model => datamodel}/model_utils_test.go (99%) create mode 100644 datamodel/reports/spectral.go rename {model => datamodel}/reports/statistics.go (100%) rename {model => datamodel}/schemas/oas3-schema.json (100%) rename {model => datamodel}/schemas/swagger2-schema.json (100%) create mode 100644 datamodel/spec.go rename {model => datamodel}/spec_index.go (99%) rename {model => datamodel}/spec_index_test.go (99%) delete mode 100644 model/reports/spectral.go delete mode 100644 model/spec.go diff --git a/model/model_utils.go b/datamodel/model_utils.go similarity index 99% rename from model/model_utils.go rename to datamodel/model_utils.go index 7ef3962..fa03b33 100644 --- a/model/model_utils.go +++ b/datamodel/model_utils.go @@ -1,4 +1,4 @@ -package model +package datamodel import ( _ "embed" diff --git a/model/model_utils_test.go b/datamodel/model_utils_test.go similarity index 99% rename from model/model_utils_test.go rename to datamodel/model_utils_test.go index 4b3fcfa..a3affce 100644 --- a/model/model_utils_test.go +++ b/datamodel/model_utils_test.go @@ -1,4 +1,4 @@ -package model +package datamodel import ( "github.com/daveshanley/vacuum/utils" diff --git a/datamodel/reports/spectral.go b/datamodel/reports/spectral.go new file mode 100644 index 0000000..b6fe38d --- /dev/null +++ b/datamodel/reports/spectral.go @@ -0,0 +1,23 @@ +package reports + +// SpectralReport represents a datamodel that can be deserialized into a spectral compatible output. +type SpectralReport struct { + Code string `json:"code" yaml:"code"` // the rule that was run + Path []string `json:"path" yaml:"path"` // the path to the item, broken down into a slice + Message string `json:"message" yaml:"message"` // the result message + Severity int `json:"severity" yaml:"severity"` // the severity reported + Range Range `json:"range" yaml:"range"` // the location of the issue in the spec. + Source string `json:"source" yaml:"source"` // the source of the report. +} + +// Range indicates the start and end of a report item +type Range struct { + Start RangeItem `json:"start" yaml:"start"` + End RangeItem `json:"end" yaml:"end"` +} + +// RangeItem indicates the line and character of a range. +type RangeItem struct { + Line int `json:"line" yaml:"line"` + Char int `json:"character" yaml:"character"` +} diff --git a/model/reports/statistics.go b/datamodel/reports/statistics.go similarity index 100% rename from model/reports/statistics.go rename to datamodel/reports/statistics.go diff --git a/model/schemas/oas3-schema.json b/datamodel/schemas/oas3-schema.json similarity index 100% rename from model/schemas/oas3-schema.json rename to datamodel/schemas/oas3-schema.json diff --git a/model/schemas/swagger2-schema.json b/datamodel/schemas/swagger2-schema.json similarity index 100% rename from model/schemas/swagger2-schema.json rename to datamodel/schemas/swagger2-schema.json diff --git a/datamodel/spec.go b/datamodel/spec.go new file mode 100644 index 0000000..d06e433 --- /dev/null +++ b/datamodel/spec.go @@ -0,0 +1,35 @@ +package datamodel + +import ( + "gopkg.in/yaml.v3" + "time" +) + +// SpecInfo represents information about a supplied specification. +type SpecInfo struct { + SpecType string `json:"type"` + Version string `json:"version"` + SpecFormat string `json:"format"` + SpecFileType string `json:"fileType"` + RootNode *yaml.Node `json:"-"` // reference to the root node of the spec. + SpecBytes *[]byte `json:"bytes"` // the original bytes + SpecJSONBytes *[]byte `json:"-"` // original bytes converted to JSON + SpecJSON *map[string]interface{} `json:"-"` // standard JSON map of original bytes + Error error `json:"-"` // something go wrong? + APISchema string `json:"-"` // API Schema for supplied spec type (2 or 3) + Generated time.Time `json:"-"` + jsonParsingChannel chan bool +} + +// SearchResult represents the position of a result in a specification. +type SearchResult struct { + Key string `json:"key"` + Line int `json:"line"` + Col int `json:"col"` +} + +// GetJSONParsingChannel returns a channel that will close once async JSON parsing is completed. +// This is required as rules may start executing before we're even done reading in the spec to JSON. +func (si SpecInfo) GetJSONParsingChannel() chan bool { + return si.jsonParsingChannel +} diff --git a/model/spec_index.go b/datamodel/spec_index.go similarity index 99% rename from model/spec_index.go rename to datamodel/spec_index.go index 0d9989e..e8c443b 100644 --- a/model/spec_index.go +++ b/datamodel/spec_index.go @@ -1,7 +1,7 @@ // Copyright 2022 Dave Shanley / Quobix // SPDX-License-Identifier: MIT -package model +package datamodel import ( "errors" @@ -249,7 +249,7 @@ func NewSpecIndex(rootNode *yaml.Node) *SpecIndex { runIndexFunction(countFuncs, &wg) // run as fast as we can. wg.Wait() - // these functions are aggregate and can only run once the rest of the model is ready + // these functions are aggregate and can only run once the rest of the datamodel is ready countFuncs = []func() int{ index.GetInlineUniqueParamCount, index.GetOperationTagsCount, diff --git a/model/spec_index_test.go b/datamodel/spec_index_test.go similarity index 99% rename from model/spec_index_test.go rename to datamodel/spec_index_test.go index 19d289d..8d84818 100644 --- a/model/spec_index_test.go +++ b/datamodel/spec_index_test.go @@ -1,4 +1,4 @@ -package model +package datamodel import ( "github.com/stretchr/testify/assert" diff --git a/model/reports/spectral.go b/model/reports/spectral.go deleted file mode 100644 index 57a8995..0000000 --- a/model/reports/spectral.go +++ /dev/null @@ -1,23 +0,0 @@ -package reports - -// SpectralReport represents a model that can be deserialized into a spectral compatible output. -type SpectralReport struct { - Code string `json:"code" yaml:"code"` // the rule that was run - Path []string `json:"path" yaml:"path"` // the path to the item, broken down into a slice - Message string `json:"message" yaml:"message"` // the result message - Severity int `json:"severity" yaml:"severity"` // the severity reported - Range Range `json:"range" yaml:"range"` // the location of the issue in the spec. - Source string `json:"source" yaml:"source"` // the source of the report. -} - -// Range indicates the start and end of a report item -type Range struct { - Start RangeItem `json:"start" yaml:"start"` - End RangeItem `json:"end" yaml:"end"` -} - -// RangeItem indicates the line and character of a range. -type RangeItem struct { - Line int `json:"line" yaml:"line"` - Char int `json:"character" yaml:"character"` -} diff --git a/model/spec.go b/model/spec.go deleted file mode 100644 index d283081..0000000 --- a/model/spec.go +++ /dev/null @@ -1,35 +0,0 @@ -package model - -import ( - "gopkg.in/yaml.v3" - "time" -) - -// SpecInfo represents information about a supplied specification. -type SpecInfo struct { - SpecType string `json:"type"` - Version string `json:"version"` - SpecFormat string `json:"format"` - SpecFileType string `json:"fileType"` - RootNode *yaml.Node `json:"-"` // reference to the root node of the spec. - SpecBytes *[]byte `json:"bytes"` // the original bytes - SpecJSONBytes *[]byte `json:"-"` // original bytes converted to JSON - SpecJSON *map[string]interface{} `json:"-"` // standard JSON map of original bytes - Error error `json:"-"` // something go wrong? - APISchema string `json:"-"` // API Schema for supplied spec type (2 or 3) - Generated time.Time `json:"-"` - jsonParsingChannel chan bool -} - -// SearchResult represents the position of a result in a specification. -type SearchResult struct { - Key string `json:"key"` - Line int `json:"line"` - Col int `json:"col"` -} - -// GetJSONParsingChannel returns a channel that will close once async JSON parsing is completed. -// This is required as rules may start executing before we're even done reading in the spec to JSON. -func (si SpecInfo) GetJSONParsingChannel() chan bool { - return si.jsonParsingChannel -}