1
1
import Api from '../Api'
2
- import Field from '../Field'
3
- import Resource from '../Resource'
4
2
import handleJson from './handleJson'
5
3
6
- /**
7
- * Extracts the short name of a resource.
8
- *
9
- * @param {string } url
10
- * @param {string } entrypointUrl
11
- * @return {string }
12
- */
13
- function guessNameFromUrl ( url , entrypointUrl ) {
14
- return url . substr ( entrypointUrl . length + 1 ) ;
15
- }
16
-
17
- /**
18
- * Finds the description of the class with the given id.
19
- *
20
- * @param {object[] } docs
21
- * @param {string } supportedClass
22
- * @return {object }
23
- */
24
- function findSupportedClass ( docs , supportedClass ) {
25
- const supportedClasses = docs [ 0 ] [ 'http://www.w3.org/ns/hydra/core#supportedClass' ] ;
26
-
27
- for ( let i = 0 ; i < supportedClasses . length ; i ++ ) {
28
- if ( supportedClasses [ i ] [ '@id' ] === supportedClass ) {
29
- return supportedClasses [ i ] ;
30
- }
31
- }
32
-
33
- throw new Error ( `The class ${ supportedClass } doesn't exist.` ) ;
34
- }
35
-
36
4
function removeTrailingSlash ( url ) {
37
5
if ( / \/ $ / . test ( url ) ) {
38
6
url = url . slice ( 0 , - 1 )
@@ -54,82 +22,7 @@ export default function parseSwaggerDocumentation(entrypointUrl) {
54
22
55
23
const title = response . info . title ;
56
24
const resources = handleJson ( response , entrypointUrl ) ;
57
-
58
- // // Add resources
59
- // for (let properties of entrypointSupportedClass['http://www.w3.org/ns/hydra/core#supportedProperty']) {
60
- // const property = properties['http://www.w3.org/ns/hydra/core#property'][0];
61
- // const entrypointSupportedOperations = property['http://www.w3.org/ns/hydra/core#supportedOperation'];
62
-
63
- // let readableFields = [];
64
- // let resourceFields = [];
65
- // let writableFields = [];
66
-
67
- // // Add fields
68
- // for (let j = 0; j < entrypointSupportedOperations.length; j++) {
69
- // let className = entrypointSupportedOperations[j]['http://www.w3.org/ns/hydra/core#returns'];
70
-
71
- // // Skip operations not having a return type
72
- // if (!className) {
73
- // continue;
74
- // }
75
-
76
- // className = className[0]['@id'];
77
-
78
- // if (0 === className.indexOf('http://www.w3.org/ns/hydra/core')) {
79
- // continue;
80
- // }
81
-
82
- // const supportedClass = findSupportedClass(docs, className);
83
- // for (let supportedProperties of supportedClass['http://www.w3.org/ns/hydra/core#supportedProperty']) {
84
- // const supportedProperty = supportedProperties['http://www.w3.org/ns/hydra/core#property'][0];
85
- // const range = supportedProperty['http://www.w3.org/2000/01/rdf-schema#range'] ? supportedProperty['http://www.w3.org/2000/01/rdf-schema#range'][0]['@id'] : null;
86
-
87
- // const field = new Field(
88
- // supportedProperty['http://www.w3.org/2000/01/rdf-schema#label'][0]['@value'],
89
- // {
90
- // id: supportedProperty['@id'],
91
- // range,
92
- // reference: 'http://www.w3.org/ns/hydra/core#Link' === property['@type'][0] ? range : null, // Will be updated in a subsequent pass
93
- // required: supportedProperties['http://www.w3.org/ns/hydra/core#required'] ? supportedProperties['http://www.w3.org/ns/hydra/core#required'][0]['@value'] : false,
94
- // description: supportedProperties['http://www.w3.org/ns/hydra/core#description'] ? supportedProperties['http://www.w3.org/ns/hydra/core#description'][0]['@value'] : ''
95
- // },
96
- // );
97
-
98
- // fields.push(field);
99
- // resourceFields.push(field);
100
-
101
- // if (supportedProperties['http://www.w3.org/ns/hydra/core#readable'][0]['@value']) {
102
- // readableFields.push(field);
103
- // }
104
-
105
- // if (supportedProperties['http://www.w3.org/ns/hydra/core#writable'][0]['@value']) {
106
- // writableFields.push(field);
107
- // }
108
- // }
109
-
110
- // resources.push(new Resource(
111
- // guessNameFromUrl(entrypoint[0][property['@id']][0]['@id'], entrypointUrl),
112
- // entrypoint[0][property['@id']][0]['@id'],
113
- // {
114
- // id: supportedClass['@id'],
115
- // title: supportedClass['http://www.w3.org/ns/hydra/core#title'][0]['@value'],
116
- // fields: resourceFields,
117
- // readableFields,
118
- // writableFields
119
- // }
120
- // ));
121
-
122
- // break;
123
- // }
124
- // }
125
-
126
- // // Resolve references
127
- // for (let field of fields) {
128
- // if (null !== field.reference) {
129
- // field.reference = resources.find(resource => resource.id === field.reference) || null;
130
- // }
131
- // }
132
-
25
+
133
26
return Promise . resolve ( { api : new Api ( entrypointUrl , { title, resources} ) , response , status : response . status } ) ;
134
27
} ,
135
28
( { response } ) => Promise . reject ( { api : new Api ( entrypointUrl , { resources : [ ] } ) , response, status : response . status } )
0 commit comments