swagger

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: MIT Imports: 1 Imported by: 0

README

Swagger 2.0

Loose implementation of Swagger 2.0 specification for the needs of specifically polyform. This does not aim to be a full fledged implementation, so be cautious before considering using anything here (pro tip, you shouldn't).

Documentation

Index

Constants

View Source
const AABBDefinitionName = "AABB"
View Source
const Float2DefinitionName = "Float2"
View Source
const Float3DefinitionName = "Float3"
View Source
const Float4DefinitionName = "Float4"
View Source
const Int2DefinitionName = "Int2"
View Source
const Int3DefinitionName = "Int3"
View Source
const Int4DefinitionName = "Int4"

Variables

View Source
var AABBDefinition = Definition{
	Type: "object",
	Properties: map[string]Property{
		"min": {
			Ref: DefinitionRefPath(Float3DefinitionName),
		},
		"max": {
			Ref: DefinitionRefPath(Float3DefinitionName),
		},
	},
}
View Source
var Float2Definition = Definition{
	Type: "object",
	Properties: map[string]Property{
		"x": floatComponent,
		"y": floatComponent,
	},
}
View Source
var Float3Definition = Definition{
	Type: "object",
	Properties: map[string]Property{
		"x": floatComponent,
		"y": floatComponent,
		"z": floatComponent,
	},
}
View Source
var Float4Definition = Definition{
	Type: "object",
	Properties: map[string]Property{
		"x": floatComponent,
		"y": floatComponent,
		"z": floatComponent,
		"w": floatComponent,
	},
}
View Source
var Int2Definition = Definition{
	Type: "object",
	Properties: map[string]Property{
		"x": intComponent,
		"y": intComponent,
	},
}
View Source
var Int3Definition = Definition{
	Type: "object",
	Properties: map[string]Property{
		"x": intComponent,
		"y": intComponent,
		"z": intComponent,
	},
}
View Source
var Int4Definition = Definition{
	Type: "object",
	Properties: map[string]Property{
		"x": intComponent,
		"y": intComponent,
		"z": intComponent,
		"w": intComponent,
	},
}

Functions

func DefinitionRefPath

func DefinitionRefPath(r string) string

Types

type Definition

type Definition struct {
	// Type is probably always "object"
	Type                 string              `json:"type"`
	Properties           map[string]Property `json:"properties,omitempty"`
	AdditionalProperties any                 `json:"additionalProperties,omitempty"`
	Required             []string            `json:"required,omitempty"`
	Example              any                 `json:"example,omitempty"`
}

type Info

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

type Parameter

type Parameter struct {
	// Required. The location of the parameter. Possible values are "query",
	// "header", "path", "formData" or "body".
	In ParameterLocation `json:"in"`

	// Required. The name of the parameter. Parameter names are case sensitive.
	//  * If in is "path", the name field MUST correspond to the associated
	//    path segment from the path field in the Paths Object. See Path
	//    Templating for further information.
	//  * For all other cases, the name corresponds to the parameter name used
	//    based on the in property
	Name string `json:"name,omitempty"`

	// A brief description of the parameter. This could contain examples of
	// use. GFM syntax can be used for rich text representation.
	Description string `json:"description,omitempty"`

	// Determines whether this parameter is mandatory. If the parameter is in
	// "path", this property is required and its value MUST be true. Otherwise,
	// the property MAY be included and its default value is false.
	Required bool `json:"required,omitempty"`

	// If in is "body": Required. The schema defining the type used for the
	// body parameter.
	Schema any `json:"schema,omitempty"`

	// If in is any value other than "body"
	// Required. The type of the parameter. Since the parameter is not located
	// at the request body, it is limited to simple types (that is, not an
	// object). The value MUST be one of "string", "number", "integer",
	// "boolean", "array" or "file". If type is "file", the consumes MUST be
	// either "multipart/form-data", " application/x-www-form-urlencoded" or
	// both and the parameter MUST be in "formData".
	Type string `json:"type,omitempty"`
}

type ParameterLocation

type ParameterLocation string
const (
	PathParameterLocation   ParameterLocation = "path"
	QueryParameterLocation  ParameterLocation = "query"
	HeaderParameterLocation ParameterLocation = "header"
	BodyParameterLocation   ParameterLocation = "body"
	FormParameterLocation   ParameterLocation = "formData"
)

type Path

type Property

type Property struct {
	Type PropertyType `json:"type,omitempty"`

	// An optional format modifier serves as a hint at the contents and format
	// of the string
	Format PropertyFormat `json:"format,omitempty"`

	Example     any `json:"example,omitempty"`
	Ref         any `json:"$ref,omitempty"`
	Description any `json:"description,omitempty"`
	Items       any `json:"items,omitempty"`

	// If type is object
	Properties []Property `json:"properties,omitempty"`
}

type PropertyFormat

type PropertyFormat string
const (
	Int32PropertyFormat PropertyFormat = "int32"
	Int64PropertyFormat PropertyFormat = "int64"

	FloatPropertyFormat  PropertyFormat = "float"
	DoublePropertyFormat PropertyFormat = "double"

	// Base64-encoded characters, for example, U3dhZ2dlciByb2Nrcw==
	BytePropertyFormat PropertyFormat = "byte"

	// Binary data, used to describe files
	BinaryPropertyFormat PropertyFormat = "binary"

	// Full-date notation as defined by RFC 3339, section 5.6, for example,
	// 2017-07-21
	DatePropertyFormat PropertyFormat = "date"

	// The date-time notation as defined by RFC 3339, section 5.6, for example,
	// 2017-07-21T17:32:28Z
	DateTimePropertyFormat PropertyFormat = "date-time"

	// A hint to UIs to mask the input
	PasswordPropertyFormat PropertyFormat = "password"
)

type PropertyType

type PropertyType string
const (
	ObjectPropertyType  PropertyType = "object"
	StringPropertyType  PropertyType = "string"
	IntegerPropertyType PropertyType = "integer"
	NumberPropertyType  PropertyType = "number"
	BooleanPropertyType PropertyType = "boolean"
	ArrayPropertyType   PropertyType = "array"
)

type RequestDefinition

type RequestDefinition struct {
	Summary     string           `json:"summary"`
	Description string           `json:"description"`
	Produces    []string         `json:"produces"`
	Consumes    []string         `json:"consumes"`
	Responses   map[int]Response `json:"responses"`
	Parameters  []Parameter      `json:"parameters"`
}

type RequestMethod

type RequestMethod string
const (
	GetRequestMethod  RequestMethod = "get"
	PostRequestMethod RequestMethod = "post"
)

type Response

type Response struct {
	Description string `json:"description,omitempty"`
	// This is a lookup into the responses section, not definitions
	Ref    string `json:"$ref,omitempty"`
	Schema any    `json:"schema,omitempty"`
}

type SchemaObject

type SchemaObject struct {
	Ref string `json:"$ref,omitempty"`
}

type Spec

type Spec struct {
	Version     string                `json:"swagger"` // Must be 2.0
	Info        *Info                 `json:"info,omitempty"`
	Paths       map[string]Path       `json:"paths"`
	Definitions map[string]Definition `json:"definitions,omitempty"`
	Responses   map[string]Response   `json:"responses,omitempty"`
}

Jump to

Keyboard shortcuts

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