openapi

package module
v0.0.0-...-32a4d35 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 3 Imported by: 0

README

OpenAPI

build-img pkg-img reportcard-img coverage-img version-img

OpenAPI specification object model

Features

  • Easy to integrate.

Installation

go get github.com/neotoolkit/openapi

Usage

package main

import (
	"fmt"
	"io/ioutil"
	"log"

	"github.com/neotoolkit/openapi"
)

func main() {
	file, err := ioutil.ReadFile("openapi.yml")
	if err != nil {
		log.Fatalln(err)
	}

	oapi, err := openapi.Parse(file)
	if err != nil {
		log.Fatalln(err)
	}
	
	fmt.Println(oapi.OpenAPI)
}

Documentation

See these docs.

License

MIT License.

Sponsors

Sponsored by Evrone

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExampleToResponse

func ExampleToResponse(data interface{}) interface{}

ExampleToResponse -.

Types

type Components

type Components struct {
	Schemas       Schemas       `json:"schemas,omitempty" yaml:"schemas,omitempty"`
	RequestBodies RequestBodies `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty"`
	Responses     Responses     `json:"responses,omitempty" yaml:"responses,omitempty"`
}

Components -.

type Content

type Content map[string]*MediaType

Content -.

type Example

type Example struct {
	Value interface{} `json:"value,omitempty" yaml:"value,omitempty"`
}

Example -.

type Examples

type Examples map[string]Example

Examples -.

func (Examples) GetKeys

func (e Examples) GetKeys() []string

GetKeys -.

type Info

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

Info Object See specification https://swagger.io/specification/#info-object

type MediaType

type MediaType struct {
	Schema   Schema      `json:"schema" yaml:"schema"`
	Example  interface{} `json:"example,omitempty" yaml:"example,omitempty"`
	Examples Examples    `json:"examples,omitempty" yaml:"examples,omitempty"`
}

Media Type Object See specification https://swagger.io/specification/#media-type-object

func (MediaType) ResponseByExample

func (mt MediaType) ResponseByExample() interface{}

ResponseByExample -.

func (MediaType) ResponseByExamplesKey

func (mt MediaType) ResponseByExamplesKey(key string) interface{}

ResponseByExamplesKey -.

type OpenAPI

type OpenAPI struct {
	Paths      Paths      `json:"paths" yaml:"paths"`
	Components Components `json:"components,omitempty" yaml:"components,omitempty"`
	OpenAPI    string     `json:"openapi" yaml:"openapi"`
	Servers    Servers    `json:"servers,omitempty" yaml:"servers,omitempty"`
	Security   []Security `json:"security,omitempty" yaml:"security,omitempty"`
	Tags       Tags       `json:"tags,omitempty" yaml:"tags,omitempty"`
	Info       Info       `json:"info" yaml:"info"`
}

OpenAPI Object See specification https://swagger.io/specification/#openapi-object

func Parse

func Parse(data []byte) (OpenAPI, error)

func (OpenAPI) LookupRequestBodyByReference

func (api OpenAPI) LookupRequestBodyByReference(ref string) (RequestBody, error)

func (OpenAPI) LookupSchemaByReference

func (api OpenAPI) LookupSchemaByReference(ref string) (Schema, error)

LookupSchemaByReference -.

type Operation

type Operation struct {
	OperationId string      `json:"operationId,omitempty" yaml:"operationId,omitempty"`
	Tags        []string    `json:"tags,omitempty" yaml:"tags,omitempty"`
	Parameters  Parameters  `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	RequestBody RequestBody `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
	Responses   Responses   `json:"responses" yaml:"responses"`
}

Operation -.

type Parameter

type Parameter struct {
	Name     string  `json:"name,omitempty" yaml:"name,omitempty"`
	In       string  `json:"in,omitempty" yaml:"in,omitempty"`
	Required bool    `json:"required,omitempty" yaml:"required,omitempty"`
	Schema   *Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
}

Parameter -.

type Parameters

type Parameters []Parameter

Parameters -.

type Path

type Path struct {
	Parameters Parameters `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	Post       *Operation `json:"post,omitempty" yaml:"post,omitempty"`
	Get        *Operation `json:"get,omitempty" yaml:"get,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"`
}

Path -.

type Paths

type Paths map[string]*Path

Paths -.

type RequestBodies

type RequestBodies map[string]*RequestBody

RequestBodies -.

type RequestBody

type RequestBody struct {
	Description string  `json:"description,omitempty" yaml:"description,omitempty"`
	Required    bool    `json:"required,omitempty" yaml:"required,omitempty"`
	Content     Content `json:"content,omitempty" yaml:"content,omitempty"`
	Ref         string  `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}

RequestBody -.

func (RequestBody) IsRef

func (body RequestBody) IsRef() bool

IsRef -.

type RequestBodyError

type RequestBodyError struct {
	Ref string
}

RequestBodyError -.

func (*RequestBodyError) Error

func (e *RequestBodyError) Error() string

Error -.

type Response

type Response struct {
	Description *string `json:"description,omitempty" yaml:"description,omitempty"`
	Content     Content `json:"content,omitempty" yaml:"content,omitempty"`
	Ref         string  `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}

Response -.

func (*Response) IsRef

func (r *Response) IsRef() bool

type Responses

type Responses map[string]*Response

Responses -.

type Schema

type Schema struct {
	Properties Schemas     `json:"properties,omitempty" yaml:"properties,omitempty"`
	Type       string      `json:"type,omitempty" yaml:"type,omitempty"`
	Format     string      `json:"format,omitempty" yaml:"format,omitempty"`
	Default    interface{} `json:"default,omitempty" yaml:"default,omitempty"`
	Example    interface{} `json:"example,omitempty" yaml:"example,omitempty"`
	Required   []string    `json:"required,omitempty" yaml:"required,omitempty"`
	Items      *Schema     `json:"items,omitempty" yaml:"items,omitempty"`
	Ref        string      `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	MinItems   int         `json:"minItems,omitempty" yaml:"minItems,omitempty"`
	MaxItems   int         `json:"maxItems,omitempty" yaml:"maxItems,omitempty"`
	Faker      string      `json:"x-faker,omitempty" yaml:"x-faker,omitempty"`
}

Schema -.

func (Schema) IsRef

func (s Schema) IsRef() bool

IsRef -.

func (Schema) ResponseByExample

func (s Schema) ResponseByExample(schemaContext SchemaContext) (interface{}, error)

ResponseByExample -.

type SchemaContext

type SchemaContext interface {
	LookupSchemaByReference(ref string) (Schema, error)
}

SchemaContext -.

type SchemaError

type SchemaError struct {
	Ref string
}

SchemaError -.

func (*SchemaError) Error

func (e *SchemaError) Error() string

Error -.

type Schemas

type Schemas map[string]*Schema

Schemas -.

type Security

type Security map[string][]string

type Server

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

Server -.

type Servers

type Servers []*Server

Servers -.

type Tag

type Tag struct {
	Name        string `json:"name,omitempty" yaml:"name,omitempty"`
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
}

Tag -.

type Tags

type Tags []*Tag

Tags -.

Jump to

Keyboard shortcuts

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