Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix lint #19

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ linters-settings:
# Default: false
all: true


linters:
disable-all: true
enable:
Expand Down
176 changes: 112 additions & 64 deletions complex.go

Large diffs are not rendered by default.

43 changes: 37 additions & 6 deletions consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ var SetOfScalarTypes = map[string]struct{}{
}

var SetOfStringFacets = map[string]struct{}{
"minLength": {}, "maxLength": {}, "pattern": {},
FacetMinLength: {}, FacetMaxLength: {}, FacetPattern: {},
}

var SetOfNumberFacets = map[string]struct{}{
"minimum": {}, "maximum": {}, "multipleOf": {},
FacetMinimum: {}, FacetMaximum: {}, FacetMultipleOf: {},
}

var SetOfFileFacets = map[string]struct{}{
"fileTypes": {},
FacetFileTypes: {},
}

var SetOfObjectFacets = map[string]struct{}{
"properties": {}, "additionalProperties": {}, "minProperties": {},
"maxProperties": {}, "discriminator": {}, "discriminatorValue": {},
FacetProperties: {}, FacetAdditionalProperties: {}, FacetMinProperties: {},
FacetMaxProperties: {}, FacetDiscriminator: {}, FacetDiscriminatorValue: {},
}

var SetOfArrayFacets = map[string]struct{}{
"items": {}, "minItems": {}, "maxItems": {}, "uniqueItems": {},
FacetItems: {}, FacetMinItems: {}, FacetMaxItems: {}, FacetUniqueItems: {},
}

var SetOfNumberFormats = map[string]struct{}{
Expand Down Expand Up @@ -55,6 +55,7 @@ const (
TypeObject = "object"
TypeFile = "file"
TypeNil = "nil"
TypeNull = "null"
)

// Special non-standard types
Expand All @@ -63,3 +64,33 @@ const (
TypeJSON = "json" // Cannot be used in RAML
TypeComposite = "composite" // Cannot be used in RAML
)

const (
TagNull = "!!null"
TagInclude = "!include"
TagStr = "!!str"
TagTimestamp = "!!timestamp"
TagInt = "!!int"
)

const (
FacetFormat = "format"
FacetEnum = "enum"
FacetMinimum = "minimum"
FacetMaximum = "maximum"
FacetMultipleOf = "multipleOf"
FacetMinLength = "minLength"
FacetMaxLength = "maxLength"
FacetPattern = "pattern"
FacetFileTypes = "fileTypes"
FacetAdditionalProperties = "additionalProperties"
FacetProperties = "properties"
FacetMinProperties = "minProperties"
FacetMaxProperties = "maxProperties"
FacetItems = "items"
FacetMinItems = "minItems"
FacetMaxItems = "maxItems"
FacetUniqueItems = "uniqueItems"
FacetDiscriminator = "discriminator"
FacetDiscriminatorValue = "discriminatorValue"
)
23 changes: 13 additions & 10 deletions example.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,27 @@ func (r *RAML) makeExample(value *yaml.Node, name string, location string) (*Exa
for i := 0; i != len(value.Content); i += 2 {
node := value.Content[i]
valueNode := value.Content[i+1]
if IsCustomDomainExtensionNode(node.Value) {
name, de, err := r.unmarshalCustomDomainExtension(location, node, valueNode)
if err != nil {
return nil, StacktraceNewWrapped("unmarshal custom domain extension", err, location, WithNodePosition(valueNode))
}
ex.CustomDomainProperties.Set(name, de)
} else if node.Value == "strict" {
switch node.Value {
case "strict":
if err := valueNode.Decode(&ex.Strict); err != nil {
return nil, StacktraceNewWrapped("decode strict", err, location, WithNodePosition(valueNode))
}
} else if node.Value == "displayName" {
case "displayName":
if err := valueNode.Decode(&ex.DisplayName); err != nil {
return nil, StacktraceNewWrapped("decode displayName", err, location, WithNodePosition(valueNode))
}
} else if node.Value == "description" {
case "description":
if err := valueNode.Decode(&ex.Description); err != nil {
return nil, StacktraceNewWrapped("decode description", err, location, WithNodePosition(valueNode))
}
default:
if IsCustomDomainExtensionNode(node.Value) {
deName, de, err := r.unmarshalCustomDomainExtension(location, node, valueNode)
if err != nil {
return nil, StacktraceNewWrapped("unmarshal custom domain extension", err, location, WithNodePosition(valueNode))
}
ex.CustomDomainProperties.Set(deName, de)
}
}
}
n, err := r.makeRootNode(valueKey, location)
Expand All @@ -75,7 +78,7 @@ func (r *RAML) makeExample(value *yaml.Node, name string, location string) (*Exa

// Example represents an example of a shape
type Example struct {
Id string
ID string
Name string
DisplayName string
Description string
Expand Down
12 changes: 8 additions & 4 deletions extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type DomainExtension struct {
Id string
ID string
Name string
Extension *Node
DefinedBy *Shape
Expand All @@ -17,14 +17,18 @@ type DomainExtension struct {
raml *RAML
}

func (r *RAML) unmarshalCustomDomainExtension(location string, keyNode *yaml.Node, valueNode *yaml.Node) (string, *DomainExtension, error) {
func (r *RAML) unmarshalCustomDomainExtension(location string, keyNode *yaml.Node,
valueNode *yaml.Node,
) (string, *DomainExtension, error) {
name := keyNode.Value[1 : len(keyNode.Value)-1]
if name == "" {
return "", nil, stacktrace.New("annotation name must not be empty", location, WithNodePosition(keyNode))
return "", nil, stacktrace.New("annotation name must not be empty", location,
WithNodePosition(keyNode))
}
n, err := r.makeRootNode(valueNode, location)
if err != nil {
return "", nil, StacktraceNewWrapped("make node", err, location, WithNodePosition(valueNode))
return "", nil, StacktraceNewWrapped("make node", err, location,
WithNodePosition(valueNode))
}
de := &DomainExtension{
Name: name,
Expand Down
50 changes: 27 additions & 23 deletions fragment.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Fragment interface {

// Library is the RAML 1.0 Library
type Library struct {
Id string
ID string
Usage string
AnnotationTypes *orderedmap.OrderedMap[string, *Shape]
// TODO: Specific to API fragments. Not supported yet.
Expand All @@ -47,7 +47,7 @@ func (l *Library) GetLocation() string {
}

type LibraryLink struct {
Id string
ID string
Value string

Link *Library
Expand All @@ -66,14 +66,9 @@ func (l *Library) UnmarshalYAML(value *yaml.Node) error {
for i := 0; i != len(value.Content); i += 2 {
node := value.Content[i]
valueNode := value.Content[i+1]
if IsCustomDomainExtensionNode(node.Value) {
name, de, err := l.raml.unmarshalCustomDomainExtension(l.Location, node, valueNode)
if err != nil {
return StacktraceNewWrapped("unmarshal custom domain extension", err, l.Location, WithNodePosition(valueNode))
}
l.CustomDomainProperties.Set(name, de)
} else if node.Value == "uses" {
if valueNode.Tag == "!!null" {
switch node.Value {
case "uses":
if valueNode.Tag == TagNull {
continue
}

Expand All @@ -88,8 +83,8 @@ func (l *Library) UnmarshalYAML(value *yaml.Node) error {
Position: stacktrace.Position{Line: path.Line, Column: path.Column},
})
}
} else if node.Value == "types" {
if valueNode.Tag == "!!null" {
case "types":
if valueNode.Tag == TagNull {
continue
}

Expand All @@ -106,8 +101,8 @@ func (l *Library) UnmarshalYAML(value *yaml.Node) error {
l.raml.PutTypeIntoFragment(name, l.Location, shape)
l.raml.PutShapePtr(shape)
}
} else if node.Value == "annotationTypes" {
if valueNode.Tag == "!!null" {
case "annotationTypes":
if valueNode.Tag == TagNull {
continue
}

Expand All @@ -124,10 +119,18 @@ func (l *Library) UnmarshalYAML(value *yaml.Node) error {
l.raml.PutAnnotationTypeIntoFragment(name, l.Location, shape)
l.raml.PutShapePtr(shape)
}
} else if node.Value == "usage" {
case "usage":
if err := valueNode.Decode(&l.Usage); err != nil {
return StacktraceNewWrapped("parse usage: value node decode", err, l.Location, WithNodePosition(valueNode))
}
default:
if IsCustomDomainExtensionNode(node.Value) {
name, de, err := l.raml.unmarshalCustomDomainExtension(l.Location, node, valueNode)
if err != nil {
return StacktraceNewWrapped("unmarshal custom domain extension", err, l.Location, WithNodePosition(valueNode))
}
l.CustomDomainProperties.Set(name, de)
}
}
}

Expand All @@ -143,7 +146,7 @@ func (r *RAML) MakeLibrary(path string) *Library {

// DataType is the RAML 1.0 DataType
type DataType struct {
Id string
ID string
Usage string
Uses *orderedmap.OrderedMap[string, *LibraryLink]
Shape *Shape
Expand All @@ -167,11 +170,12 @@ func (dt *DataType) UnmarshalYAML(value *yaml.Node) error {
for i := 0; i != len(value.Content); i += 2 {
node := value.Content[i]
valueNode := value.Content[i+1]
if node.Value == "usage" {
switch node.Value {
case "usage":
dt.Usage = valueNode.Value
} else if node.Value == "uses" {
if valueNode.Tag == "!!null" {
continue
case "uses":
if valueNode.Tag == TagNull {
break
}

dt.Uses = orderedmap.New[string, *LibraryLink](len(valueNode.Content) / 2)
Expand All @@ -185,7 +189,7 @@ func (dt *DataType) UnmarshalYAML(value *yaml.Node) error {
Position: stacktrace.Position{Line: path.Line, Column: path.Column},
})
}
} else {
default:
shapeValue.Content = append(shapeValue.Content, node, valueNode)
}
}
Expand All @@ -204,7 +208,7 @@ func (r *RAML) MakeDataType(path string) *DataType {
}
}

func (r *RAML) MakeJsonDataType(value []byte, path string) (*DataType, error) {
func (r *RAML) MakeJSONDataType(value []byte, path string) (*DataType, error) {
dt := r.MakeDataType(path)
// Convert to yaml node to reuse the same data node creation interface
node := &yaml.Node{
Expand All @@ -230,7 +234,7 @@ func (r *RAML) MakeJsonDataType(value []byte, path string) (*DataType, error) {

// NamedExample is the RAML 1.0 NamedExample
type NamedExample struct {
Id string
ID string
Map *orderedmap.OrderedMap[string, *Example]

Location string
Expand Down
Loading
Loading