openapi

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

README

OpenAPI

Extract API schema metadata from OpenAPI (v2/v3) and gRPC (protobuf) definitions.

Usage

source:
  name: openapi
  scope: my-api
  config:
    source: ./specs/petstore.yaml
    format: openapi
    service: petstore
Protobuf example
source:
  name: openapi
  scope: my-service
  config:
    source: ./protos/*.proto
    format: protobuf
Remote URL example
source:
  name: openapi
  scope: my-api
  config:
    source: https://petstore3.swagger.io/api/v3/openapi.json

Configuration

Key Type Required Description
source string Yes Path or URL to the spec file. Supports globs for local files (e.g. ./specs/*.yaml).
format string No Format of the spec: openapi or protobuf. Auto-detected from file extension if omitted.
service string No Service name override. Defaults to info.title for OpenAPI or package name for protobuf.

Entities

Entity: api
OpenAPI properties
Field Sample Value
urn urn:openapi:my-api:api:petstore
name Petstore
description A sample API for pets
properties.version 1.0.0
properties.format openapi_v3
properties.endpoints [{"method": "GET", "path": "/pets", "summary": "List all pets", "operation_id": "listPets"}]
properties.schemas 5
properties.servers ["https://api.example.com/v1"]
Protobuf properties
Field Sample Value
urn urn:openapi:my-service:api:mypackage
name mypackage
properties.version proto3
properties.format protobuf
properties.package mypackage
properties.services [{"name": "UserService", "methods": [{"name": "GetUser", "input_type": "GetUserRequest", "output_type": "GetUserResponse"}]}]
properties.messages 10
Edges

No edges are emitted by this extractor.

Contributing

Refer to the contribution guidelines for information on contributing to this module.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client fetches spec files from HTTP(S) URLs.

func NewClient

func NewClient() *Client

NewClient creates a new HTTP client for fetching specs.

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context, url string) ([]byte, error)

Fetch retrieves the content at the given URL.

type Config

type Config struct {
	// Path or URL to the OpenAPI/gRPC spec file. Supports globs for local files.
	Source string `json:"source" yaml:"source" mapstructure:"source" validate:"required"`
	// Format: "openapi" or "protobuf" (auto-detected from file extension if omitted).
	Format string `json:"format" yaml:"format" mapstructure:"format" validate:"omitempty,oneof=openapi protobuf"`
	// Service name override (defaults to info.title for OpenAPI or package name for proto).
	Service string `json:"service" yaml:"service" mapstructure:"service"`
}

Config holds the extractor configuration.

type Extractor

type Extractor struct {
	plugins.BaseExtractor
	// contains filtered or unexported fields
}

Extractor extracts metadata from OpenAPI and protobuf schema files.

func New

func New(logger log.Logger) *Extractor

New creates a new openapi extractor.

func (*Extractor) Extract

func (e *Extractor) Extract(ctx context.Context, emit plugins.Emit) error

Extract reads the spec source(s) and emits records.

func (*Extractor) Init

func (e *Extractor) Init(ctx context.Context, config plugins.Config) error

Init initialises the extractor with the given config.

Jump to

Keyboard shortcuts

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