Esempio n. 1
0
func (g *Generator) generateOperation(b *descriptor.Binding) *spec.Operation {
	response := new(spec.Response)
	responses := new(spec.Responses)

	op := new(spec.Operation)
	op.Tags = make([]string, 0)
	op.Parameters = make([]spec.Parameter, 0)

	op.ID = strings.ToLower(b.Method.GetName())

	// op.Consumes = []string{"application/x-www-form-urlencoded", "application/json", "application/x-protobuf"}
	// op.Produces = []string{"application/json", "application/x-protobuf"}
	if cmt := g.file.GetCommentText(b.Method.CommentPath); cmt != nil {
		// TODO(ceram1): Cut by newline to extract summary, like golang.
		op.Summary = *cmt
		_ = strings.Index(*cmt, "\n\n") // idx to cut comment.

		op.Description = *cmt
	}

	for _, param := range b.PathParams {
		p := g.generatePathParameter(&param)
		op.Parameters = append(op.Parameters, *p)
	}

	response.Ref = messageRef(b.Method.ResponseType)

	responses.Default = response
	op.Responses = responses
	return op
}
Esempio n. 2
0
func opResponsesSetter(op *spec.Operation) func(*spec.Response, map[int]spec.Response) {
	return func(def *spec.Response, scr map[int]spec.Response) {
		if op.Responses == nil {
			op.Responses = new(spec.Responses)
		}
		op.Responses.Default = def
		op.Responses.StatusCodeResponses = scr
	}
}