Documentation
¶
Index ¶
- Constants
- Variables
- func CheckFragmentKind(f *os.File, kind FragmentKind) error
- 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 CustomErrorListener
- type DataType
- type DateOnlyShape
- type DateTimeOnlyShape
- type DateTimeShape
- type Definitions
- 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) Convert(s Shape) (*JSONSchema, error)
- func (c *JSONSchemaConverter) Visit(s Shape) *JSONSchema
- func (c *JSONSchemaConverter) VisitAnyShape(s *AnyShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitArrayShape(s *ArrayShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitBooleanShape(s *BooleanShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitDateOnlyShape(s *DateOnlyShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitDateTimeOnlyShape(s *DateTimeOnlyShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitDateTimeShape(s *DateTimeShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitFileShape(s *FileShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitIntegerShape(s *IntegerShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitJSONShape(s *JSONShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitNilShape(s *NilShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitNumberShape(s *NumberShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitObjectShape(s *ObjectShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitRecursiveShape(s *RecursiveShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitStringShape(s *StringShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitTimeOnlyShape(s *TimeOnlyShape) *JSONSchema
- func (c *JSONSchemaConverter) VisitUnionShape(s *UnionShape) *JSONSchema
- type JSONSchemaConverterOpt
- type JSONSchemaConverterOptions
- 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) 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
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 ( // TrueSchema defines a schema with a true value TrueSchema = &JSONSchema{boolean: &[]bool{true}[0]} // FalseSchema defines a schema with a false value FalseSchema = &JSONSchema{boolean: &[]bool{false}[0]} )
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 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 Definitions ¶
type Definitions map[string]*JSONSchema
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
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 {
Version string `json:"$schema,omitempty"`
ID string `json:"$id,omitempty"`
Ref string `json:"$ref,omitempty"`
Definitions Definitions `json:"definitions,omitempty"`
Comment string `json:"$comment,omitempty"`
AllOf []*JSONSchema `json:"allOf,omitempty"`
AnyOf []*JSONSchema `json:"anyOf,omitempty"`
OneOf []*JSONSchema `json:"oneOf,omitempty"`
Not *JSONSchema `json:"not,omitempty"`
If *JSONSchema `json:"if,omitempty"`
Then *JSONSchema `json:"then,omitempty"`
Else *JSONSchema `json:"else,omitempty"`
Items *JSONSchema `json:"items,omitempty"`
Properties *orderedmap.OrderedMap[string, *JSONSchema] `json:"properties,omitempty"`
PatternProperties *orderedmap.OrderedMap[string, *JSONSchema] `json:"patternProperties,omitempty"`
AdditionalProperties *bool `json:"additionalProperties,omitempty"`
PropertyNames *JSONSchema `json:"propertyNames,omitempty"`
Type string `json:"type,omitempty"`
Enum []any `json:"enum,omitempty"`
Const any `json:"const,omitempty"`
MultipleOf json.Number `json:"multipleOf,omitempty"`
Maximum json.Number `json:"maximum,omitempty"`
Minimum json.Number `json:"minimum,omitempty"`
MaxLength *uint64 `json:"maxLength,omitempty"`
MinLength *uint64 `json:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
MaxItems *uint64 `json:"maxItems,omitempty"`
MinItems *uint64 `json:"minItems,omitempty"`
UniqueItems *bool `json:"uniqueItems,omitempty"`
MaxContains *uint64 `json:"maxContains,omitempty"`
MinContains *uint64 `json:"minContains,omitempty"`
MaxProperties *uint64 `json:"maxProperties,omitempty"`
MinProperties *uint64 `json:"minProperties,omitempty"`
Required []string `json:"required,omitempty"`
ContentEncoding string `json:"contentEncoding,omitempty"`
ContentMediaType string `json:"contentMediaType,omitempty"`
Format string `json:"format,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Default any `json:"default,omitempty"`
Examples []any `json:"examples,omitempty"`
// TODO: There's no better way to serialize custom properties on the same level in Go.
Extras map[string]any `json:"x-custom,omitempty"`
// contains filtered or unexported fields
}
Schema represents a JSON Schema object type.
https://json-schema.org/draft-07/draft-handrews-json-schema-00.pdf
type JSONSchemaConverter ¶
type JSONSchemaConverter struct {
ShapeVisitor[JSONSchema]
// contains filtered or unexported fields
}
func NewJSONSchemaConverter ¶
func NewJSONSchemaConverter(opts ...JSONSchemaConverterOpt) *JSONSchemaConverter
func (*JSONSchemaConverter) Convert ¶
func (c *JSONSchemaConverter) Convert(s Shape) (*JSONSchema, error)
func (*JSONSchemaConverter) Visit ¶
func (c *JSONSchemaConverter) Visit(s Shape) *JSONSchema
func (*JSONSchemaConverter) VisitAnyShape ¶
func (c *JSONSchemaConverter) VisitAnyShape(s *AnyShape) *JSONSchema
func (*JSONSchemaConverter) VisitArrayShape ¶
func (c *JSONSchemaConverter) VisitArrayShape(s *ArrayShape) *JSONSchema
func (*JSONSchemaConverter) VisitBooleanShape ¶
func (c *JSONSchemaConverter) VisitBooleanShape(s *BooleanShape) *JSONSchema
func (*JSONSchemaConverter) VisitDateOnlyShape ¶
func (c *JSONSchemaConverter) VisitDateOnlyShape(s *DateOnlyShape) *JSONSchema
func (*JSONSchemaConverter) VisitDateTimeOnlyShape ¶
func (c *JSONSchemaConverter) VisitDateTimeOnlyShape(s *DateTimeOnlyShape) *JSONSchema
func (*JSONSchemaConverter) VisitDateTimeShape ¶
func (c *JSONSchemaConverter) VisitDateTimeShape(s *DateTimeShape) *JSONSchema
func (*JSONSchemaConverter) VisitFileShape ¶
func (c *JSONSchemaConverter) VisitFileShape(s *FileShape) *JSONSchema
func (*JSONSchemaConverter) VisitIntegerShape ¶
func (c *JSONSchemaConverter) VisitIntegerShape(s *IntegerShape) *JSONSchema
func (*JSONSchemaConverter) VisitJSONShape ¶
func (c *JSONSchemaConverter) VisitJSONShape(s *JSONShape) *JSONSchema
func (*JSONSchemaConverter) VisitNilShape ¶
func (c *JSONSchemaConverter) VisitNilShape(s *NilShape) *JSONSchema
func (*JSONSchemaConverter) VisitNumberShape ¶
func (c *JSONSchemaConverter) VisitNumberShape(s *NumberShape) *JSONSchema
func (*JSONSchemaConverter) VisitObjectShape ¶
func (c *JSONSchemaConverter) VisitObjectShape(s *ObjectShape) *JSONSchema
func (*JSONSchemaConverter) VisitRecursiveShape ¶
func (c *JSONSchemaConverter) VisitRecursiveShape(s *RecursiveShape) *JSONSchema
func (*JSONSchemaConverter) VisitStringShape ¶
func (c *JSONSchemaConverter) VisitStringShape(s *StringShape) *JSONSchema
func (*JSONSchemaConverter) VisitTimeOnlyShape ¶
func (c *JSONSchemaConverter) VisitTimeOnlyShape(s *TimeOnlyShape) *JSONSchema
func (*JSONSchemaConverter) VisitUnionShape ¶
func (c *JSONSchemaConverter) VisitUnionShape(s *UnionShape) *JSONSchema
type JSONSchemaConverterOpt ¶
type JSONSchemaConverterOpt interface {
Apply(*JSONSchemaConverterOptions)
}
func WithOmitRefs ¶
func WithOmitRefs(omitRefs bool) JSONSchemaConverterOpt
type JSONSchemaConverterOptions ¶
type JSONSchemaConverterOptions struct {
// contains filtered or unexported fields
}
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 and marks recursion in the shape.
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 ¶
func (r *RAML) MakeBaseShape(name string, location string, position *stacktrace.Position) *BaseShape
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.
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) 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 }