apispec

package
v0.21.11 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Deprecated:   "API specs are created automatically in the Akita app.",
	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 projectName string
			if serviceFlag != "" {
				projectName = serviceFlag
			} else if outFlag.AkitaURI != nil {
				projectName = outFlag.AkitaURI.ServiceName
			} else {
				return errors.New("Must specify \"project\" or \"out\" to use \"trace-tag\"")
			}
			destURI, err := util.GetTraceURIByTags(rest.Domain, telemetry.GetClientID(), projectName, 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:       telemetry.GetClientID(),
			Domain:         rest.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