@@ -143,4 +143,71 @@ public function prepare_item_for_response( $item, $request ) {
143143 $ response = rest_ensure_response ( $ item );
144144 return $ response ;
145145 }
146+
147+
148+ /**
149+ * Get the location schema, conforming to JSON Schema.
150+ *
151+ * @since 3.1.0
152+ * @return array
153+ */
154+ public function get_item_schema () {
155+ $ schema = array (
156+ '$schema ' => 'http://json-schema.org/draft-04/schema# ' ,
157+ 'title ' => 'data_locations ' ,
158+ 'type ' => 'array ' ,
159+ 'items ' => array (
160+ 'type ' => 'object ' ,
161+ 'properties ' => array (
162+ 'code ' => array (
163+ 'type ' => 'string ' ,
164+ 'description ' => __ ( '2-character continent code ' , 'woocommerce ' ),
165+ 'context ' => array ( 'view ' ),
166+ 'readonly ' => true ,
167+ ),
168+ 'name ' => array (
169+ 'type ' => 'string ' ,
170+ 'description ' => __ ( 'Full name of continent ' , 'woocommerce ' ),
171+ 'context ' => array ( 'view ' ),
172+ 'readonly ' => true ,
173+ ),
174+ 'countries ' => array (
175+ 'type ' => 'array ' ,
176+ 'context ' => array ( 'view ' ),
177+ 'readonly ' => true ,
178+ 'items ' => array (
179+ 'type ' => 'object ' ,
180+ 'context ' => array ( 'view ' ),
181+ 'readonly ' => true ,
182+ 'properties ' => array (
183+ 'code ' => array (
184+ 'type ' => 'string ' ,
185+ 'description ' => __ ( 'ISO3166 alpha-2 country code ' , 'woocommerce ' ),
186+ 'context ' => array ( 'view ' ),
187+ 'readonly ' => true ,
188+ ),
189+ 'name ' => array (
190+ 'type ' => 'string ' ,
191+ 'description ' => __ ( 'Full name of country ' , 'woocommerce ' ),
192+ 'context ' => array ( 'view ' ),
193+ 'readonly ' => true ,
194+ ),
195+ 'states ' => array (
196+ 'type ' => 'object ' ,
197+ 'description ' => __ ( 'List of states in (code, name) pairs ' , 'woocommerce ' ),
198+ 'context ' => array ( 'view ' ),
199+ 'readonly ' => true ,
200+ 'additionalProperties ' => array (
201+ 'type ' => 'string ' ,
202+ ),
203+ ),
204+ ),
205+ ),
206+ ),
207+ ),
208+ ),
209+ );
210+
211+ return $ this ->add_additional_fields_schema ( $ schema );
212+ }
146213}
0 commit comments