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.
This commit is contained in:
Dave Shanley
2022-07-18 08:12:12 -04:00
parent 366862c071
commit 9db542f36c
11 changed files with 63 additions and 63 deletions

View File

@@ -1,4 +1,4 @@
package model
package datamodel
import (
_ "embed"

View File

@@ -1,4 +1,4 @@
package model
package datamodel
import (
"github.com/daveshanley/vacuum/utils"

View File

@@ -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"`
}

35
datamodel/spec.go Normal file
View File

@@ -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
}

View File

@@ -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,

View File

@@ -1,4 +1,4 @@
package model
package datamodel
import (
"github.com/stretchr/testify/assert"

View File

@@ -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"`
}

View File

@@ -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
}