At the moment I have RestController with the following code
package be.smartask.api; import be.smartask.api.model.*; import org.springframework.web.bind.annotation.*; /** * @author Glenn Van Schil * Created on 21/01/2016 */ @CrossOrigin @RestController @RequestMapping(path = "/attributes") public class Controller { @RequestMapping(value = "/number", method = RequestMethod.POST) void createAttribute(@RequestBody NumberAttribute numberAttribute) { System.out.println(numberAttribute.getName()); System.out.println(numberAttribute.getMinValue()); } } This works great, I can post a NumberAttribute like this:
<attribute id="id" name="text" self="http:" minValue="0" maxValue="10" /> But when i change the previous xml to:
<blablabla id="id" name="text" self="http:" minValue="0" maxValue="10" /> It still works.Or when I change the name="text" to namie="text" it will also work but leaving name=null in my java code.
My question is: How can i enforce a 400: Bad Request (or something like that) when the body is not exactly the same as defined in my xsd file? By defined I mean the xml tag's name is not the same or a required xs:attribute is missing, ...
My xsd file:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- AttributeVO --> <xs:complexType name="attribute"> <xs:attribute type="xs:string" name="id" use="optional"/> <xs:attribute type="xs:string" name="name" use="required"/> <xs:attribute type="xs:anyURI" name="self" use="optional"/> </xs:complexType> <xs:complexType name="numberAttribute"> <xs:complexContent> <xs:extension base="attribute"> <xs:attribute type="xs:double" name="minValue" use="optional"/> <xs:attribute type="xs:double" name="maxValue" use="optional"/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:element name="attribute" type="attribute"/> <xs:element name="numberAttribute" type="numberAttribute"/> <xs:element name="attributes"> <xs:complexType> <xs:sequence> <xs:element ref="attribute" maxOccurs="unbounded" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> <!-- END AttributeVO --> </xs:schema>
No comments:
Post a Comment