spec

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2021 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BasicAuthSecurityDefinitionKey  = "BasicAuth"
	APIKeyAuthSecurityDefinitionKey = "ApiKeyAuth"
	OAuth2SecurityDefinitionKey     = "OAuth2"

	BearerAuthPrefix = "Bearer "
	BasicAuthPrefix  = "Basic "

	AccessTokenParamKey = "access_token"
)

Variables

This section is empty.

Functions

func AddOperationToPathItem

func AddOperationToPathItem(item *oapi_spec.PathItem, method string, operation *oapi_spec.Operation)

func CloneOperation

func CloneOperation(op *spec.Operation) (*spec.Operation, error)

func ConvertHeadersToMap

func ConvertHeadersToMap(headers [][2]string) map[string]string

func CopyPathItemWithNewOperation

func CopyPathItemWithNewOperation(item *oapi_spec.PathItem, method string, operation *oapi_spec.Operation) *oapi_spec.PathItem

func GetContentTypeWithoutParameter

func GetContentTypeWithoutParameter(contentTypeHeaderField string) string

func GetOperationFromPathItem

func GetOperationFromPathItem(item *oapi_spec.PathItem, method string) *oapi_spec.Operation

func GetPathAndQuery

func GetPathAndQuery(fullPath string) (path, query string)

example: for "/example-path?param=value" returns "/example-path", "param=value"

func MergePathItems

func MergePathItems(dst, src *oapi_spec.PathItem) *oapi_spec.PathItem

Types

type APIDiff added in v0.0.2

type APIDiff struct {
	Type             DiffType
	Path             string
	PathID           string
	OriginalPathItem *oapi_spec.PathItem
	ModifiedPathItem *oapi_spec.PathItem
	InteractionID    uuid.UUID
	SpecID           uuid.UUID
}

type ApprovedSpec

type ApprovedSpec struct {
	PathItems           map[string]*oapi_spec.PathItem
	SecurityDefinitions oapi_spec.SecurityDefinitions
}

func (*ApprovedSpec) Clone

func (a *ApprovedSpec) Clone() (*ApprovedSpec, error)

func (*ApprovedSpec) GetPathItem

func (a *ApprovedSpec) GetPathItem(path string) *oapi_spec.PathItem

type ApprovedSpecReview

type ApprovedSpecReview struct {
	PathItemsReview []*ApprovedSpecReviewPathItem
	PathToPathItem  map[string]*oapi_spec.PathItem
}

type ApprovedSpecReviewPathItem

type ApprovedSpecReviewPathItem struct {
	ReviewPathItem
	PathUUID string
}

type DiffParams

type DiffParams struct {
	// contains filtered or unexported fields
}

type DiffSource

type DiffSource string
const (
	DiffSourceReconstructed DiffSource = "RECONSTRUCTED"
	DiffSourceProvided      DiffSource = "PROVIDED"
)

type DiffType

type DiffType string
const (
	DiffTypeNoDiff      DiffType = "NO_DIFF"
	DiffTypeZombieDiff  DiffType = "ZOMBIE_DIFF"
	DiffTypeShadowDiff  DiffType = "SHADOW_DIFF"
	DiffTypeGeneralDiff DiffType = "GENERAL_DIFF"
)

type HTTPInteractionData

type HTTPInteractionData struct {
	ReqBody, RespBody       string
	ReqHeaders, RespHeaders map[string]string
	QueryParams             url.Values
	// contains filtered or unexported fields
}

type LearningParametrizedPaths

type LearningParametrizedPaths struct {
	// map parameterized paths into a list of paths included in it.
	// e.g: /api/{param1} -> /api/1, /api/2
	// non parameterized path will map to itself
	Paths map[string]map[string]bool
}

type LearningSpec

type LearningSpec struct {
	// map parameterized path into path item
	PathItems           map[string]*oapi_spec.PathItem
	SecurityDefinitions oapi_spec.SecurityDefinitions
}

func (*LearningSpec) AddPathItem

func (l *LearningSpec) AddPathItem(path string, pathItem *oapi_spec.PathItem)

func (*LearningSpec) GetPathItem

func (l *LearningSpec) GetPathItem(path string) *oapi_spec.PathItem

type OperationGenerator added in v0.0.3

type OperationGenerator struct {
	ResponseHeadersToIgnore map[string]struct{}
	RequestHeadersToIgnore  map[string]struct{}
}

func CreateTestNewOperationGenerator added in v0.0.3

func CreateTestNewOperationGenerator() *OperationGenerator

func NewOperationGenerator added in v0.0.3

func NewOperationGenerator(config OperationGeneratorConfig) *OperationGenerator

func (*OperationGenerator) GenerateSpecOperation added in v0.0.3

func (o *OperationGenerator) GenerateSpecOperation(data *HTTPInteractionData, securityDefinitions spec.SecurityDefinitions) (*spec.Operation, error)

Note: securityDefinitions might be updated.

type OperationGeneratorConfig added in v0.0.3

type OperationGeneratorConfig struct {
	ResponseHeadersToIgnore []string
	RequestHeadersToIgnore  []string
}

type PathParam

type PathParam struct {
	*spec.Parameter
}

type ProvidedSpec

type ProvidedSpec struct {
	Spec *oapispec.Swagger
}

func (*ProvidedSpec) GetPathItem added in v0.0.4

func (p *ProvidedSpec) GetPathItem(path string) *oapispec.PathItem

type ReviewPathItem

type ReviewPathItem struct {
	// ParameterizedPath represents the parameterized path grouping Paths
	ParameterizedPath string
	// Paths group of paths ParametrizedPath is representing
	Paths map[string]bool
}

type SCNTCommon

type SCNTCommon struct {
	Version       string      `json:"version"`
	Headers       [][2]string `json:"headers"`
	Body          []byte      `json:"body"`
	TruncatedBody bool        `json:"truncated_body"`
}

type SCNTRequest

type SCNTRequest struct {
	Method string `json:"method"`
	Path   string `json:"path"`
	Host   string `json:"host"`
	SCNTCommon
}

type SCNTResponse

type SCNTResponse struct {
	StatusCode string `json:"status_code"`
	SCNTCommon
}

type SCNTelemetry

type SCNTelemetry struct {
	RequestID          string       `json:"request_id"`
	Scheme             string       `json:"scheme"`
	DestinationAddress string       `json:"destination_address"`
	SourceAddress      string       `json:"source_address"`
	SCNTRequest        SCNTRequest  `json:"scnt_request"`
	SCNTResponse       SCNTResponse `json:"scnt_response"`
}

type Spec

type Spec struct {
	SpecInfo

	OpGenerator *OperationGenerator
	// contains filtered or unexported fields
}

func CreateDefaultSpec

func CreateDefaultSpec(host string, port string, config OperationGeneratorConfig) *Spec

func (*Spec) ApplyApprovedReview

func (s *Spec) ApplyApprovedReview(approvedReviews *ApprovedSpecReview) error

func (*Spec) CreateSuggestedReview

func (s *Spec) CreateSuggestedReview() *SuggestedSpecReview

this function should group all paths that have suspect parameter (with a certain template), into one path which is parameterized, and then add this path params to the spec.

func (*Spec) DiffTelemetry

func (s *Spec) DiffTelemetry(telemetry *SCNTelemetry, diffSource DiffSource) (*APIDiff, error)

func (*Spec) GenerateOASJson

func (s *Spec) GenerateOASJson() ([]byte, error)

func (*Spec) GenerateOASYaml

func (s *Spec) GenerateOASYaml() ([]byte, error)

func (*Spec) HasApprovedSpec

func (s *Spec) HasApprovedSpec() bool

func (*Spec) HasProvidedSpec

func (s *Spec) HasProvidedSpec() bool

func (*Spec) LearnTelemetry

func (s *Spec) LearnTelemetry(telemetry *SCNTelemetry) error

func (*Spec) LoadProvidedSpec

func (s *Spec) LoadProvidedSpec(providedSpec []byte, pathToPathID map[string]string) error

func (*Spec) SpecInfoClone added in v0.0.3

func (s *Spec) SpecInfoClone() (*Spec, error)

type SpecInfo added in v0.0.3

type SpecInfo struct {
	// Host of the spec
	Host string

	Port string
	// Spec ID
	ID uuid.UUID
	// Provided Spec
	ProvidedSpec *ProvidedSpec
	// Merged & approved state (can be generated into spec YAML)
	ApprovedSpec *ApprovedSpec
	// Upon learning, this will be updated (not the ApprovedSpec field)
	LearningSpec *LearningSpec

	ApprovedPathTrie pathtrie.PathTrie
	ProvidedPathTrie pathtrie.PathTrie
}

type SuggestedSpecReview

type SuggestedSpecReview struct {
	PathItemsReview []*SuggestedSpecReviewPathItem
	PathToPathItem  map[string]*oapi_spec.PathItem
}

type SuggestedSpecReviewPathItem

type SuggestedSpecReviewPathItem struct {
	ReviewPathItem
}

type TestOperation

type TestOperation struct {
	Op *oapi_spec.Operation
}

func NewOperation

func NewOperation(t *testing.T, data *HTTPInteractionData) *TestOperation

func (*TestOperation) Deprecated added in v0.0.4

func (op *TestOperation) Deprecated() *TestOperation

type TestPathItem

type TestPathItem struct {
	PathItem oapi_spec.PathItem
}

func NewTestPathItem

func NewTestPathItem() *TestPathItem

func (*TestPathItem) WithOperation

func (t *TestPathItem) WithOperation(method string, op *oapi_spec.Operation) *TestPathItem

func (*TestPathItem) WithPathParams

func (t *TestPathItem) WithPathParams(name, tpe, format string) *TestPathItem

type TestSpec

type TestSpec struct {
	Spec *oapi_spec.Swagger
}

func NewTestSpec

func NewTestSpec() *TestSpec

func (*TestSpec) WithPathItem

func (t *TestSpec) WithPathItem(path string, pathItem oapi_spec.PathItem) *TestSpec

Jump to

Keyboard shortcuts

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