spec

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package spec provides parsing of OpenAPI v2, OpenAPI v3, and Postman collection specifications. It returns a unified Doc structure used by the rest of the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doc

type Doc struct {
	Version     string      `json:"version,omitempty"`
	Title       string      `json:"title,omitempty"`
	Description string      `json:"description,omitempty"`
	VersionStr  string      `json:"versionStr,omitempty"`
	Servers     []Server    `json:"servers,omitempty"`
	PathItems   []*PathItem `json:"pathItems,omitempty"`
}

Doc is the unified representation of a parsed Swagger/OpenAPI document. All versions (Swagger 2.0, OpenAPI 3.0, 3.1) are mapped to this type.

func Parse

func Parse(data []byte) (*Doc, error)

Parse parses a Swagger 2.0, OpenAPI 3.x, or Postman collection document (JSON or YAML) and returns a unified Doc.

type MediaType

type MediaType struct {
	Schema *Schema `json:"schema,omitempty"`
}

MediaType represents a media type with an associated schema.

type Operation

type Operation struct {
	ID          string                `json:"id,omitempty"`
	Tags        []string              `json:"tags,omitempty"`
	Summary     string                `json:"summary,omitempty"`
	Description string                `json:"description,omitempty"`
	Deprecated  bool                  `json:"deprecated,omitempty"`
	Parameters  []*Parameter          `json:"parameters,omitempty"`
	RequestBody *RequestBody          `json:"requestBody,omitempty"`
	Responses   map[string]*Response  `json:"responses,omitempty"`
	Security    []map[string][]string `json:"security,omitempty"`
	// contains filtered or unexported fields
}

Operation represents a single API operation (method) with its parameters, request body, and responses.

type Parameter

type Parameter struct {
	Name        string  `json:"name,omitempty"`
	In          string  `json:"in,omitempty"` // "query", "path", "header", "cookie"
	Description string  `json:"description,omitempty"`
	Required    bool    `json:"required,omitempty"`
	Schema      *Schema `json:"schema,omitempty"`
}

Parameter represents a request parameter with name, location, schema, and required status.

type PathItem

type PathItem struct {
	Path      string     `json:"path,omitempty"`
	Method    string     `json:"method,omitempty"`
	Operation *Operation `json:"operation,omitempty"`
}

PathItem is a single endpoint (path + method + operation).

type RequestBody

type RequestBody struct {
	Description string                `json:"description,omitempty"`
	Required    bool                  `json:"required,omitempty"`
	Content     map[string]*MediaType `json:"content,omitempty"`
}

RequestBody represents an HTTP request body with content type definitions.

type Response

type Response struct {
	Description string                `json:"description,omitempty"`
	Content     map[string]*MediaType `json:"content,omitempty"`
	Example     any                   `json:"example,omitempty"`
}

Response represents an API response with description and content type definitions.

type Schema

type Schema struct {
	Type       string             `json:"type,omitempty"`
	Format     string             `json:"format,omitempty"`
	Properties map[string]*Schema `json:"properties,omitempty"`
	Items      *Schema            `json:"items,omitempty"`
	Required   []string           `json:"required,omitempty"`
	Ref        string             `json:"$ref,omitempty"`
	OneOf      []*Schema          `json:"oneOf,omitempty"`
	AnyOf      []*Schema          `json:"anyOf,omitempty"`
	AllOf      []*Schema          `json:"allOf,omitempty"`

	Description string `json:"description,omitempty"`
	Default     any    `json:"default,omitempty"`
	Enum        []any  `json:"enum,omitempty"`
	Example     any    `json:"example,omitempty"`
	Nullable    bool   `json:"nullable,omitempty"`
	ReadOnly    bool   `json:"readOnly,omitempty"`
	WriteOnly   bool   `json:"writeOnly,omitempty"`
}

Schema represents a JSON Schema definition for request/response bodies.

type Server

type Server struct {
	URL         string `json:"url,omitempty"`
	Description string `json:"description,omitempty"`
}

Server represents an API server with URL and description.

Jump to

Keyboard shortcuts

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