Documentation
¶
Overview ¶
Package nvueschema extracts and generates config schemas from Cumulus Linux NVUE OpenAPI specs.
Index ¶
- Constants
- func ConfigLeafPaths(config any, schemas ...*Config) []string
- func FetchSpec(v VersionInfo) ([]byte, error)
- func SpecURL(v VersionInfo) string
- func WriteGoStructs(w io.Writer, schema *Config, info map[string]any) error
- func WriteJSONSchema(w io.Writer, schema *Config, info map[string]any) error
- func WriteOpenAPI(w io.Writer, schema *Config, info map[string]any) error
- func WriteProtobuf(w io.Writer, schema *Config, info map[string]any, validate bool) error
- func WritePydantic(w io.Writer, schema *Config, info map[string]any) error
- func WriteYANG(w io.Writer, schema *Config, info map[string]any) error
- type Change
- type Config
- type Diff
- type Node
- type Parser
- type TypeSegment
- type VersionInfo
Constants ¶
const UserAgent = "cumulus-schema/1.0"
userAgent must be set on all requests to api-prod.nvidia.com. Akamai's bot protection blocks Go's default "Go-http-client/1.1" UA, causing the connection to hang indefinitely.
Variables ¶
This section is empty.
Functions ¶
func ConfigLeafPaths ¶
ConfigLeafPaths walks a parsed config value (from YAML/JSON) alongside the schema tree and returns all paths in schema notation (with [*] for map keys). Both schemas should be provided to handle keys that may only exist in one version.
func FetchSpec ¶
func FetchSpec(v VersionInfo) ([]byte, error)
FetchSpec downloads the spec for the given version from Nvidia.
func SpecURL ¶
func SpecURL(v VersionInfo) string
SpecURL returns the download URL for a given version. Versions 5.0-5.8 use the old docs.nvidia.com path. Versions 5.9+ use the new api-prod.nvidia.com endpoint.
func WriteGoStructs ¶
WriteGoStructs outputs the config schema as Go struct definitions with json tags.
func WriteJSONSchema ¶
WriteJSONSchema outputs the config schema as a standalone JSON Schema draft-07 document.
func WriteOpenAPI ¶
WriteOpenAPI outputs a minimal OpenAPI 3.0 spec containing only the config schema.
func WriteProtobuf ¶
WriteProtobuf outputs the config schema as a .proto file. If validate is true, buf protovalidate constraints are included.
func WritePydantic ¶
WritePydantic outputs the config schema as Python Pydantic v2 model classes.
Types ¶
type Change ¶
type Change struct {
Path string
Kind string // "added", "removed", "changed"
Desc string
TypeSegs []TypeSegment // type info for added/removed leaves
DefaultVal string // default value for added/removed leaves
}
Change represents a single schema difference.
type Config ¶
type Config struct {
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"`
Nullable bool `json:"nullable,omitempty"`
Properties map[string]*Config `json:"properties,omitempty"`
AdditionalProperties *Config `json:"additionalProperties,omitempty"`
Items *Config `json:"items,omitempty"`
AllOf []*Config `json:"allOf,omitempty"`
OneOf []*Config `json:"oneOf,omitempty"`
AnyOf []*Config `json:"anyOf,omitempty"`
Enum []any `json:"enum,omitempty"`
Default any `json:"default,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
MinLength *int `json:"minLength,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
Format string `json:"format,omitempty"`
Required []string `json:"required,omitempty"`
XModelName string `json:"x-model-name,omitempty"`
SourceRef string `json:"-"` // x-defs key or API path, not serialized
}
Config is a resolved JSON-Config-like node (no $ref remaining).
func FlattenComposite ¶
FlattenComposite merges allOf, anyOf, and oneOf into a single Schema by combining all their properties, additionalProperties, etc. In the NVUE spec these composition keywords are used to express "this object has all of these property groups", so merging is the right interpretation.
func (*Config) JSONSchemaDoc ¶
JSONSchemaDoc builds a complete JSON Schema 2020-12 document, including $schema and $defs for format types.
func (*Config) ToJSONSchema ¶
ToJSONSchema converts a Schema to a JSON Schema map.
type Diff ¶
type Diff struct {
Changes []Change
}
Diff holds the result of comparing two schemas.
func DiffSchemas ¶
DiffSchemas compares two schemas and returns a Diff.
func (*Diff) FilterAffected ¶
FilterAffected returns a new Diff containing only changes that overlap with the given config paths. A change is included if it is at, above, or below any config path (bidirectional prefix match).
type Node ¶
type Node struct {
Name string
TypeSegs []TypeSegment // type annotation segments
DefaultVal string // default value, rendered separately
Desc string
Children []*Node
}
Node represents a node in the show tree.
func BuildShowTree ¶
BuildShowTree creates a Node tree from a schema.
func CollapseNode ¶
CollapseNode collapses single-child chains.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser resolves $ref pointers within x-defs and extracts the config tree.
func (*Parser) ConfigPaths ¶
ConfigPaths returns all paths that have a PATCH operation (i.e., configurable).
func (*Parser) ConfigSchema ¶
ConfigSchema returns the fully-resolved config schema starting from the PATCH request body of the root path ("/").
type TypeSegment ¶
type TypeSegment struct {
Text string
Literal bool // true for enum/literal values, false for type names
}
TypeSegment is a piece of a type annotation, either a type name or a literal value.
func LeafTypeSegs ¶
func LeafTypeSegs(s *Config) (segs []TypeSegment, defaultVal string)
LeafTypeSegs returns the type segments and default value for a leaf schema.
func ScalarUnionTypeSegs ¶
func ScalarUnionTypeSegs(s *Config) (segs []TypeSegment, defaultVal string)
ScalarUnionTypeSegs returns type segments for a scalar union schema.
type VersionInfo ¶
VersionInfo holds parsed version information.
func ParseVersion ¶
func ParseVersion(version string) (VersionInfo, error)
ParseVersion parses a Cumulus Linux version string (e.g. "5.14").
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
nvueschema
command
Command nvueschema is a CLI for extracting and generating config schemas from Cumulus Linux NVUE OpenAPI specs.
|
Command nvueschema is a CLI for extracting and generating config schemas from Cumulus Linux NVUE OpenAPI specs. |
