Skip to content
Snippets Groups Projects
Unverified Commit ead5c151 authored by Bob Callaway's avatar Bob Callaway Committed by GitHub
Browse files

Mark request body for create entry as required (#81)


We can't insert a blank entry, so mark request body as required.

Signed-off-by: default avatarBob Callaway <bcallawa@redhat.com>
parent b4faddc4
No related branches found
No related tags found
No related merge requests found
...@@ -75,6 +75,7 @@ paths: ...@@ -75,6 +75,7 @@ paths:
name: proposedEntry name: proposedEntry
schema: schema:
$ref: '#/definitions/ProposedEntry' $ref: '#/definitions/ProposedEntry'
required: true
responses: responses:
201: 201:
description: Returns the entry created in the transparency log description: Returns the entry created in the transparency log
......
...@@ -115,6 +115,7 @@ func init() { ...@@ -115,6 +115,7 @@ func init() {
{ {
"name": "proposedEntry", "name": "proposedEntry",
"in": "body", "in": "body",
"required": true,
"schema": { "schema": {
"$ref": "#/definitions/ProposedEntry" "$ref": "#/definitions/ProposedEntry"
} }
...@@ -579,6 +580,7 @@ func init() { ...@@ -579,6 +580,7 @@ func init() {
{ {
"name": "proposedEntry", "name": "proposedEntry",
"in": "body", "in": "body",
"required": true,
"schema": { "schema": {
"$ref": "#/definitions/ProposedEntry" "$ref": "#/definitions/ProposedEntry"
} }
......
...@@ -24,6 +24,7 @@ package entries ...@@ -24,6 +24,7 @@ package entries
import ( import (
"context" "context"
"io"
"net/http" "net/http"
"github.com/go-openapi/errors" "github.com/go-openapi/errors"
...@@ -51,6 +52,7 @@ type CreateLogEntryParams struct { ...@@ -51,6 +52,7 @@ type CreateLogEntryParams struct {
HTTPRequest *http.Request `json:"-"` HTTPRequest *http.Request `json:"-"`
/* /*
Required: true
In: body In: body
*/ */
ProposedEntry models.ProposedEntry ProposedEntry models.ProposedEntry
...@@ -69,6 +71,9 @@ func (o *CreateLogEntryParams) BindRequest(r *http.Request, route *middleware.Ma ...@@ -69,6 +71,9 @@ func (o *CreateLogEntryParams) BindRequest(r *http.Request, route *middleware.Ma
defer r.Body.Close() defer r.Body.Close()
body, err := models.UnmarshalProposedEntry(r.Body, route.Consumer) body, err := models.UnmarshalProposedEntry(r.Body, route.Consumer)
if err != nil { if err != nil {
if err == io.EOF {
err = errors.Required("proposedEntry", "body", "")
}
res = append(res, err) res = append(res, err)
} else { } else {
// validate body object // validate body object
...@@ -85,6 +90,8 @@ func (o *CreateLogEntryParams) BindRequest(r *http.Request, route *middleware.Ma ...@@ -85,6 +90,8 @@ func (o *CreateLogEntryParams) BindRequest(r *http.Request, route *middleware.Ma
o.ProposedEntry = body o.ProposedEntry = body
} }
} }
} else {
res = append(res, errors.Required("proposedEntry", "body", ""))
} }
if len(res) > 0 { if len(res) > 0 {
return errors.CompositeValidationError(res...) return errors.CompositeValidationError(res...)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment