本文整理匯總了Golang中github.com/go-openapi/spec.Operation.Summary方法的典型用法代碼示例。如果您正苦於以下問題:Golang Operation.Summary方法的具體用法?Golang Operation.Summary怎麽用?Golang Operation.Summary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/go-openapi/spec.Operation
的用法示例。
在下文中一共展示了Operation.Summary方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: generateSwaggerOperation
func (g *swaggerGenerator) generateSwaggerOperation(test IApiTest, defs spec.Definitions) (spec.Operation, error) {
op := spec.Operation{}
op.Responses = &spec.Responses{}
op.Responses.StatusCodeResponses = map[int]spec.Response{}
var description string
processedQueryParams := map[string]interface{}{}
processedPathParams := map[string]interface{}{}
processedHeaderParams := map[string]interface{}{}
for _, testCase := range test.TestCases() {
// parameter definitions are collected from 2xx tests only
if testCase.ExpectedHttpCode >= 200 && testCase.ExpectedHttpCode < 300 {
description = testCase.Description
for key, param := range testCase.Headers {
if _, ok := processedHeaderParams[key]; ok {
continue
}
specParam, err := generateSwaggerSpecParam(key, param, "header")
if err != nil {
return op, err
}
processedHeaderParams[key] = nil
op.Parameters = append(op.Parameters, specParam)
}
for key, param := range testCase.PathParams {
if _, ok := processedPathParams[key]; ok {
continue
}
param.Required = true // path parameters are always required
specParam, err := generateSwaggerSpecParam(key, param, "path")
if err != nil {
return op, err
}
processedPathParams[key] = nil
op.Parameters = append(op.Parameters, specParam)
}
for key, param := range testCase.QueryParams {
if _, ok := processedQueryParams[key]; ok {
continue
}
specParam, err := generateSwaggerSpecParam(key, param, "query")
if err != nil {
return op, err
}
processedQueryParams[key] = nil
op.Parameters = append(op.Parameters, specParam)
}
if testCase.RequestBody != nil {
specParam := spec.Parameter{}
specParam.Name = "body"
specParam.In = "body"
specParam.Required = true
// TODO: right now it supports json, but should support marshaller depending on MIME type
if content, err := json.MarshalIndent(testCase.RequestBody, "", " "); err == nil {
specParam.Description = string(content)
}
specParam.Schema = generateSpecSchema(testCase.RequestBody, defs)
op.Parameters = append(op.Parameters, specParam)
}
}
response := spec.Response{}
response.Description = testCase.Description
if testCase.ExpectedData != nil {
response.Schema = generateSpecSchema(testCase.ExpectedData, defs)
response.Examples = map[string]interface{}{
"application/json": testCase.ExpectedData,
}
}
op.Responses.StatusCodeResponses[testCase.ExpectedHttpCode] = response
}
op.Summary = description
if taggable, ok := test.(ITaggable); ok {
op.Tags = []string{taggable.Tag()}
}
return op, nil
}