parser

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const CodegenHeader = "// Code generated by jamf-cli generator. DO NOT EDIT."

CodegenHeader is the marker line at the top of every modern API generated file. Must match the first line of resourceTemplate and registryTemplate.

Variables

This section is empty.

Functions

func ApplyLookupFields

func ApplyLookupFields(resources []*Resource)

ApplyLookupFields sets LookupFields on resources that have alternate identifier fields defined in resourceLookupFields. Must be called after DeduplicateVersioned so resource names are in their final canonical form.

func ApplyNameFieldOverrides

func ApplyNameFieldOverrides(resources []*Resource)

ApplyNameFieldOverrides corrects NameField and IDField values that the auto-detection heuristics got wrong. Must be called after ApplyNameOverrides so resource names are in their final canonical form.

func ApplyNameOverrides

func ApplyNameOverrides(resources []*Resource)

ApplyNameOverrides corrects resource names that auto-pluralization got wrong. Must be called after DeduplicateVersioned.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator generates Go code from parsed resources

func NewGenerator

func NewGenerator(outputDir string) *Generator

NewGenerator creates a new code generator

func (*Generator) Generate

func (g *Generator) Generate(resource *Resource) (string, error)

Generate generates a Go command file for a resource

func (*Generator) GenerateRegistry

func (g *Generator) GenerateRegistry(resources []*Resource) (string, error)

GenerateRegistry generates the registry file that registers all commands

type LookupField

type LookupField struct {
	Flag      string // CLI flag name (e.g. "serial")
	RSQLField string // RSQL filter field path (e.g. "hardware.serialNumber")
	Desc      string // Flag description shown in --help
}

LookupField represents an alternate identifier that can be used to resolve a resource ID instead of the primary name field (e.g. serial number for computers).

type Operation

type Operation struct {
	Name          string // e.g., "list", "get", "create"
	Method        string // HTTP method
	Path          string // API path
	Summary       string
	Description   string
	Parameters    []*Parameter
	RequestBody   *RequestBody
	Responses     map[string]*Response
	IsAction      bool     // x-action: true
	IsDestructive bool     // Requires confirmation (delete, erase, etc.)
	IsList        bool     // List operation with pagination support
	APIVersion    string   // v1, v2, preview, etc.
	Privileges    []string // x-required-privileges
}

Operation represents an API operation (endpoint)

type Parameter

type Parameter struct {
	Name        string
	In          string // "query", "path"
	Description string
	Required    bool
	Type        string
	Default     any
	IsArray     bool
}

Parameter represents a query/path parameter

type Property

type Property struct {
	Name        string
	Type        string
	Description string
	Example     any
	Nullable    bool
	ReadOnly    bool
	SchemaRef   string  // name of the referenced component schema for object/array types (e.g. "ComputerGeneralUpdate")
	Nested      *Schema // resolved nested schema for object types (may be nil)
}

Property represents a schema property

type RequestBody

type RequestBody struct {
	Description  string
	Required     bool
	Schema       *Schema
	IsMultipart  bool   // true when content type is multipart/form-data
	IsMergePatch bool   // true when content type is application/merge-patch+json
	FileField    string // schema property that holds the binary file (e.g. "file")
}

RequestBody represents a request body

type Resource

type Resource struct {
	Name              string // e.g., "buildings"
	NameSingular      string // e.g., "building"
	GoName            string // e.g., "Buildings"
	Description       string
	Operations        []*Operation
	Schemas           map[string]*Schema
	NameField         string        // Filter field for name lookups (default "name", some use "displayName")
	IDField           string        // Response field for ID extraction in name resolution (default "id", some use "templateId", "groupId", etc.)
	IsSingleton       bool          // True for settings-style resources: single object, GET+PUT, no {id} in any path
	LookupFields      []LookupField // Alternate identifier fields for patch-by-name / delete-by-name (e.g. serial number)
	NameLookupPath    string        // Override list path for name resolution (when the standard list endpoint ignores RSQL)
	NameLookupIDField string        // Override ID field extracted from NameLookupPath response (when it differs from IDField)
	HasVersionLock    bool          // True when PUT/POST request body includes versionLock (optimistic locking for prestages)
}

Resource represents a parsed API resource (e.g., buildings, computers)

func DeduplicateVersioned

func DeduplicateVersioned(resources []*Resource) []*Resource

DeduplicateVersioned consolidates multi-version resources so each resource group surfaces as a single command using the latest API version.

When multiple spec files cover the same resource at different API versions (e.g. MobileDevicePrestagesV2.yaml + MobileDevicePrestagesV3.yaml), the generator produces commands like "mobile-device-prestages-v-2s" and "mobile-device-prestages-v-3s". This function:

  • Detects versioned resource names via the "-v-{N}s" suffix pattern
  • For each version family, keeps only the highest version
  • Renames the winning resource to the clean canonical name (no version suffix)
  • Suppresses any non-versioned base resource that the versioned family supersedes

func ParseSpec

func ParseSpec(specPath string) ([]*Resource, error)

ParseSpec parses an OpenAPI spec file and returns one or more Resources. Most specs produce a single resource, but specs with multiple sibling collection paths (e.g. /v1/foo/macos and /v1/foo/ios in the same file) produce one resource per family. Returns nil when the file should be skipped.

type Response

type Response struct {
	StatusCode  string
	Description string
	Schema      *Schema
	IsBinary    bool // true for image/* content types, text/csv, or format:binary schemas
}

Response represents an API response

type ScalarField

type ScalarField struct {
	Path string // dot-notation path, e.g. "general.managed"
	Type string // scalar type: "string", "integer", "boolean", "number"
}

ScalarField represents a patchable scalar field in dot-notation (e.g. "general.managed").

type Schema

type Schema struct {
	Name       string
	Type       string
	Properties map[string]*Property
	Required   []string
}

Schema represents a JSON schema

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL