本文整理匯總了Golang中github.com/go-openapi/spec.Swagger.Host方法的典型用法代碼示例。如果您正苦於以下問題:Golang Swagger.Host方法的具體用法?Golang Swagger.Host怎麽用?Golang Swagger.Host使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/go-openapi/spec.Swagger
的用法示例。
在下文中一共展示了Swagger.Host方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setSwaggerHost
func setSwaggerHost(swspec *spec.Swagger, lines []string) error {
lns := lines
if len(lns) == 0 || (len(lines) == 1 && len(lines[0]) == 0) {
lns = []string{"localhost"}
}
swspec.Host = lns[0]
return nil
}
示例2: TestGenerateSwaggerYAML
func TestGenerateSwaggerYAML(t *testing.T) {
seed := spec.Swagger{}
seed.Host = "testapi.my"
seed.Produces = []string{"application/json"}
seed.Consumes = []string{"application/json"}
seed.Schemes = []string{"http"}
seed.Info = &spec.Info{}
seed.Info.Description = "Our very little example API with 2 endpoints"
seed.Info.Title = "Example API"
seed.Info.Version = "0.1"
seed.BasePath = "/"
generator := NewSwaggerGeneratorYAML(seed)
tests := getTests()
doc, err := generator.Generate(tests)
assert.NoError(t, err, "could not generate docs")
// checking validity of generated swagger doc
yamlMap := map[interface{}]interface{}{}
err = yaml.Unmarshal(doc, &yamlMap)
assert.NoError(t, err, "could not unmarshal generated doc into map")
rawJSON, err := fmts.YAMLToJSON(yamlMap)
assert.NoError(t, err)
swaggerDoc, err := loads.Analyzed(rawJSON, "")
assert.NoError(t, err)
err = validate.Spec(swaggerDoc, strfmt.Default)
assert.NoError(t, err)
// checking equality of generated and expected doc
actual := map[interface{}]interface{}{}
err = yaml.Unmarshal(doc, &actual)
assert.NoError(t, err, "could not unmarshal generated doc into map")
fixture, err := ioutil.ReadFile("fixtures/swagger/swagger.yml")
assert.NoError(t, err, "could not read fixture file")
expected := map[interface{}]interface{}{}
err = yaml.Unmarshal(fixture, &expected)
assert.NoError(t, err, "could not unmarshal fixture into map")
assert.Equal(t, expected, actual)
}
示例3: generateSwaggerYAML
func generateSwaggerYAML(t *testing.T, tests []apitest.IApiTest, writer io.Writer) {
seed := spec.Swagger{}
seed.Host = "localhost"
seed.Produces = []string{"application/json"}
seed.Consumes = []string{"application/json"}
seed.Schemes = []string{"http"}
seed.Info = &spec.Info{}
seed.Info.Description = "Example API"
seed.Info.Title = "Example API"
seed.Info.Version = "0.1"
seed.BasePath = "/"
generator := apitest.NewSwaggerGeneratorYAML(seed)
doc, err := generator.Generate(tests)
if err != nil {
t.Fatalf("could not generate doc: %s", err.Error())
}
fmt.Fprint(writer, string(doc))
}