Documentation
¶
Index ¶
Constants ¶
const Wildcard = "-"
Wildcard represents the character that matches any value for hints.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Discriminator ¶
type Discriminator struct { Discriminator string Mapping map[string]*InferredSchema }
Discriminator represents discriminators for the schema.
type HintSet ¶
type HintSet struct {
Values [][]string
}
HintSet represents a list of paths (lists) to match for hints.
func (HintSet) PeekActive ¶
PeekActive returns the currently active value if any. The returned boolean tells if a value was found.
type Hints ¶
Hints contains the default number type to use and all the hints for enums, values and discriminators.
func (Hints) IsEnumActive ¶
IsEnumActive checks if the enum hint set is active.
func (Hints) IsValuesActive ¶
IsValuesActive checks if the values hint set is active.
func (Hints) PeekActiveDiscriminator ¶
PeekActiveDiscriminator will peek the currently active discriminator, if any. The returned boolean tells if there is an active discriminator.
type InferredNumber ¶
InferredNumber represents the state for a column that is a number. It holds the seen maximum and minimum value together with information about if all seen numbers are integers.
func (*InferredNumber) ContainedBy ¶
func (i *InferredNumber) ContainedBy(nt NumType) bool
ContainedBy checks if an inferred number column can be contained within the passed `NumType`, meaning it is above the minimum and below the maximum value for the number type.
func (*InferredNumber) Infer ¶
func (i *InferredNumber) Infer(n float64) *InferredNumber
Infer will infer a value, updating the state for the `InferredNumber`.
type InferredSchema ¶
type InferredSchema struct { SchemaType SchemaType Number *InferredNumber Enum map[string]struct{} Array *InferredSchema Properties Properties Values *InferredSchema Discriminator Discriminator Nullable *InferredSchema }
InferredSchema is the schema while being inferred that holds information about fields.
func NewInferredSchema ¶
func NewInferredSchema() *InferredSchema
NewInferredSchema will return a new, empty, `InferredSchema`.
func (*InferredSchema) Infer ¶
func (i *InferredSchema) Infer(value any, hints Hints) *InferredSchema
Infer will infer the schema by trying to mimic the way it's implemented in the Rust implementation at https://github.com/jsontypedef/json-typedef-infer/blob/master/src/inferred_schema.rs. Since we don't have enums of this kind in Go we're using a struct with pointers to a schema instead of wrapping the enums.
func (*InferredSchema) IntoSchema ¶
func (i *InferredSchema) IntoSchema(hints Hints) Schema
IntoSchema will convert an `InferredSchema` to a final `Schema`.
type Inferrer ¶
type Inferrer struct { Inference *InferredSchema Hints Hints }
Inferrer represents the `InferredSchema` with its state combined with the hints used when inferring.
func InferStrings ¶
InferStrings accepts a slice of strings and will try to JSON unmarshal each row. If an error occurs the inferrer will return with the state it had when the error occurred. If you already have the type of your data such as a slice of numbers or a map of strings you can pass them directly to `Infer`. This is just a convenience method if all you got is strings.
func NewInferrer ¶
NewInferrer will create a new inferrer with a default `InferredSchema`.
func (*Inferrer) IntoSchema ¶
IntoSchema will convert the `InferredSchema` into a final `Schema`.
type NumType ¶
type NumType uint8
NumType represents the type of number a number should be represented in the JTD.
const ( NumTypeUint8 NumType = iota NumTypeInt8 NumTypeUint16 NumTypeInt16 NumTypeUint32 NumTypeInt32 NumTypeFloat32 NumTypeFloat64 )
Available number types.
type Properties ¶
type Properties struct { Required map[string]*InferredSchema Optional map[string]*InferredSchema }
Properties represents all required and optional properties which is the same as JSON objects.
type Schema ¶
type Schema struct { Definitions map[string]Schema `json:"definitions,omitempty"` Metadata map[string]interface{} `json:"metadata,omitempty"` Nullable bool `json:"nullable,omitempty"` Ref *string `json:"ref,omitempty"` Type jtd.Type `json:"type,omitempty"` Enum []string `json:"enum,omitempty"` Elements *Schema `json:"elements,omitempty"` Properties map[string]Schema `json:"properties,omitempty"` OptionalProperties map[string]Schema `json:"optionalProperties,omitempty"` AdditionalProperties bool `json:"additionalProperties,omitempty"` Values *Schema `json:"values,omitempty"` Discriminator string `json:"discriminator,omitempty"` Mapping map[string]Schema `json:"mapping,omitempty"` }
Schema represents the JTD schema that will get inferred. It's a hard copy of the upstream type since we want and need to be able to omit empty fields. Ref: https://github.com/jsontypedef/json-typedef-go/issues/7
type SchemaType ¶
type SchemaType int8
SchemaType represents the type of schema element. It will map to the available types for JTD.
const ( SchemaTypeUnknown SchemaType = iota SchemaTypeAny SchemaTypeBoolean SchemaTypeNumber SchemaTypeString SchemaTypeTimestmap SchemaTypeEnum SchemaTypeArray SchemaTypeProperties SchemaTypeValues SchemaTypeDiscriminator SchemaTypeNullable )
Available schema types.