apispec

package
v0.20.6 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:          "apispec",
	Short:        "Convert traces into an OpenAPI3 specification.",
	SilenceUsage: true,
	Args:         cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, _ []string) error {
		traces, err := toLocations(tracesFlag)
		if err != nil {
			return err
		}

		traceTags, err := util.ParseTags(tracesByTagFlag)
		if err != nil {
			return err
		}

		for _, version := range versionsFlag {
			if version_names.IsReservedVersionName(version) {
				return errors.Errorf("'%s' is an Akita-reserved version", version)
			}
		}

		var timeRange *time_span.TimeSpan
		var startTime time.Time
		endTime := time.Now()
		if fromTimeFlag != "" {
			startTime, err = parseTime(fromTimeFlag)
			if err != nil {
				return errors.Wrap(err, "failed to parse start time")
			}
		}
		if toTimeFlag != "" {
			endTime, err = parseTime(toTimeFlag)
			if err != nil {
				return errors.Wrap(err, "failed to parse end time")
			}
		}
		if fromTimeFlag != "" || toTimeFlag != "" {
			timeRange = time_span.NewTimeSpan(startTime, endTime)
		}

		if len(traces) == 0 && len(traceTags) == 0 {
			return errors.New("Must specify at least one input via \"traces\" or \"trace-tag\"")
		}

		if len(traceTags) > 0 {
			var serviceName string
			if serviceFlag != "" {
				serviceName = serviceFlag
			} else if outFlag.AkitaURI != nil {
				serviceName = outFlag.AkitaURI.ServiceName
			} else {
				return errors.New("Must specify \"service\" or \"out\" to use \"trace-tag\"")
			}
			destURI, err := util.GetTraceURIByTags(akiflag.Domain, akiflag.GetClientID(), serviceName, traceTags, "trace-tag")
			if err != nil {
				return err
			}
			if destURI.ObjectName == "" {
				return cmderr.AkitaErr{Err: errors.New("No traces matching specified tag, cannot create spec")}
			}
			traces = append(traces, location.Location{AkitaURI: &destURI})
		}

		tags, err := util.ParseTagsAndWarn(tagsFlag)
		if err != nil {
			return err
		}

		var gitlabMR *gitlab.MRInfo
		if gitlabProjectFlag != "" {
			gitlabMR = &gitlab.MRInfo{
				Project: gitlabProjectFlag,
				IID:     gitlabMRFlag,
				Branch:  gitlabBranchFlag,
				Commit:  gitlabCommitFlag,
			}
		}

		plugins, err := pluginloader.Load(pluginsFlag)
		if err != nil {
			return errors.Wrap(err, "failed to load plugins")
		}

		args := apispec.Args{
			ClientID:       akiflag.GetClientID(),
			Domain:         akiflag.Domain,
			Traces:         traces,
			Out:            outFlag,
			Service:        serviceFlag,
			Format:         formatFlag,
			Tags:           tags,
			Versions:       versionsFlag,
			PathParams:     pathParamsFlag,
			PathExclusions: pathExclusionsFlag,
			TimeRange:      timeRange,

			GitHubBranch: githubBranchFlag,
			GitHubCommit: githubCommitFlag,
			GitHubRepo:   githubRepoFlag,
			GitHubPR:     githubPRFlag,

			GitLabMR: gitlabMR,

			GetSpecEnableRelatedFields: getSpecEnableRelatedFieldsFlag,
			IncludeTrackers:            includeTrackersFlag,

			Plugins: plugins,
		}
		if err := apispec.Run(args); err != nil {
			return cmderr.AkitaErr{Err: err}
		}
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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