@@ -145,7 +145,7 @@ export default function parseHydraDocumentation(entrypointUrl, options = {}) {
145
145
146
146
return fetchEntrypointAndDocs ( entrypointUrl , options ) . then (
147
147
( { entrypoint, docs, response } ) => {
148
- const resources = [ ] , fields = [ ] ;
148
+ const resources = [ ] , fields = [ ] , operations = [ ] ;
149
149
const title = get ( docs , '[0]["http://www.w3.org/ns/hydra/core#title"][0]["@value"]' , 'API Platform' ) ;
150
150
151
151
const entrypointType = get ( entrypoint , '[0]["@type"][0]' ) ;
@@ -160,7 +160,7 @@ export default function parseHydraDocumentation(entrypointUrl, options = {}) {
160
160
161
161
// Add resources
162
162
for ( const properties of entrypointClass [ 'http://www.w3.org/ns/hydra/core#supportedProperty' ] ) {
163
- const readableFields = [ ] , resourceFields = [ ] , writableFields = [ ] , operations = [ ] ;
163
+ const readableFields = [ ] , resourceFields = [ ] , writableFields = [ ] , resourceOperations = [ ] ;
164
164
165
165
const property = get ( properties , '["http://www.w3.org/ns/hydra/core#property"][0]' ) ;
166
166
if ( ! property ) {
@@ -197,21 +197,45 @@ export default function parseHydraDocumentation(entrypointUrl, options = {}) {
197
197
}
198
198
}
199
199
200
+ // parse entrypoint's operations (a.k.a. collection operations)
201
+ if ( property [ 'http://www.w3.org/ns/hydra/core#supportedOperation' ] ) {
202
+ for ( const entrypointOperation of property [ 'http://www.w3.org/ns/hydra/core#supportedOperation' ] ) {
203
+ if ( ! entrypointOperation [ 'http://www.w3.org/ns/hydra/core#returns' ] ) {
204
+ continue ;
205
+ }
206
+
207
+ const range = entrypointOperation [ 'http://www.w3.org/ns/hydra/core#returns' ] [ 0 ] [ '@id' ] ;
208
+ const operation = new Operation (
209
+ entrypointOperation [ 'http://www.w3.org/2000/01/rdf-schema#label' ] [ 0 ] [ '@value' ] ,
210
+ {
211
+ method : entrypointOperation [ 'http://www.w3.org/ns/hydra/core#method' ] [ 0 ] [ '@value' ] ,
212
+ returns : range ,
213
+ types : entrypointOperation [ '@type' ] ,
214
+ } ,
215
+ ) ;
216
+
217
+ resourceOperations . push ( operation ) ;
218
+ operations . push ( operation ) ;
219
+ }
220
+ }
221
+
222
+ // parse resource operations (a.k.a. item operations)
200
223
for ( const supportedOperation of relatedClass [ 'http://www.w3.org/ns/hydra/core#supportedOperation' ] ) {
201
- // @todo not sure what's the best attribute to consider the operation as valid
202
224
if ( ! supportedOperation [ 'http://www.w3.org/ns/hydra/core#returns' ] ) {
203
225
continue ;
204
226
}
205
227
228
+ const range = supportedOperation [ 'http://www.w3.org/ns/hydra/core#returns' ] [ 0 ] [ '@id' ] ;
206
229
const operation = new Operation (
207
230
supportedOperation [ 'http://www.w3.org/2000/01/rdf-schema#label' ] [ 0 ] [ '@value' ] ,
208
231
{
209
232
method : supportedOperation [ 'http://www.w3.org/ns/hydra/core#method' ] [ 0 ] [ '@value' ] ,
210
- returns : supportedOperation [ 'http://www.w3.org/ns/hydra/core#returns' ] [ 0 ] [ '@id' ] ,
233
+ returns : range ,
211
234
types : supportedOperation [ '@type' ] ,
212
235
} ,
213
236
) ;
214
237
238
+ resourceOperations . push ( operation ) ;
215
239
operations . push ( operation ) ;
216
240
}
217
241
@@ -229,7 +253,7 @@ export default function parseHydraDocumentation(entrypointUrl, options = {}) {
229
253
fields : resourceFields ,
230
254
readableFields,
231
255
writableFields,
232
- operations
256
+ operations : resourceOperations
233
257
}
234
258
) ) ;
235
259
}
0 commit comments