@@ -94,7 +94,8 @@ func NewParser(request *http.Request) *Parser {
94
94
}
95
95
96
96
/*
97
- Document returns a single JSON data object from the parser.
97
+ Document returns a single JSON data object from the parser. In the process it will also validate
98
+ any data objects against the JSON API.
98
99
*/
99
100
func (p * Parser ) Document (payload io.ReadCloser ) (* Document , * Error ) {
100
101
defer closeReader (payload )
@@ -110,8 +111,15 @@ func (p *Parser) Document(payload io.ReadCloser) (*Document, *Error) {
110
111
return nil , ISE (fmt .Sprintf ("Error parsing JSON Document: %s" , decodeErr .Error ()))
111
112
}
112
113
114
+ // If the document has data, validate against specification
113
115
if document .HasData () {
114
116
for _ , object := range document .Data {
117
+
118
+ // TODO: currently this doesn't really do any user input
119
+ // validation since it is validating against the jsh
120
+ // "Object" type. Figure out how to options pass the
121
+ // corressponding user object struct in to enable this
122
+ // without making the API super clumsy.
115
123
inputErr := validateInput (object )
116
124
if inputErr != nil {
117
125
return nil , inputErr [0 ]
@@ -128,6 +136,9 @@ func (p *Parser) Document(payload io.ReadCloser) (*Document, *Error) {
128
136
return document , nil
129
137
}
130
138
139
+ /*
140
+ closeReader is a deferal helper function for closing a reader and logging any errors that might occur after the fact.
141
+ */
131
142
func closeReader (reader io.ReadCloser ) {
132
143
err := reader .Close ()
133
144
if err != nil {
0 commit comments