swagsampler

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

README

swagsampler

Generate sample requests from a swagger 2.0 spec

package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"io/ioutil"
	"log"

	"github.com/breise/swagsampler"
)

func main() {
	endpointP := flag.String("endpoint", "", "endpoint, including leading slash")
	methodP := flag.String("method", "", "method, in lowercase (e.g. get post)")
	flag.Parse()
	endpoint := *endpointP
	method := *methodP
	if endpoint == "" || method == "" || len(flag.Args()) != 1 {
		flag.Usage()
		log.Fatal("usage: swagSampler -endpoint {endpoint} -method {method} {file path}")
	}
	file := flag.Arg(0)
	specBytes, err := ioutil.ReadFile(file)
	if err != nil {
		log.Fatalf("cannot open file '%s' for reading: %s", file, err)
	}

	sampler := swagsampler.New().
		UseExample(true).
		DefaultPattern("^[A-Z][a-z]{4,9}$")
	sample, err := sampler.MkSample(specBytes, endpoint, method)
	if err != nil {
		log.Fatal(err)
	}

	b, err := json.MarshalIndent(sample, "", "  ")
	if err != nil {
		log.Fatalf("cannot marshal to json: %s", err)
	}
	fmt.Printf("%s\n", b)
}


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SwagSampler

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

func New

func New() *SwagSampler

func (*SwagSampler) DefaultExclusiveMaximum

func (s *SwagSampler) DefaultExclusiveMaximum(x bool) *SwagSampler

func (*SwagSampler) DefaultExclusiveMinimum

func (s *SwagSampler) DefaultExclusiveMinimum(x bool) *SwagSampler

func (*SwagSampler) DefaultMaxItems

func (s *SwagSampler) DefaultMaxItems(x int) *SwagSampler

func (*SwagSampler) DefaultMaxLength

func (s *SwagSampler) DefaultMaxLength(x int) *SwagSampler

func (*SwagSampler) DefaultMaxProperties

func (s *SwagSampler) DefaultMaxProperties(x int) *SwagSampler

func (*SwagSampler) DefaultMaximum

func (s *SwagSampler) DefaultMaximum(x float64) *SwagSampler

func (*SwagSampler) DefaultMinItems

func (s *SwagSampler) DefaultMinItems(x int) *SwagSampler

func (*SwagSampler) DefaultMinLength

func (s *SwagSampler) DefaultMinLength(x int) *SwagSampler

func (*SwagSampler) DefaultMinProperties

func (s *SwagSampler) DefaultMinProperties(x int) *SwagSampler

func (*SwagSampler) DefaultMinimum

func (s *SwagSampler) DefaultMinimum(x float64) *SwagSampler

func (*SwagSampler) DefaultPattern

func (s *SwagSampler) DefaultPattern(x string) *SwagSampler

func (*SwagSampler) DefaultUniqueItems

func (s *SwagSampler) DefaultUniqueItems(x bool) *SwagSampler

func (*SwagSampler) MkSample

func (s *SwagSampler) MkSample(specBytes []byte, endpoint string, method string) (interface{}, error)

func (*SwagSampler) RenderSample

func (s *SwagSampler) RenderSample(breadcrumbs *rstack.RStack, node map[interface{}]interface{}) (interface{}, error)

func (*SwagSampler) UseExample

func (s *SwagSampler) UseExample(x bool) *SwagSampler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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