コード例 #1
0
ファイル: swagson.go プロジェクト: sfodje/swagson
// handleMeta extracts data from api:meta markup
// there should only be one api:meta markup tag per project
// if there is more than one, the first tag will be used
func handleMeta(swagDoc *specs.SwagDoc, docs []string) error {
	swagDoc.Swagger = "2.0"
	y := []byte(docs[0])
	j, err := yaml.YAMLToJSON(y)
	err = json.Unmarshal(j, swagDoc)
	return err
}
コード例 #2
0
ファイル: swagson_test.go プロジェクト: sfodje/swagson
func getSwagDoc() *specs.SwagDoc {
	var swagDoc specs.SwagDoc = specs.SwagDoc{}
	swagDoc.Swagger = "2.0"
	swagDoc.Info = &specs.SwagInfo{}
	swagDoc.Info.Title = "Swagger Petstore"
	swagDoc.Info.Description = `This is a sample server Petstore server.
You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).  For this sample, you can use the api key ` + "`special-key`" + ` to test the authorization filters.
`
	swagDoc.Info.TermsOfService = "http://swagger.io/terms/"
	swagDoc.Info.Contact = &specs.SwagContact{}
	swagDoc.Info.Contact.Name = "John Doe"
	swagDoc.Info.Contact.Url = "http://swagger.io"
	swagDoc.Info.Contact.Email = "*****@*****.**"
	swagDoc.Info.License = &specs.SwagLicense{}
	swagDoc.Info.License.Name = "Apache 2.0"
	swagDoc.Info.License.Url = "http://www.apache.org/licenses/LICENSE-2.0.html"
	swagDoc.Info.Version = "1.0.0"
	swagDoc.Host = "petstore.swagger.io"
	swagDoc.BasePath = "/v2"
	swagDoc.Consumes = &[]string{"application/json", "application/xml"}
	swagDoc.Produces = &[]string{"application/json", "application/xml"}
	swagDoc.Schemes = &[]string{"http"}
	swagDoc.SecurityDefinitions = &map[string]specs.SwagSecDef{}
	(*swagDoc.SecurityDefinitions)["api_key"] = specs.SwagSecDef{
		In:   "header",
		Name: "api_key",
		Type: "apiKey",
	}
	(*swagDoc.SecurityDefinitions)["petstore_auth"] = specs.SwagSecDef{
		AuthorizationUrl: "http://petstore.swagger.io/api/oauth/dialog",
		Flow:             "implicit",
		Type:             "oauth2",
		Scopes: &map[string]string{
			"read:pets":  "read your pets",
			"write:pets": "modify pets in your account",
		},
	}
	swagDoc.ExternalDocs = &specs.SwagExtDoc{
		Description: "Find out more about Swagger",
		Url:         "http://swagger.io",
	}
	swagDoc.Tags = &[]specs.SwagTag{}
	swagDoc.Tags = &[]specs.SwagTag{
		specs.SwagTag{
			Name:        "pet",
			Description: "Everything about your Pets",
			ExternalDocs: &specs.SwagExtDoc{
				Description: "Find out more",
				Url:         "http://swagger.io",
			},
		},
	}
	return &swagDoc
}