openapi3

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DescStatusIsEmpty    = 0
	DescStatusIsNotEmpty = 1
	DescStatusDefaultSep = " ~~~ "
)
View Source
const (
	OASVersionLatest = "3.0.3"
)
View Source
const XTagGroupsPropertyName = "x-tag-groups"

Variables

This section is empty.

Functions

func BuildApiUrlOAS

func BuildApiUrlOAS(specServerURL, overrideServerURL, specPath string) string

func Copy

func Copy(spec *oas3.Swagger) (*oas3.Swagger, error)

func CopySchemaStandard added in v1.1.5

func CopySchemaStandard(schema oas3.Schema) (oas3.Schema, error)

func GetExtensionPropString

func GetExtensionPropString(xprops oas3.ExtensionProps, key string) (string, error)

GetExtensionPropString converts extension prop value from `json.RawMessage` to `string`.

func GetExtensionPropStringOrEmpty

func GetExtensionPropStringOrEmpty(xprops oas3.ExtensionProps, key string) string

GetExtensionPropStringOrEmpty converts extension prop value from `json.RawMessage` to `string`.

func GetOperationExtensionPropStringOrEmpty added in v1.1.4

func GetOperationExtensionPropStringOrEmpty(op oas3.Operation, key string) string

GetOperationExtensionPropStringOrEmpty converts extension prop value from `json.RawMessage` to `string`.

func Merge

func Merge(specMaster, specExtra *oas3.Swagger, specExtraNote string, mergeOpts *MergeOptions) (*oas3.Swagger, error)

func MergeDirectory

func MergeDirectory(dir string, mergeOpts *MergeOptions) (*oas3.Swagger, int, error)

func MergeFiles

func MergeFiles(filepaths []string, mergeOpts *MergeOptions) (*oas3.Swagger, error)

func MergeParameters

func MergeParameters(specMaster, specExtra *oas3.Swagger, specExtraNote string, mergeOpts *MergeOptions) (*oas3.Swagger, error)

func MergePaths

func MergePaths(specMaster, specExtra *oas3.Swagger) (*oas3.Swagger, error)

func MergeRequestBodies

func MergeRequestBodies(specMaster, specExtra *oas3.Swagger, specExtraNote string) (*oas3.Swagger, error)

func MergeResponses

func MergeResponses(specMaster, specExtra *oas3.Swagger, specExtraNote string, mergeOpts *MergeOptions) (*oas3.Swagger, error)

func MergeSchemas

func MergeSchemas(specMaster, specExtra *oas3.Swagger, specExtraNote string, mergeOpts *MergeOptions) (*oas3.Swagger, error)

func MergeTags

func MergeTags(specMaster, specExtra *oas3.Swagger) *oas3.Swagger

func MergeWithTables

func MergeWithTables(spec1, spec2 *oas3.Swagger, specExtraNote string, mergeOpts *MergeOptions) (*oas3.Swagger, []*table.Table, error)

MergeWithTables performs a spec merge and returns comparison tables. This is useful to combine with github.com/grokify/gocharts/data/table WriteXLSX() to write out comparison tables for debugging.

func NewSpec added in v1.1.4

func NewSpec(oasVersion, apiTitle, apiVersion string) *oas3.Swagger

NewSpec returns a new OpenAPI 3 spec that will validate. Specifically, it includes an OAS version, sets `info` to be an empty object instead of null and sets apiVersion.

func OpTableColumnsDefault

func OpTableColumnsDefault() []text.Text

func OpTableColumnsRingCentral

func OpTableColumnsRingCentral() *text.TextSet

func OperationRequestMediaTypes

func OperationRequestMediaTypes(op *oas3.Operation) []string
func MediaTypesToSlice(typesMap map[string]*oas3.MediaType) []string {
	slice := []string{}
	for thisType := range typesMap {
		slice = append(slides, thisType)
	}
	return slice
}

OperationRequestMediaTypes returns a sorted slice of request media types.

func OperationResponseMediaTypes

func OperationResponseMediaTypes(op *oas3.Operation) []string

OperationResponseMediaTypes returns a sorted slice of response media types.

func OperationSetRequestBodySchemaRef added in v1.1.4

func OperationSetRequestBodySchemaRef(op *oas3.Operation, mediaType string, schemaRef *oas3.SchemaRef)

func OperationSetResponseBodySchemaRef added in v1.1.4

func OperationSetResponseBodySchemaRef(op *oas3.Operation, status, description, mediaType string, schemaRef *oas3.SchemaRef) error

func ReadAndValidateFile

func ReadAndValidateFile(oas3file string) (*oas3.Swagger, error)

func ReadFile

func ReadFile(oas3file string, validate bool) (*oas3.Swagger, error)

ReadFile does optional validation which is useful when merging incomplete spec files.

func SchemaPathExpand added in v1.1.4

func SchemaPathExpand(schemaName string) string

func TagsWithoutGroups

func TagsWithoutGroups(spec *oas3.Swagger, tagGroupSet TagGroupSet) []string

func VisitOperations

func VisitOperations(spec *oas3.Swagger, visitOp func(path, method string, op *oas3.Operation))

func WriteFileDirMerge

func WriteFileDirMerge(outfile, inputDir string, perm os.FileMode, mergeOpts *MergeOptions) (int, error)

Types

type CollisionCheckResult

type CollisionCheckResult int
const (
	CollisionCheckSame CollisionCheckResult = iota
	CollisionCheckOverwrite
	CollisionCheckError
	CollisionCheckSkip
)

func SchemaCheckCollisionDefault

func SchemaCheckCollisionDefault(schemaName string, item1, item2 interface{}, item2Note string) CollisionCheckResult

func SchemaCheckCollisionSkip

func SchemaCheckCollisionSkip(schemaName string, item1, item2 interface{}, item2Note string) CollisionCheckResult

type ExtensionPropsParent added in v1.1.4

type ExtensionPropsParent interface{}

type MergeOptions

type MergeOptions struct {
	FileRx               *regexp.Regexp
	SchemaFunc           func(schemaName string, sch1, sch2 interface{}, hint2 string) CollisionCheckResult
	CollisionCheckResult CollisionCheckResult
	ValidateEach         bool
	ValidateFinal        bool
}

func NewMergeOptionsSkip

func NewMergeOptionsSkip() *MergeOptions

func (*MergeOptions) CheckSchemaCollision

func (mo *MergeOptions) CheckSchemaCollision(schemaName string, sch1, sch2 interface{}, hint2 string) CollisionCheckResult

type OperationMeta

type OperationMeta struct {
	OperationID string
	Summary     string
	Method      string
	Path        string
	Tags        []string
	MetaNotes   []string
}

func OperationToMeta

func OperationToMeta(url, method string, op *oas3.Operation) OperationMeta

type SpecMeta

type SpecMeta struct {
	Filepath        string
	Version         int
	IsValid         bool
	ValidationError string
}

type SpecMetas

type SpecMetas struct {
	Metas []SpecMeta
}

func ReadSpecMetasDir

func ReadSpecMetasDir(dir string, rx *regexp.Regexp) (SpecMetas, error)

func ReadSpecMetasFiles

func ReadSpecMetasFiles(files []string) (SpecMetas, error)

func (*SpecMetas) Filepaths

func (metas *SpecMetas) Filepaths(validOnly bool) []string

func (*SpecMetas) Merge

func (metas *SpecMetas) Merge(validatesOnly bool, mergeOpts *MergeOptions) (SpecMore, error)

type SpecMore

type SpecMore struct {
	Spec *oas3.Swagger
}

func MergeSpecMetas

func MergeSpecMetas(metas *SpecMetas, validatesOnly bool, mergeOpts *MergeOptions) (SpecMore, error)

func ReadSpecMore

func ReadSpecMore(path string, validate bool) (*SpecMore, error)

func (*SpecMore) ComponentRequestBody

func (sm *SpecMore) ComponentRequestBody(componentPath string) *oas3.RequestBodyRef

func (*SpecMore) ExtensionNames

func (sm *SpecMore) ExtensionNames() map[string]int

ExtensionNames is not complete yet.

func (*SpecMore) HasComponentSchema

func (sm *SpecMore) HasComponentSchema(componentSchemaName string, lowerCaseMatch bool) bool

func (*SpecMore) MarshalJSON added in v1.1.4

func (sm *SpecMore) MarshalJSON(prefix, indent string) ([]byte, error)

func (*SpecMore) OperationByID added in v1.1.3

func (sm *SpecMore) OperationByID(wantOperationID string) (path, method string, op *oas3.Operation, err error)

func (*SpecMore) OperationMetas

func (sm *SpecMore) OperationMetas() []OperationMeta

func (*SpecMore) OperationParametersDescriptionStatus

func (sm *SpecMore) OperationParametersDescriptionStatus() maputil.MapStringMapStringInt

OperationParametersDescriptionStatus returns a set of operationIds and parameters with description status where `1` indicates a description and `0` indicates no descriptions. Descriptions for references aren't processed so they aren't analyzed and reported on. This returns a `MapStringMapStringInt` where the first key is the operationIds and the second key is the parameter name.

func (*SpecMore) OperationParametersDescriptionStatusCounts

func (sm *SpecMore) OperationParametersDescriptionStatusCounts() (with, without, all int)

OperationParametersDescriptionStatusCounts returns operation parameter counts with descriptions, without descriptions, and total counts.

func (*SpecMore) OperationParametersWithoutDescriptionsWriteFile

func (sm *SpecMore) OperationParametersWithoutDescriptionsWriteFile(filename string) error

func (*SpecMore) OperationsCount

func (sm *SpecMore) OperationsCount() int

func (*SpecMore) OperationsIDs added in v1.1.3

func (sm *SpecMore) OperationsIDs() []string

func (*SpecMore) OperationsTable

func (sm *SpecMore) OperationsTable(columns *text.TextSet) (*table.Table, error)

func (*SpecMore) PrintJSON added in v1.1.4

func (sm *SpecMore) PrintJSON(prefix, indent string) error

func (*SpecMore) SchemaNameExists

func (sm *SpecMore) SchemaNameExists(schemaName string, includeNil bool) bool

func (*SpecMore) SchemaNames

func (sm *SpecMore) SchemaNames() []string

func (*SpecMore) SchemaPropertiesDescriptionStatus

func (sm *SpecMore) SchemaPropertiesDescriptionStatus() maputil.MapStringMapStringInt

SchemaPropertiesDescriptionStatus returns a set of schema names and properties with description status where `1` indicates a description and `0` indicates no descriptions. Descriptions for references aren't processed so they aren't analyzed and reported on. This returns a `MapStringMapStringInt` where the first key is the component name and the second key is the property name.

func (*SpecMore) SchemaPropertiesDescriptionStatusCounts

func (sm *SpecMore) SchemaPropertiesDescriptionStatusCounts() (with, without, all int)

SchemaPropertiesDescriptionStatusCounts returns schema property counts with descriptions, without descriptions, and total counts.

func (*SpecMore) SchemaPropertiesWithoutDescriptionsWriteFile

func (sm *SpecMore) SchemaPropertiesWithoutDescriptionsWriteFile(filename string) error

func (*SpecMore) SchemaRef added in v1.1.4

func (sm *SpecMore) SchemaRef(schemaName string) *oas3.SchemaRef

func (*SpecMore) SchemasCount

func (sm *SpecMore) SchemasCount() int

func (*SpecMore) ServerURL

func (sm *SpecMore) ServerURL(index uint) string

ServerURL returns the OAS3 Spec URL for the index specified.

func (*SpecMore) ServerURLBasePath

func (sm *SpecMore) ServerURLBasePath(index uint) (string, error)

ServerURLBasePath extracts the base path from a OAS URL which can include variables.

func (*SpecMore) SetOperation added in v1.1.4

func (sm *SpecMore) SetOperation(path, method string, op *oas3.Operation)

func (*SpecMore) SetSchemaRef added in v1.1.4

func (sm *SpecMore) SetSchemaRef(schemaName string, schemaRef *oas3.SchemaRef) error

func (*SpecMore) Stats

func (sm *SpecMore) Stats() SpecStats

func (*SpecMore) TagGroups

func (sm *SpecMore) TagGroups() (TagGroupSet, error)

TagGroups parses a TagGroupSet from an OpenAPI3 spec.

func (*SpecMore) Tags

func (sm *SpecMore) Tags(inclTop, inclOps bool) []string

func (*SpecMore) TagsMap

func (sm *SpecMore) TagsMap(inclTop, inclOps bool) map[string]int

TagsMap returns a set of tags present in the current spec.

func (*SpecMore) WriteFileJSON

func (sm *SpecMore) WriteFileJSON(filename string, perm os.FileMode, prefix, indent string) error

func (*SpecMore) WriteFileXLSX

func (sm *SpecMore) WriteFileXLSX(filename string) error

type SpecStats

type SpecStats struct {
	OperationsCount int
	SchemasCount    int
}

type TagGroup

type TagGroup struct {
	Name    string   `json:"name"`
	Popular bool     `json:"popular"`
	Tags    []string `json:"tags"`
}

type TagGroupSet

type TagGroupSet struct {
	TagGroups []TagGroup
}

func NewTagGroupSet

func NewTagGroupSet() TagGroupSet

func (*TagGroupSet) AddToSpec

func (set *TagGroupSet) AddToSpec(spec *oas3.Swagger) error

func (*TagGroupSet) Exists

func (set *TagGroupSet) Exists(tagName string) bool

func (*TagGroupSet) GetTagGroupNamesForTagNames

func (set *TagGroupSet) GetTagGroupNamesForTagNames(wantTagNames ...string) []string

type TagsMore

type TagsMore struct {
	Tags oas3.Tags
}

func (*TagsMore) Get

func (tg *TagsMore) Get(tagName string) *oas3.Tag

type ValidationStatus

type ValidationStatus struct {
	Status  bool
	Message string
	Context string
	OpenAPI string
}

func ValidateMore

func ValidateMore(spec *oas3.Swagger) (ValidationStatus, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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