openapi2

package
v0.0.0-...-1d7c4e0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package openapi2 outputs to OpenAPI 2.0

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md http://json-schema.org/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteJSON

func WriteJSON(w io.Writer, prog *docparse.Program) error

WriteJSON writes to w as JSON.

func WriteJSONIndent

func WriteJSONIndent(w io.Writer, prog *docparse.Program) error

WriteJSONIndent writes to w as indented JSON.

func WriteYAML

func WriteYAML(w io.Writer, prog *docparse.Program) error

WriteYAML writes w as YAML.

Types

type Contact

type Contact struct {
	Name  string `json:"name,omitempty" yaml:"name,omitempty"`
	URL   string `json:"url,omitempty" yaml:"url,omitempty"`
	Email string `json:"email,omitempty" yaml:"email,omitempty"`
}

Contact provides contact information for the exposed API.

type Info

type Info struct {
	Title       string  `json:"title,omitempty" yaml:"title,omitempty"`
	Description string  `json:"description,omitempty" yaml:"description,omitempty"`
	Version     string  `json:"version,omitempty" yaml:"version,omitempty"`
	Contact     Contact `json:"contact,omitempty" yaml:"contact,omitempty"`
}

Info provides metadata about the API.

type OpenAPI

type OpenAPI struct {
	Swagger string `json:"swagger" yaml:"swagger"`
	Info    Info   `json:"info" yaml:"info"`

	// TODO: do we need this? will have to come from config
	Host     string   `json:"host,omitempty" yaml:"host,omitempty"`
	BasePath string   `json:"basePath,omitempty" yaml:"basePath,omitempty"`
	Schemes  []string `json:"schemes,omitempty" yaml:"schemes,omitempty"`
	Consumes []string `json:"consumes,omitempty" yaml:"consumes,omitempty"`
	Produces []string `json:"produces,omitempty" yaml:"produces,omitempty"`

	Paths       map[string]*Path           `json:"paths" yaml:"paths"`
	Definitions map[string]docparse.Schema `json:"definitions" yaml:"definitions"`
}

OpenAPI output.

type Operation

type Operation struct {
	OperationID string           `json:"operationId" yaml:"operationId"`
	Tags        []string         `json:"tags,omitempty" yaml:"tags,omitempty"`
	Summary     string           `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description string           `json:"description,omitempty" yaml:"description,omitempty"`
	Consumes    []string         `json:"consumes,omitempty" yaml:"consumes,omitempty"`
	Produces    []string         `json:"produces,omitempty" yaml:"produces,omitempty"`
	Parameters  []Parameter      `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	Responses   map[int]Response `json:"responses" yaml:"responses"`
}

Operation describes a single API operation on a path.

type Parameter

type Parameter struct {
	Name        string           `json:"name" yaml:"name"`
	In          string           `json:"in" yaml:"in"` // query, header, path, cookie
	Description string           `json:"description,omitempty" yaml:"description,omitempty"`
	Type        string           `json:"type,omitempty" yaml:"type,omitempty"`
	Items       *docparse.Schema `json:"items,omitempty" yaml:"items,omitempty"`
	Format      string           `json:"format,omitempty" yaml:"format,omitempty"`
	Required    bool             `json:"required,omitempty" yaml:"required,omitempty"`
	Readonly    *bool            `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
	Enum        []string         `json:"enum,omitempty" yaml:"enum,omitempty"`
	Default     string           `json:"default,omitempty" yaml:"default,omitempty"`
	Minimum     int              `json:"minimum,omitempty" yaml:"minimum,omitempty"`
	Maximum     int              `json:"maximum,omitempty" yaml:"maximum,omitempty"`
	Schema      *docparse.Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
}

Parameter describes a single operation parameter.

type Path

type Path struct {
	Ref    string     `json:"ref,omitempty" yaml:"ref,omitempty"`
	Get    *Operation `json:"get,omitempty" yaml:"get,omitempty"`
	Post   *Operation `json:"post,omitempty" yaml:"post,omitempty"`
	Put    *Operation `json:"put,omitempty" yaml:"put,omitempty"`
	Patch  *Operation `json:"patch,omitempty" yaml:"patch,omitempty"`
	Delete *Operation `json:"delete,omitempty" yaml:"delete,omitempty"`
	Head   *Operation `json:"head,omitempty" yaml:"head,omitempty"`
}

Path describes the operations available on a single path.

type Reference

type Reference struct {
	Ref string `json:"$ref" yaml:"$ref"`
}

Reference other components in the specification, internally and externally.

type Response

type Response struct {
	Description string           `json:"description,omitempty" yaml:"description,omitempty"`
	Schema      *docparse.Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
}

Response describes a single response from an API Operation.

Jump to

Keyboard shortcuts

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