schemaextract

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package schemaextract parses an endpoint's API schema (OpenAPI for HTTP, protobuf for gRPC) into a flat list of renderable routes. The result is injected into the template-rendering CEL context as workload.endpoints[name].resources so ComponentType templates can emit exact path/method route matches instead of catch-all routing.

Extraction is best-effort: a missing, empty, or unparseable schema yields an empty (non-nil) result so templates can fall back to catch-all routing. The caller is expected to log returned errors as warnings, never to fail the render.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EndpointResource

type EndpointResource struct {
	// Kind is the protocol of the resource: "HTTP" or "gRPC".
	Kind string `json:"kind"`
	// Service is the fully-qualified gRPC service name (e.g. "greeter.Greeter").
	// Empty for HTTP resources.
	Service string `json:"service,omitempty"`
	// Method is the HTTP verb (GET/POST/...) or the gRPC method name (e.g. "SayHello").
	Method string `json:"method,omitempty"`
	// Path is the HTTP path template (e.g. "/v1/pets/{id}"). Empty for gRPC resources.
	Path string `json:"path,omitempty"`
}

EndpointResource is one renderable route extracted from an endpoint's API schema. JSON tags are lowercase so CEL templates see r.kind / r.service / r.method / r.path after the context is marshaled to a generic map.

func Extract

func Extract(epType v1alpha1.EndpointType, schema *v1alpha1.Schema) ([]EndpointResource, error)

Extract returns the routes extracted from an endpoint's schema. It never fails fatally: a nil/blank schema, an unresolved type, an unregistered extractor, or a parse error all return a non-nil empty slice. A non-nil error is returned for the caller to log as a warning only (rendering must continue regardless).

The schema is parsed on each call. The pipeline only invokes this once per render (and only when a template opts into the workload.toEndpointResources() macro), so no result memoization is kept here.

type Extractor

type Extractor interface {
	Extract(content string) ([]EndpointResource, error)
}

Extractor parses one schema content blob into resources. Implementations must be pure and side-effect free.

type SchemaType

type SchemaType string

SchemaType is a canonical schema-format identifier used to select an extractor.

const (
	SchemaTypeOpenAPI  SchemaType = "openapi"
	SchemaTypeProto    SchemaType = "proto"
	SchemaTypeGraphQL  SchemaType = "graphql"  // reserved; no extractor registered yet
	SchemaTypeAsyncAPI SchemaType = "asyncapi" // reserved; no extractor registered yet
)

Jump to

Keyboard shortcuts

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