openapi

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "openapi [flags] package [package ...]",
	Short: "Generate openapi document for functions",
	Args: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("Miss package path")
		}
		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		def := parser.NewParser(nil)
		for _, arg := range args {
			err := def.Import(arg, way)
			if err != nil {
				return err
			}
		}

		var oainfo *oaspec.Info

		if info != "" {
			fil, err := ioutil.ReadFile(info)
			if err != nil {
				return err
			}
			fil, err = util.YAML2JSON(fil)

			if err != nil {
				return err
			}
			err = json.Unmarshal(fil, &oainfo)
			if err != nil {
				return err
			}
		}

		api, err := openapi.NewGenOpenAPI(def.API()).
			WithServices(servers...).
			SetInfo(oainfo).
			SetExplode(explode).
			Generate()
		if err != nil {
			return err
		}

		d, err := json.MarshalIndent(api, "", " ")
		if err != nil {
			return err
		}

		switch format {
		case "json":
		case "yaml":
			d, err = util.JSON2YAML(d)
			if err != nil {
				return err
			}

		default:
			return fmt.Errorf("undefined format %s", format)
		}
		if out != "" {
			err := ioutil.WriteFile(out, d, 0666)
			if err != nil {
				return err
			}
		} else {
			fmt.Println(string(d))
		}

		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