Skip to content

Commit cb5e494

Browse files
committed
Add schemas
1 parent 9890448 commit cb5e494

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

includes/api/class-wc-rest-data-controller.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,36 @@ public function prepare_item_for_response( $resource, $request ) {
123123

124124
return $response;
125125
}
126+
127+
/**
128+
* Get the data index schema, conforming to JSON Schema.
129+
*
130+
* @return array
131+
*/
132+
public function get_item_schema() {
133+
$schema = array(
134+
'$schema' => 'http://json-schema.org/draft-04/schema#',
135+
'title' => 'data_index',
136+
'type' => 'array',
137+
'items' => array(
138+
'type' => 'object',
139+
'properties' => array(
140+
'slug' => array(
141+
'description' => __( 'Data resource ID.', 'woocommerce' ),
142+
'type' => 'string',
143+
'context' => array( 'view' ),
144+
'readonly' => true,
145+
),
146+
'description' => array(
147+
'description' => __( 'Data resource description.', 'woocommerce' ),
148+
'type' => 'string',
149+
'context' => array( 'view' ),
150+
'readonly' => true,
151+
),
152+
),
153+
),
154+
);
155+
156+
return $this->add_additional_fields_schema( $schema );
157+
}
126158
}

includes/api/class-wc-rest-data-locations-controller.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)