Documentation
¶
Index ¶
- Constants
- Variables
- func CheckFragmentKind(f *os.File, kind FragmentKind) error
- func CutLast(s, sep string) (string, string, bool)
- func CutReferenceName(refName string) (string, string, bool)
- func FixYamlError(err error) error
- func GetYamlError(err error) *yaml.TypeError
- func IsCustomDomainExtensionNode(name string) bool
- func NewNodePosition(node *yaml.Node) *stacktrace.Position
- func ReadHead(f io.ReadSeeker) (string, error)
- func ReadRawFile(path string) (io.ReadCloser, error)
- func StacktraceNew(msg string, location string, opts ...stacktrace.Option) *stacktrace.StackTrace
- func StacktraceNewWrapped(msg string, err error, location string, opts ...stacktrace.Option) *stacktrace.StackTrace
- func WithNodePosition(node *yaml.Node) stacktrace.Option
- type AnyShape
- type ArrayFacets
- type ArrayShape
- type BaseShape
- func (s *BaseShape) AliasTo(source *BaseShape) (*BaseShape, error)
- func (s *BaseShape) AppendRAMLHook(key HookKey, hook HookFunc)
- func (s *BaseShape) Check() error
- func (s *BaseShape) ClearRAMLHooks(key HookKey)
- func (s *BaseShape) Clone(clonedMap map[int64]*BaseShape) *BaseShape
- func (s *BaseShape) CloneDetached() *BaseShape
- func (s *BaseShape) CloneShallow() *BaseShape
- func (s *BaseShape) Inherit(sourceBase *BaseShape) (*BaseShape, error)
- func (s *BaseShape) IsUnwrapped() bool
- func (s *BaseShape) PrepenRAMLHook(key HookKey, hook HookFunc)
- func (s *BaseShape) RemoveRAMLHook(key HookKey, hook HookFunc)
- func (s *BaseShape) SetShape(shape Shape)
- func (s *BaseShape) SetUnwrapped()
- func (s *BaseShape) String() string
- func (s *BaseShape) Validate(v interface{}) error
- type BooleanShape
- type Copyable
- type CustomErrorListener
- type DataType
- type DateOnlyShape
- type DateTimeOnlyShape
- type DateTimeShape
- type DomainExtension
- type EnumFacets
- type Example
- type Examples
- type FileFacets
- type FileShape
- type FormatFacets
- type Fragment
- type FragmentKind
- type HookFunc
- type HookKey
- type IntegerFacets
- type IntegerShape
- type JSONSchema
- type JSONSchemaConverter
- func (c *JSONSchemaConverter[T]) Convert(s Shape) (T, error)
- func (c *JSONSchemaConverter[T]) Visit(s Shape) T
- func (c *JSONSchemaConverter[T]) VisitAnyShape(s *AnyShape) T
- func (c *JSONSchemaConverter[T]) VisitArrayShape(s *ArrayShape) T
- func (c *JSONSchemaConverter[T]) VisitBooleanShape(s *BooleanShape) T
- func (c *JSONSchemaConverter[T]) VisitDateOnlyShape(s *DateOnlyShape) T
- func (c *JSONSchemaConverter[T]) VisitDateTimeOnlyShape(s *DateTimeOnlyShape) T
- func (c *JSONSchemaConverter[T]) VisitDateTimeShape(s *DateTimeShape) T
- func (c *JSONSchemaConverter[T]) VisitFileShape(s *FileShape) T
- func (c *JSONSchemaConverter[T]) VisitIntegerShape(s *IntegerShape) T
- func (c *JSONSchemaConverter[T]) VisitJSONShape(s *JSONShape) T
- func (c *JSONSchemaConverter[T]) VisitNilShape(s *NilShape) T
- func (c *JSONSchemaConverter[T]) VisitNumberShape(s *NumberShape) T
- func (c *JSONSchemaConverter[T]) VisitObjectShape(s *ObjectShape) T
- func (c *JSONSchemaConverter[T]) VisitRecursiveShape(s *RecursiveShape) T
- func (c *JSONSchemaConverter[T]) VisitStringShape(s *StringShape) T
- func (c *JSONSchemaConverter[T]) VisitTimeOnlyShape(s *TimeOnlyShape) T
- func (c *JSONSchemaConverter[T]) VisitUnionShape(s *UnionShape) T
- type JSONSchemaConverterOpt
- type JSONSchemaConverterOptions
- type JSONSchemaGeneric
- type JSONSchemaRAML
- type JSONShape
- type LengthFacets
- type Library
- type LibraryLink
- type LocationGetter
- type MockShape
- type NamedExample
- type NilShape
- type Node
- type Nodes
- type NumberFacets
- type NumberShape
- type ObjectFacets
- type ObjectShape
- type ParseOpt
- type PatternProperty
- type Property
- type RAML
- func New(ctx context.Context) *RAML
- func ParseFromPath(path string, opts ...ParseOpt) (*RAML, error)
- func ParseFromPathCtx(ctx context.Context, path string, opts ...ParseOpt) (*RAML, error)
- func ParseFromString(content string, fileName string, baseDir string, opts ...ParseOpt) (*RAML, error)
- func ParseFromStringCtx(ctx context.Context, content string, fileName string, baseDir string, ...) (*RAML, error)
- func (r *RAML) AppendHook(key HookKey, hook HookFunc)
- func (r *RAML) ClearHooks(key HookKey)
- func (r *RAML) EntryPoint() Fragment
- func (r *RAML) FindAndMarkRecursion(base *BaseShape) (*BaseShape, error)
- func (r *RAML) GetAllAnnotations() []DomainExtension
- func (r *RAML) GetAllAnnotationsPtr() []*DomainExtension
- func (r *RAML) GetAnnotationTypeFromFragmentPtr(location string, typeName string) (*BaseShape, error)
- func (r *RAML) GetFragment(location string) Fragment
- func (r *RAML) GetFragmentTypePtrs(location string) map[string]*BaseShape
- func (r *RAML) GetLocation() string
- func (r *RAML) GetReferencedAnnotationType(refName string, location string) (*BaseShape, error)
- func (r *RAML) GetReferencedType(refName string, location string) (*BaseShape, error)
- func (r *RAML) GetShapes() []*BaseShape
- func (r *RAML) GetTypeFromFragmentPtr(location string, typeName string) (*BaseShape, error)
- func (r *RAML) MakeBaseShape(name string, location string, position stacktrace.Position) *BaseShape
- func (r *RAML) MakeConcreteShapeYAML(base *BaseShape, shapeType string, shapeFacets []*yaml.Node) (Shape, error)
- func (r *RAML) MakeDataType(path string) *DataType
- func (r *RAML) MakeEnum(v *yaml.Node, location string) (Nodes, error)
- func (r *RAML) MakeJSONDataType(value []byte, path string) (*DataType, error)
- func (r *RAML) MakeJSONShape(base *BaseShape, rawSchema string) (*JSONShape, error)
- func (r *RAML) MakeLibrary(path string) *Library
- func (r *RAML) MakeNamedExample(path string) *NamedExample
- func (r *RAML) MakeNewShape(name string, shapeType string, location string, position stacktrace.Position) (*BaseShape, Shape, error)
- func (r *RAML) MakeRecursiveShape(headBase *BaseShape) *BaseShape
- func (r *RAML) ParseFromPath(path string, opts ...ParseOpt) error
- func (r *RAML) ParseFromString(content string, fileName string, baseDir string, opts ...ParseOpt) error
- func (r *RAML) PrependHook(key HookKey, hook HookFunc)
- func (r *RAML) PutAnnotationTypeIntoFragment(name string, location string, shape *BaseShape)
- func (r *RAML) PutFragment(location string, fragment Fragment)
- func (r *RAML) PutShape(shape *BaseShape)
- func (r *RAML) PutTypeIntoFragment(name string, location string, shape *BaseShape)
- func (r *RAML) RemoveHook(key HookKey, hook HookFunc)
- func (r *RAML) SetEntryPoint(entryPoint Fragment) *RAML
- func (r *RAML) UnwrapShape(base *BaseShape) (*BaseShape, error)
- func (r *RAML) UnwrapShapes() error
- func (r *RAML) UnwrapTarget(target Shape) error
- func (r *RAML) ValidateShapes() error
- type RdtVisitor
- func (visitor *RdtVisitor) Visit(tree antlr.ParseTree, target *UnknownShape) (Shape, error)
- func (visitor *RdtVisitor) VisitArray(ctx *rdt.ArrayContext, target *UnknownShape) (Shape, error)
- func (visitor *RdtVisitor) VisitEntrypoint(ctx *rdt.EntrypointContext, target *UnknownShape) (Shape, error)
- func (visitor *RdtVisitor) VisitExpression(ctx *rdt.ExpressionContext, target *UnknownShape) (Shape, error)
- func (visitor *RdtVisitor) VisitGroup(ctx *rdt.GroupContext, target *UnknownShape) (Shape, error)
- func (visitor *RdtVisitor) VisitOptional(ctx *rdt.OptionalContext, target *UnknownShape) (Shape, error)
- func (visitor *RdtVisitor) VisitPrimitive(ctx *rdt.PrimitiveContext, target *UnknownShape) (Shape, error)
- func (visitor *RdtVisitor) VisitReference(ctx *rdt.ReferenceContext, target *UnknownShape) (Shape, error)
- func (visitor *RdtVisitor) VisitType(ctx *rdt.TypeContext, target *UnknownShape) (Shape, error)
- func (visitor *RdtVisitor) VisitUnion(ctx *rdt.UnionContext, target *UnknownShape) (Shape, error)
- func (visitor *RdtVisitor) VisitUnionMembers(node antlr.RuleNode, target *UnknownShape) ([]*BaseShape, error)
- type RecursiveShape
- type ReferenceAnnotationTypeGetter
- type ReferenceTypeGetter
- type Shape
- type ShapeAliaser
- type ShapeBaser
- type ShapeChecker
- type ShapeCloner
- type ShapeInheritor
- type ShapeSetter
- type ShapeValidator
- type ShapeVisitor
- type StringFacets
- type StringShape
- type TimeOnlyShape
- type UnionFacets
- type UnionShape
- type UnknownShape
- type Value
- type WrapperFunc
Constants ¶
const ( TypeAny = "any" TypeString = "string" TypeInteger = "integer" TypeNumber = "number" TypeBoolean = "boolean" TypeDatetime = "datetime" TypeDatetimeOnly = "datetime-only" TypeDateOnly = "date-only" TypeTimeOnly = "time-only" TypeArray = "array" TypeObject = "object" TypeFile = "file" TypeNil = "nil" TypeNull = "null" )
Standard types according to specification
const ( TypeUnion = "union" // Can be used in RAML TypeJSON = "json" // Cannot be used in RAML TypeComposite = "composite" // Cannot be used in RAML TypeRecursive = "recursive" // Cannot be used in RAML )
Special non-standard types
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" FacetDescription = "description" FacetDisplayName = "displayName" FacetStrict = "strict" FacetRequired = "required" FacetType = "type" FacetFacets = "facets" FacetExample = "example" FacetExamples = "examples" FacetDefault = "default" FacetAllowedTargets = "allowedTargets" )
const ( DateTimeFormatRFC3339 = "rfc3339" DateTimeFormatRFC2616 = "rfc2616" )
const ( FormatDateTime = "date-time" FormatDate = "date" FormatTime = "time" )
const ( StacktraceTypeUnwrapping stacktrace.Type = "unwrapping" StacktraceTypeResolving stacktrace.Type = "resolving" StacktraceTypeParsing stacktrace.Type = "parsing" StacktraceTypeValidating stacktrace.Type = "validating" StacktraceTypeReading stacktrace.Type = "reading" StacktraceTypeLoading stacktrace.Type = "loading" )
const ( RFC2616 = "Mon, 02 Jan 2006 15:04:05 GMT" // NOTE: time.DateTime uses "2006-01-02 15:04:05" format which is different from date-time defined in RAML spec. DateTime = "2006-01-02T15:04:05" )
const (
ExampleValue = "value"
)
const HookBeforeBaseShapeInherit = "BaseShape.Inherit"
const HookBeforeBaseShapeInheritUnionSource = "BaseShape.inheritUnionSource"
const HookBeforeBaseShapeInheritUnionTarget = "BaseShape.inheritUnionTarget"
const HookBeforeParseDataType = "before:RAML.parseDataType"
const HookBeforeRAMLMakeConcreteShapeYAML = "before:RAML.makeConcreteShapeYAML"
const HookBeforeRAMLMakeNewShapeYAML = "before:RAML.makeNewShapeYAML"
const JSONSchemaVersion = "http://json-schema.org/draft-07/schema"
Version is the JSON Schema version.
Variables ¶
var ErrNil error
var ErrValueKeyNotFound = errors.New("value key not found")
var SetOfDateTimeFormats = map[string]struct{}{
"rfc3339": {}, "rfc2616": {},
}
SetOfDateTimeFormats contains a set of date-time formats
var SetOfIntegerFormats = map[string]int8{
"int8": 0, "int16": 1, "int32": 2, "int": 2, "int64": 3, "long": 3,
}
SetOfIntegerFormats contains a set of integer formats
var SetOfNumberFormats = map[string]struct{}{
"float": {}, "double": {},
}
SetOfNumberFormats contains a set of number formats
var SetOfScalarTypes = map[string]struct{}{
TypeString: {}, TypeInteger: {}, TypeNumber: {}, TypeBoolean: {}, TypeDatetime: {}, TypeDatetimeOnly: {},
TypeDateOnly: {}, TypeTimeOnly: {}, TypeFile: {},
}
SetOfScalarTypes contains a set of scalar types
Functions ¶
func CheckFragmentKind ¶
func CheckFragmentKind(f *os.File, kind FragmentKind) error
func CutReferenceName ¶
CutReferenceName cuts a reference name into two parts: before and after the dot.
func FixYamlError ¶
FixYamlError fixes the yaml type error from the given error.
func GetYamlError ¶
GetYamlError returns the yaml type error from the given error. nil if the error is not a yaml type error.
func NewNodePosition ¶
func NewNodePosition(node *yaml.Node) *stacktrace.Position
NewNodePosition creates a new position from the given node.
func ReadHead ¶
func ReadHead(f io.ReadSeeker) (string, error)
ReadHead reads, reset file and returns the trimmed first line of a file.
func StacktraceNew ¶
func StacktraceNew(msg string, location string, opts ...stacktrace.Option) *stacktrace.StackTrace
func StacktraceNewWrapped ¶
func StacktraceNewWrapped(msg string, err error, location string, opts ...stacktrace.Option) *stacktrace.StackTrace
func WithNodePosition ¶
func WithNodePosition(node *yaml.Node) stacktrace.Option
WithNodePosition sets the position of the error to the position of the given node.
Types ¶
type ArrayFacets ¶
ArrayFacets contains constraints for array shapes.
type ArrayShape ¶
type ArrayShape struct {
*BaseShape
ArrayFacets
// contains filtered or unexported fields
}
ArrayShape represents an array shape.
type BaseShape ¶
type BaseShape struct {
Shape
ID int64
Name string
DisplayName *string
Description *string
// TODO: Move Type to underlying Shape
Type string
TypeLabel string // Used to store the label either the link or type value
Example *Example
Examples *Examples
Inherits []*BaseShape
Alias *BaseShape
Default *Node
Required *bool
// To support !include of DataType fragment
Link *DataType
// CustomShapeFacets is a map of custom facets with values
CustomShapeFacets *orderedmap.OrderedMap[string, *Node]
// CustomShapeFacetDefinitions is an object properties share the same syntax with custom shape facets.
CustomShapeFacetDefinitions *orderedmap.OrderedMap[string, Property]
// CustomDomainProperties is a map of custom annotations
CustomDomainProperties *orderedmap.OrderedMap[string, *DomainExtension]
// NOTE: Not thread safe and should be used only in one method simultaneously.
ShapeVisited bool
Location string
stacktrace.Position
// contains filtered or unexported fields
}
func (*BaseShape) AppendRAMLHook ¶
func (*BaseShape) ClearRAMLHooks ¶
func (*BaseShape) Clone ¶
Clone creates a deep copy of the shape.
Use this method to make a deep copy of the shape while preserving the relationships between shapes. Passed cloned map will be populated with cloned shape IDs that can be reused in subsequent Clone calls.
NOTE: If you need a completely independent copy of a shape, use CloneDetached method.
func (*BaseShape) CloneDetached ¶
CloneDetached creates a detached deep copy of the shape.
Detached copy makes a deep copy of the shape, including parents, links and aliases. This makes the copied shape and its references completely independent from the original tree.
NOTE: To avoid excessive memory copies and allocation, this method must be used only when an independent shape copy is required. Otherwise, use Clone method.
func (*BaseShape) CloneShallow ¶
CloneShallow creates a shallow copy of the shape.
func (*BaseShape) IsUnwrapped ¶
IsUnwrapped returns true if the shape is unwrapped.
func (*BaseShape) PrepenRAMLHook ¶
func (*BaseShape) RemoveRAMLHook ¶
func (*BaseShape) SetUnwrapped ¶
func (s *BaseShape) SetUnwrapped()
type BooleanShape ¶
type BooleanShape struct {
*BaseShape
EnumFacets
// contains filtered or unexported fields
}
func (*BooleanShape) Base ¶
func (s *BooleanShape) Base() *BaseShape
type Copyable ¶ added in v2.0.2
type Copyable[T any] interface { // DeepCopy creates a deep copy of the JSON Schema object. DeepCopy() T // Generic returns the generic JSON Schema object. ShallowCopy() T // Map returns the JSON Schema object as a map[string]any. // Implementers should return a map that is compatible for use in gojsonschema.NewRawLoader. Map() map[string]any }
type CustomErrorListener ¶
type CustomErrorListener struct {
*antlr.DefaultErrorListener // Embed default which ensures we fit the interface
Stacktrace *stacktrace.StackTrace
// contains filtered or unexported fields
}
func (*CustomErrorListener) SyntaxError ¶
func (c *CustomErrorListener) SyntaxError( _ antlr.Recognizer, offendingSymbol interface{}, _, _ int, msg string, _ antlr.RecognitionException, )
type DataType ¶
type DataType struct {
ID string
Usage string
Uses *orderedmap.OrderedMap[string, *LibraryLink]
Shape *BaseShape
Location string
// contains filtered or unexported fields
}
DataType is the RAML 1.0 DataType
func (*DataType) GetLocation ¶
func (*DataType) GetReferenceAnnotationType ¶
GetReferenceAnnotationType returns a reference annotation type by name, implementing the ReferenceAnnotationTypeGetter interface
func (*DataType) GetReferenceType ¶
GetReferenceType returns a reference type by name, implementing the ReferenceTypeGetter interface
type DateOnlyShape ¶
type DateOnlyShape struct {
*BaseShape
// contains filtered or unexported fields
}
func (*DateOnlyShape) Base ¶
func (s *DateOnlyShape) Base() *BaseShape
type DateTimeOnlyShape ¶
type DateTimeOnlyShape struct {
*BaseShape
// contains filtered or unexported fields
}
func (*DateTimeOnlyShape) Base ¶
func (s *DateTimeOnlyShape) Base() *BaseShape
type DateTimeShape ¶
type DateTimeShape struct {
*BaseShape
FormatFacets
// contains filtered or unexported fields
}
func (*DateTimeShape) Base ¶
func (s *DateTimeShape) Base() *BaseShape
type DomainExtension ¶
type EnumFacets ¶
type EnumFacets struct {
Enum Nodes
}
type Example ¶
type Example struct {
ID string
Name string
DisplayName string
Description string
Data *Node
Strict bool
CustomDomainProperties *orderedmap.OrderedMap[string, *DomainExtension]
Location string
stacktrace.Position
// contains filtered or unexported fields
}
Example represents an example of a shape
type Examples ¶
type Examples struct {
ID string
Map *orderedmap.OrderedMap[string, *Example]
// To support !include of NamedExample fragment
Link *NamedExample
Location string
stacktrace.Position
}
Examples represents a collection of examples.
type FileFacets ¶
type FileFacets struct {
FileTypes Nodes
}
type FileShape ¶
type FileShape struct {
*BaseShape
LengthFacets
FileFacets
// contains filtered or unexported fields
}
type FormatFacets ¶
type FormatFacets struct {
Format *string
}
type Fragment ¶
type Fragment interface {
LocationGetter
ReferenceTypeGetter
ReferenceAnnotationTypeGetter
}
type FragmentKind ¶
type FragmentKind int
const ( FragmentUnknown FragmentKind = iota - 1 FragmentLibrary FragmentDataType FragmentNamedExample )
func IdentifyFragment ¶
func IdentifyFragment(head string) (FragmentKind, error)
IdentifyFragment returns the kind of the fragment by its head.
type HookKey ¶
type HookKey string
const HookBeforeFindAndMarkRecursion HookKey = "RAML.FindAndMarkRecursion"
const HookBeforeUnwrapShape HookKey = "RAML.UnwrapShape"
const HookBeforeValidateDataType HookKey = "RAML.validateDataType"
const HookBeforeValidateDomainExtensions HookKey = "RAML.validateDomainExtensions"
const HookBeforeValidateExamples HookKey = "RAML.validateExamples"
const HookBeforeValidateFragments HookKey = "RAML.validateFragments"
const HookBeforeValidateLibrary HookKey = "RAML.validateLibrary"
const HookBeforeValidateObjectShape HookKey = "RAML.validateObjectShape"
const HookBeforeValidateShapeCommons HookKey = "RAML.validateShapeCommons"
const HookBeforeValidateShapeFacets HookKey = "RAML.validateShapeFacets"
const HookBeforeValidateShapes HookKey = "RAML.ValidateShapes"
const HookBeforeValidateTypes HookKey = "RAML.validateTypes"
type IntegerFacets ¶
type IntegerShape ¶
type IntegerShape struct {
*BaseShape
EnumFacets
FormatFacets
IntegerFacets
// contains filtered or unexported fields
}
func (*IntegerShape) Base ¶
func (s *IntegerShape) Base() *BaseShape
type JSONSchema ¶
type JSONSchema struct {
JSONSchemaGeneric[*JSONSchema] `yaml:",inline"`
}
Plain, spec‑only flavour – just an alias. It does not use pointer to embedded structure since it does not use wrapper function that would require a newJs.
func (*JSONSchema) DeepCopy ¶ added in v2.0.2
func (js *JSONSchema) DeepCopy() *JSONSchema
func (*JSONSchema) Generic ¶
func (js *JSONSchema) Generic() *JSONSchemaGeneric[*JSONSchema]
func (*JSONSchema) Map ¶ added in v2.0.2
func (js *JSONSchema) Map() map[string]any
func (*JSONSchema) ShallowCopy ¶ added in v2.0.2
func (js *JSONSchema) ShallowCopy() *JSONSchema
type JSONSchemaConverter ¶
type JSONSchemaConverter[T jsonSchemaWrapper[T]] struct {
ShapeVisitor[T]
// contains filtered or unexported fields
}
func NewJSONSchemaConverter ¶
func NewJSONSchemaConverter[T jsonSchemaWrapper[T]](opt ...JSONSchemaConverterOpt[T]) (*JSONSchemaConverter[T], error)
func (*JSONSchemaConverter[T]) Convert ¶
func (c *JSONSchemaConverter[T]) Convert(s Shape) (T, error)
func (*JSONSchemaConverter[T]) Visit ¶
func (c *JSONSchemaConverter[T]) Visit(s Shape) T
func (*JSONSchemaConverter[T]) VisitAnyShape ¶
func (c *JSONSchemaConverter[T]) VisitAnyShape(s *AnyShape) T
func (*JSONSchemaConverter[T]) VisitArrayShape ¶
func (c *JSONSchemaConverter[T]) VisitArrayShape(s *ArrayShape) T
func (*JSONSchemaConverter[T]) VisitBooleanShape ¶
func (c *JSONSchemaConverter[T]) VisitBooleanShape(s *BooleanShape) T
func (*JSONSchemaConverter[T]) VisitDateOnlyShape ¶
func (c *JSONSchemaConverter[T]) VisitDateOnlyShape(s *DateOnlyShape) T
func (*JSONSchemaConverter[T]) VisitDateTimeOnlyShape ¶
func (c *JSONSchemaConverter[T]) VisitDateTimeOnlyShape(s *DateTimeOnlyShape) T
func (*JSONSchemaConverter[T]) VisitDateTimeShape ¶
func (c *JSONSchemaConverter[T]) VisitDateTimeShape(s *DateTimeShape) T
func (*JSONSchemaConverter[T]) VisitFileShape ¶
func (c *JSONSchemaConverter[T]) VisitFileShape(s *FileShape) T
func (*JSONSchemaConverter[T]) VisitIntegerShape ¶
func (c *JSONSchemaConverter[T]) VisitIntegerShape(s *IntegerShape) T
func (*JSONSchemaConverter[T]) VisitJSONShape ¶
func (c *JSONSchemaConverter[T]) VisitJSONShape(s *JSONShape) T
func (*JSONSchemaConverter[T]) VisitNilShape ¶
func (c *JSONSchemaConverter[T]) VisitNilShape(s *NilShape) T
func (*JSONSchemaConverter[T]) VisitNumberShape ¶
func (c *JSONSchemaConverter[T]) VisitNumberShape(s *NumberShape) T
func (*JSONSchemaConverter[T]) VisitObjectShape ¶
func (c *JSONSchemaConverter[T]) VisitObjectShape(s *ObjectShape) T
func (*JSONSchemaConverter[T]) VisitRecursiveShape ¶
func (c *JSONSchemaConverter[T]) VisitRecursiveShape(s *RecursiveShape) T
func (*JSONSchemaConverter[T]) VisitStringShape ¶
func (c *JSONSchemaConverter[T]) VisitStringShape(s *StringShape) T
func (*JSONSchemaConverter[T]) VisitTimeOnlyShape ¶
func (c *JSONSchemaConverter[T]) VisitTimeOnlyShape(s *TimeOnlyShape) T
func (*JSONSchemaConverter[T]) VisitUnionShape ¶
func (c *JSONSchemaConverter[T]) VisitUnionShape(s *UnionShape) T
type JSONSchemaConverterOpt ¶
type JSONSchemaConverterOpt[T jsonSchemaWrapper[T]] interface {
// contains filtered or unexported methods
}
func WithWrapper ¶
func WithWrapper[T jsonSchemaWrapper[T]](f WrapperFunc[T]) JSONSchemaConverterOpt[T]
WithWrapper lets the caller provide a dialect wrapper.
type JSONSchemaConverterOptions ¶
type JSONSchemaConverterOptions[T jsonSchemaWrapper[T]] struct {
// contains filtered or unexported fields
}
type JSONSchemaGeneric ¶
type JSONSchemaGeneric[T Copyable[T]] struct { // TODO: Need to collect unknown "x-" annotations into a dict Version string `json:"$schema,omitempty" yaml:"$schema,omitempty"` ID string `json:"$id,omitempty" yaml:"$id,omitempty"` Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"` Comment string `json:"$comment,omitempty" yaml:"$comment,omitempty"` // Definitions hold schema definitions. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.26 // RFC draft-wright-json-schema-validation-00, section 5.26 Definitions map[string]T `json:"definitions,omitempty" yaml:"definitions,omitempty"` AllOf []T `json:"allOf,omitempty" yaml:"allOf,omitempty"` AnyOf []T `json:"anyOf,omitempty" yaml:"anyOf,omitempty"` OneOf []T `json:"oneOf,omitempty" yaml:"oneOf,omitempty"` Not T `json:"not,omitempty" yaml:"not,omitempty"` If T `json:"if,omitempty" yaml:"if,omitempty"` Then T `json:"then,omitempty" yaml:"then,omitempty"` Else T `json:"else,omitempty" yaml:"else,omitempty"` Items T `json:"items,omitempty" yaml:"items,omitempty"` Properties *orderedmap.OrderedMap[string, T] `json:"properties,omitempty" yaml:"properties,omitempty"` PatternProperties *orderedmap.OrderedMap[string, T] `json:"patternProperties,omitempty" yaml:"patternProperties,omitempty"` AdditionalProperties *bool `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"` PropertyNames T `json:"propertyNames,omitempty" yaml:"propertyNames,omitempty"` Type string `json:"type,omitempty" yaml:"type,omitempty"` Enum []any `json:"enum,omitempty" yaml:"enum,omitempty"` Const any `json:"const,omitempty" yaml:"const,omitempty"` MultipleOf json.Number `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"` Maximum json.Number `json:"maximum,omitempty" yaml:"maximum,omitempty"` Minimum json.Number `json:"minimum,omitempty" yaml:"minimum,omitempty"` MaxLength *uint64 `json:"maxLength,omitempty" yaml:"maxLength,omitempty"` MinLength *uint64 `json:"minLength,omitempty" yaml:"minLength,omitempty"` Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty"` MaxItems *uint64 `json:"maxItems,omitempty" yaml:"maxItems,omitempty"` MinItems *uint64 `json:"minItems,omitempty" yaml:"minItems,omitempty"` UniqueItems *bool `json:"uniqueItems,omitempty" yaml:"uniqueItems,omitempty"` MaxContains *uint64 `json:"maxContains,omitempty" yaml:"maxContains,omitempty"` MinContains *uint64 `json:"minContains,omitempty" yaml:"minContains,omitempty"` MaxProperties *uint64 `json:"maxProperties,omitempty" yaml:"maxProperties,omitempty"` MinProperties *uint64 `json:"minProperties,omitempty" yaml:"minProperties,omitempty"` Required []string `json:"required,omitempty" yaml:"required,omitempty"` ContentEncoding string `json:"contentEncoding,omitempty" yaml:"contentEncoding,omitempty"` ContentMediaType string `json:"contentMediaType,omitempty" yaml:"contentMediaType,omitempty"` Format string `json:"format,omitempty" yaml:"format,omitempty"` Title string `json:"title,omitempty" yaml:"title,omitempty"` Description string `json:"description,omitempty" yaml:"description,omitempty"` Default any `json:"default,omitempty" yaml:"default,omitempty"` Examples []any `json:"examples,omitempty" yaml:"examples,omitempty"` }
Schema represents a JSON Schema object type.
https://json-schema.org/draft-07/draft-handrews-json-schema-00.pdf
func (*JSONSchemaGeneric[T]) DeepCopy ¶ added in v2.0.2
func (js *JSONSchemaGeneric[T]) DeepCopy() *JSONSchemaGeneric[T]
func (*JSONSchemaGeneric[T]) Map ¶ added in v2.0.2
func (js *JSONSchemaGeneric[T]) Map() map[string]any
func (*JSONSchemaGeneric[T]) ShallowCopy ¶ added in v2.0.2
func (js *JSONSchemaGeneric[T]) ShallowCopy() *JSONSchemaGeneric[T]
type JSONSchemaRAML ¶
type JSONSchemaRAML struct {
JSONSchemaGeneric[*JSONSchemaRAML] `yaml:",inline"`
Annotations *orderedmap.OrderedMap[string, any] `json:"x-annotations,omitempty" yaml:"x-annotations,omitempty"`
FacetDefinitions *orderedmap.OrderedMap[string, *JSONSchemaRAML] `json:"x-facet-definitions,omitempty" yaml:"x-facet-definitions,omitempty"`
FacetData *orderedmap.OrderedMap[string, any] `json:"x-facet-data,omitempty" yaml:"x-facet-data,omitempty"`
}
func JSONSchemaWrapper ¶
func JSONSchemaWrapper(c *JSONSchemaConverter[*JSONSchemaRAML], core *JSONSchemaGeneric[*JSONSchemaRAML], b *BaseShape) *JSONSchemaRAML
func (*JSONSchemaRAML) DeepCopy ¶ added in v2.0.2
func (js *JSONSchemaRAML) DeepCopy() *JSONSchemaRAML
func (*JSONSchemaRAML) Generic ¶
func (js *JSONSchemaRAML) Generic() *JSONSchemaGeneric[*JSONSchemaRAML]
func (*JSONSchemaRAML) Map ¶ added in v2.0.2
func (js *JSONSchemaRAML) Map() map[string]any
func (*JSONSchemaRAML) ShallowCopy ¶ added in v2.0.2
func (js *JSONSchemaRAML) ShallowCopy() *JSONSchemaRAML
type JSONShape ¶
type JSONShape struct {
*BaseShape
Schema *JSONSchema
Raw string
// contains filtered or unexported fields
}
type LengthFacets ¶
type Library ¶
type Library struct {
ID string
Usage string
AnnotationTypes *orderedmap.OrderedMap[string, *BaseShape]
// TODO: Specific to API fragments. Not supported yet.
// ResourceTypes map[string]interface{} `yaml:"resourceTypes"`
Types *orderedmap.OrderedMap[string, *BaseShape]
Uses *orderedmap.OrderedMap[string, *LibraryLink]
CustomDomainProperties *orderedmap.OrderedMap[string, *DomainExtension]
Location string
// contains filtered or unexported fields
}
Library is the RAML 1.0 Library
func (*Library) GetLocation ¶
func (*Library) GetReferenceAnnotationType ¶
GetReferenceAnnotationType returns a reference annotation type by name, implementing the ReferenceAnnotationTypeGetter interface
func (*Library) GetReferenceType ¶
GetReferenceType returns a reference type by name, implementing the ReferenceTypeGetter interface
type LibraryLink ¶
type LocationGetter ¶
type LocationGetter interface {
GetLocation() string
}
type MockShape ¶
type MockShape struct {
BaseShape *BaseShape
MockInherit func(source Shape) (Shape, error)
MockCheck func() error
MockClone func(base *BaseShape, clonedMap map[int64]*BaseShape) Shape
MockValidate func(v interface{}, ctxPath string) error
MockUnmarshalYAMLNodes func(v []*yaml.Node) error
MockString func() string
MockIsScalar func() bool
MockProperty *string
}
MockShape is a mock implementation of the Shape interface
type NamedExample ¶
type NamedExample struct {
ID string
Map *orderedmap.OrderedMap[string, *Example]
Location string
// contains filtered or unexported fields
}
NamedExample is the RAML 1.0 NamedExample
func (*NamedExample) GetLocation ¶
func (ne *NamedExample) GetLocation() string
func (*NamedExample) GetReferenceAnnotationType ¶
func (ne *NamedExample) GetReferenceAnnotationType(_ string) (*BaseShape, error)
GetReferenceAnnotationType returns a reference annotation type by name, implementing the ReferenceAnnotationTypeGetter interface
func (*NamedExample) GetReferenceType ¶
func (ne *NamedExample) GetReferenceType(_ string) (*BaseShape, error)
GetReferenceType returns a reference type by name, implementing the ReferenceTypeGetter interface
func (*NamedExample) UnmarshalYAML ¶
func (ne *NamedExample) UnmarshalYAML(value *yaml.Node) error
type Node ¶
type Node struct {
ID string
Value any
Location string
stacktrace.Position
// contains filtered or unexported fields
}
type NumberFacets ¶
type NumberShape ¶
type NumberShape struct {
*BaseShape
EnumFacets
FormatFacets
NumberFacets
// contains filtered or unexported fields
}
func (*NumberShape) Base ¶
func (s *NumberShape) Base() *BaseShape
type ObjectFacets ¶
type ObjectFacets struct {
Discriminator *string
DiscriminatorValue any
AdditionalProperties *bool
Properties *orderedmap.OrderedMap[string, Property]
PatternProperties *orderedmap.OrderedMap[string, PatternProperty]
MinProperties *uint64
MaxProperties *uint64
}
ObjectFacets contains constraints for object shapes.
type ObjectShape ¶
type ObjectShape struct {
*BaseShape
ObjectFacets
// contains filtered or unexported fields
}
ObjectShape represents an object shape.
type ParseOpt ¶
type ParseOpt interface {
Apply(*parserOptions)
}
func OptWithUnwrap ¶
func OptWithUnwrap() ParseOpt
func OptWithValidate ¶
func OptWithValidate() ParseOpt
type PatternProperty ¶
type PatternProperty struct {
Pattern *regexp.Regexp
Base *BaseShape
// contains filtered or unexported fields
}
Property represents a pattern property of an object shape.
type Property ¶
type Property struct {
Name string
Base *BaseShape
Required bool
// contains filtered or unexported fields
}
Property represents a property of an object shape.
type RAML ¶
type RAML struct {
// contains filtered or unexported fields
}
RAML is a store for all fragments and shapes. WARNING: Not thread-safe
func ParseFromPathCtx ¶
func ParseFromString ¶
func ParseFromStringCtx ¶
func (*RAML) AppendHook ¶
func (*RAML) ClearHooks ¶
func (*RAML) EntryPoint ¶
EntryPoint returns the entry point of the RAML.
func (*RAML) FindAndMarkRecursion ¶
FindAndMarkRecursion finds recursive shapes and replaces them with RecursiveShape.
func (*RAML) GetAllAnnotations ¶
func (r *RAML) GetAllAnnotations() []DomainExtension
GetAllAnnotations returns all annotations.
func (*RAML) GetAllAnnotationsPtr ¶
func (r *RAML) GetAllAnnotationsPtr() []*DomainExtension
GetAllAnnotationsPtr returns all annotations as pointers.
func (*RAML) GetAnnotationTypeFromFragmentPtr ¶
func (r *RAML) GetAnnotationTypeFromFragmentPtr(location string, typeName string) (*BaseShape, error)
GetTypeFromFragmentPtr returns a shape from a fragment.
func (*RAML) GetFragment ¶
GetFragment returns a fragment.
func (*RAML) GetFragmentTypePtrs ¶
GetFragmentTypePtrs returns fragment shapes as pointers.
func (*RAML) GetLocation ¶
GetLocation returns the location of the RAML.
func (*RAML) GetReferencedAnnotationType ¶
func (*RAML) GetReferencedType ¶
func (*RAML) GetTypeFromFragmentPtr ¶
GetTypeFromFragmentPtr returns a shape from a fragment as a pointer.
func (*RAML) MakeBaseShape ¶
MakeBaseShape creates a new base shape which is a base for all shapes.
func (*RAML) MakeConcreteShapeYAML ¶
func (r *RAML) MakeConcreteShapeYAML(base *BaseShape, shapeType string, shapeFacets []*yaml.Node) (Shape, error)
MakeConcreteShapeYAML creates a new concrete shape and assigns it to the base shape.
func (*RAML) MakeDataType ¶
func (*RAML) MakeJSONDataType ¶
func (*RAML) MakeJSONShape ¶
func (*RAML) MakeLibrary ¶
func (*RAML) MakeNamedExample ¶
func (r *RAML) MakeNamedExample(path string) *NamedExample
func (*RAML) MakeNewShape ¶
func (*RAML) MakeRecursiveShape ¶
func (*RAML) ParseFromString ¶
func (*RAML) PrependHook ¶
func (*RAML) PutAnnotationTypeIntoFragment ¶
PutTypeIntoFragment puts a shape into a fragment.
func (*RAML) PutFragment ¶
PutFragment puts a fragment.
func (*RAML) PutTypeIntoFragment ¶
PutTypeIntoFragment puts a shape into a fragment.
func (*RAML) RemoveHook ¶
func (*RAML) SetEntryPoint ¶
SetEntryPoint sets the entry point of the RAML.
func (*RAML) UnwrapShape ¶
UnwrapShape recursively copies and unwraps a shape in-place. Use Clone() to create a copy of a shape if necessary. Note that this method removes information about links.
func (*RAML) UnwrapShapes ¶
UnwrapShapes unwraps all shapes in the RAML in-place.
func (*RAML) UnwrapTarget ¶ added in v2.0.3
func (*RAML) ValidateShapes ¶
type RdtVisitor ¶
type RdtVisitor struct {
rdt.BaserdtParserVisitor // Embedding the base visitor class
// contains filtered or unexported fields
}
RdtVisitor defines a struct that implements the visitor
func NewRdtVisitor ¶
func NewRdtVisitor(rml *RAML) *RdtVisitor
func (*RdtVisitor) Visit ¶
func (visitor *RdtVisitor) Visit(tree antlr.ParseTree, target *UnknownShape) (Shape, error)
func (*RdtVisitor) VisitArray ¶
func (visitor *RdtVisitor) VisitArray(ctx *rdt.ArrayContext, target *UnknownShape) (Shape, error)
func (*RdtVisitor) VisitEntrypoint ¶
func (visitor *RdtVisitor) VisitEntrypoint(ctx *rdt.EntrypointContext, target *UnknownShape) (Shape, error)
func (*RdtVisitor) VisitExpression ¶
func (visitor *RdtVisitor) VisitExpression(ctx *rdt.ExpressionContext, target *UnknownShape) (Shape, error)
func (*RdtVisitor) VisitGroup ¶
func (visitor *RdtVisitor) VisitGroup(ctx *rdt.GroupContext, target *UnknownShape) (Shape, error)
func (*RdtVisitor) VisitOptional ¶
func (visitor *RdtVisitor) VisitOptional(ctx *rdt.OptionalContext, target *UnknownShape) (Shape, error)
func (*RdtVisitor) VisitPrimitive ¶
func (visitor *RdtVisitor) VisitPrimitive(ctx *rdt.PrimitiveContext, target *UnknownShape) (Shape, error)
func (*RdtVisitor) VisitReference ¶
func (visitor *RdtVisitor) VisitReference(ctx *rdt.ReferenceContext, target *UnknownShape) (Shape, error)
func (*RdtVisitor) VisitType ¶
func (visitor *RdtVisitor) VisitType(ctx *rdt.TypeContext, target *UnknownShape) (Shape, error)
func (*RdtVisitor) VisitUnion ¶
func (visitor *RdtVisitor) VisitUnion(ctx *rdt.UnionContext, target *UnknownShape) (Shape, error)
func (*RdtVisitor) VisitUnionMembers ¶
func (visitor *RdtVisitor) VisitUnionMembers(node antlr.RuleNode, target *UnknownShape) ([]*BaseShape, error)
type RecursiveShape ¶
func (*RecursiveShape) Base ¶
func (s *RecursiveShape) Base() *BaseShape
type ReferenceTypeGetter ¶
type Shape ¶
type Shape interface {
// Inherit is a ShapeInheritor
ShapeInheritor
ShapeBaser
ShapeChecker
// ShapeCloner Clones the shape and its children and points to specified base shape.
ShapeCloner
ShapeAliaser
ShapeValidator
fmt.Stringer
IsScalar() bool
// contains filtered or unexported methods
}
Shape is the interface that represents a RAML shape.
type ShapeAliaser ¶
type ShapeAliaser interface {
// contains filtered or unexported methods
}
ShapeAliaser is the interface that provides alias implementation for a RAML shape.
type ShapeBaser ¶
type ShapeBaser interface {
Base() *BaseShape
}
ShapeBaser is the interface that represents a retriever of a base shape.
type ShapeChecker ¶
type ShapeChecker interface {
// contains filtered or unexported methods
}
type ShapeCloner ¶
type ShapeCloner interface {
// contains filtered or unexported methods
}
ShapeCloner is the interface that provide clone implementation for a RAML shape.
type ShapeInheritor ¶
type ShapeInheritor interface {
// contains filtered or unexported methods
}
ShapeInheritor is the interface that represents an inheritor of a RAML shape.
type ShapeSetter ¶
type ShapeSetter interface {
SetShape(Shape)
}
type ShapeValidator ¶
type ShapeValidator interface {
// contains filtered or unexported methods
}
ShapeValidator is the interface that represents a validator of a RAML shape.
type ShapeVisitor ¶
type ShapeVisitor[T any] interface { VisitObjectShape(s *ObjectShape) T VisitArrayShape(s *ArrayShape) T VisitStringShape(s *StringShape) T VisitNumberShape(s *NumberShape) T VisitIntegerShape(s *IntegerShape) T VisitBooleanShape(s *BooleanShape) T VisitFileShape(s *FileShape) T VisitUnionShape(s *UnionShape) T VisitDateTimeShape(s *DateTimeShape) T VisitDateTimeOnlyShape(s *DateTimeOnlyShape) T VisitDateOnlyShape(s *DateOnlyShape) T VisitTimeOnlyShape(s *TimeOnlyShape) T VisitRecursiveShape(s *RecursiveShape) T VisitJSONShape(s *JSONShape) T VisitAnyShape(s *AnyShape) T VisitNilShape(s *NilShape) T }
type StringFacets ¶
type StringFacets struct {
LengthFacets
Pattern *regexp.Regexp
}
type StringShape ¶
type StringShape struct {
*BaseShape
EnumFacets
StringFacets
// contains filtered or unexported fields
}
func (*StringShape) Base ¶
func (s *StringShape) Base() *BaseShape
type TimeOnlyShape ¶
type TimeOnlyShape struct {
*BaseShape
// contains filtered or unexported fields
}
func (*TimeOnlyShape) Base ¶
func (s *TimeOnlyShape) Base() *BaseShape
type UnionFacets ¶
type UnionFacets struct {
AnyOf []*BaseShape
}
UnionFacets contains constraints for union shapes.
type UnionShape ¶
type UnionShape struct {
*BaseShape
EnumFacets
UnionFacets
// contains filtered or unexported fields
}
UnionShape represents a union shape.
type UnknownShape ¶
type UnknownShape struct {
*BaseShape
// contains filtered or unexported fields
}
func (*UnknownShape) Base ¶
func (s *UnknownShape) Base() *BaseShape
type Value ¶
type Value[T any] struct { Value T stacktrace.Position }
type WrapperFunc ¶
type WrapperFunc[T jsonSchemaWrapper[T]] func(conv *JSONSchemaConverter[T], core *JSONSchemaGeneric[T], src *BaseShape) T
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package orderedmap implements an ordered map, i.e.
|
Package orderedmap implements an ordered map, i.e. |