@oslo-flanders/swagger-generator 1.5.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/lib/SwaggerGenerationService.d.ts +2 -2
- package/lib/SwaggerGenerationService.js +89 -36
- package/lib/SwaggerGenerationServiceRunner.js +20 -0
- package/lib/config/SwaggerGenerationServiceConfiguration.d.ts +21 -0
- package/lib/config/SwaggerGenerationServiceConfiguration.js +17 -0
- package/lib/enums/Properties.d.ts +1 -1
- package/lib/enums/Properties.js +42 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ The service is executed from the CLI and expects the following parameters:
|
|
|
24
24
|
| `--input` | The URL or local file path of an OSLO-compliant RDF file | :heavy_check_mark: | |
|
|
25
25
|
| `--output` | The name of the output file | :heavy_check_mark: | |
|
|
26
26
|
| `--language` | The language in which the Swagger must be generated (labels) | No | |
|
|
27
|
+
| `--primaryLanguage` | The primary language of the API. Output files for this language keep their original name, while other languages get a `_{language}` suffix | No | `nl` (default) |
|
|
27
28
|
| `--versionSwagger` | Swagger OpenAPI specification version | :heavy_check_mark: | |
|
|
28
29
|
| `--versionAPI` | API version | :heavy_check_mark: | |
|
|
29
30
|
| `--title` | Title of the API document | :heavy_check_mark: | |
|
|
@@ -37,8 +38,11 @@ The service is executed from the CLI and expects the following parameters:
|
|
|
37
38
|
| `--licenseURL` | URL of the license of the API | No | |
|
|
38
39
|
| `--excludeClasses` | Classes to exclude from the generated Swagger | No | Persoon Organisatie Test |
|
|
39
40
|
| `--excludeProperties` | Properties to exclude from the generated Swagger | No | voornaam achternaam |
|
|
40
|
-
| `--outputFormat` | Output format for the generated files. Can be specified multiple times to generate multiple formats at once. | No | `application/json` (default) or `application/yaml` |
|
|
41
41
|
| `--disableLinks` | Disable the creation of links | No | `true` or `false` (default) |
|
|
42
|
+
| `--expanded` | Disable the creation of links | No | `true` or `false` (default) |
|
|
43
|
+
| `--excludeClassesExpanded` | Classes to exclude from expanding their properties in JSON-LD | No | Persoon Organisatie Test |
|
|
44
|
+
| `--excludePropertiesExpanded` | Properties to exclude from expanding in JSON-LD | No | voornaam achternaam |
|
|
45
|
+
| `--outputFormat` | Output format for the generated files. Can be specified multiple times to generate multiple formats at once. | No | `application/json` (default) or `application/yaml` |
|
|
42
46
|
| `--silent` | Suppress log messages | No | `true` or `false` (default) |
|
|
43
47
|
|
|
44
48
|
## Usage
|
|
@@ -6,8 +6,8 @@ export declare class SwaggerGenerationService implements IService {
|
|
|
6
6
|
readonly configuration: SwaggerGenerationServiceConfiguration;
|
|
7
7
|
readonly store: QuadStore;
|
|
8
8
|
constructor(logger: Logger, config: SwaggerGenerationServiceConfiguration, store: QuadStore);
|
|
9
|
-
private
|
|
10
|
-
private
|
|
9
|
+
private getProblemdetailsContent;
|
|
10
|
+
private getProblemdetailsLink;
|
|
11
11
|
private getContact;
|
|
12
12
|
private getLicense;
|
|
13
13
|
private schemaExists;
|
|
@@ -53,23 +53,23 @@ let SwaggerGenerationService = class SwaggerGenerationService {
|
|
|
53
53
|
this.configuration = config;
|
|
54
54
|
this.store = store;
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
getProblemdetailsContent() {
|
|
57
57
|
return {
|
|
58
58
|
[core_1.OutputFormat.JsonProblem]: {
|
|
59
59
|
schema: {
|
|
60
|
-
$ref: '#/components/schemas/
|
|
60
|
+
$ref: '#/components/schemas/Problemdetail',
|
|
61
61
|
},
|
|
62
62
|
},
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
getProblemdetailsLink(label) {
|
|
66
66
|
return {
|
|
67
|
-
'
|
|
67
|
+
'Problemdetail.type': {
|
|
68
68
|
operationId: `${label}GET`,
|
|
69
69
|
parameters: {
|
|
70
70
|
type: `$response.body#/type`,
|
|
71
71
|
},
|
|
72
|
-
description: 'De waarde van het attribuut `type` kan gebruikt worden om het gerefereerde object van het type `
|
|
72
|
+
description: 'De waarde van het attribuut `type` kan gebruikt worden om het gerefereerde object van het type `Problemdetail` op te halen.',
|
|
73
73
|
},
|
|
74
74
|
};
|
|
75
75
|
}
|
|
@@ -130,14 +130,18 @@ let SwaggerGenerationService = class SwaggerGenerationService {
|
|
|
130
130
|
};
|
|
131
131
|
/* Create Swagger endpoint paths as example */
|
|
132
132
|
const swagger = this.createSwagger(schemas, links);
|
|
133
|
+
/* Only append the language suffix when the generated language differs from the primary language */
|
|
134
|
+
const languageSuffix = this.configuration.language === this.configuration.primaryLanguage
|
|
135
|
+
? ''
|
|
136
|
+
: `_${this.configuration.language}`;
|
|
133
137
|
for (const format of this.configuration.outputFormat) {
|
|
134
138
|
const ext = (_a = FILE_EXTENSIONS[format]) !== null && _a !== void 0 ? _a : '.json';
|
|
135
139
|
for (const label of Object.keys(schemas))
|
|
136
|
-
await this.writeOutput(format, schemas[label], `swagger/components/schemas/${label}${ext}`);
|
|
140
|
+
await this.writeOutput(format, schemas[label], `swagger/components/schemas/${label}${languageSuffix}${ext}`);
|
|
137
141
|
for (const label of Object.keys(links))
|
|
138
|
-
await this.writeOutput(format, links[label], `swagger/components/links/${label}${ext}`);
|
|
139
|
-
await this.writeOutput(format, components, `swagger/components${ext}`);
|
|
140
|
-
await this.writeOutput(format, swagger, `swagger/example${ext}`);
|
|
142
|
+
await this.writeOutput(format, links[label], `swagger/components/links/${label}${languageSuffix}${ext}`);
|
|
143
|
+
await this.writeOutput(format, components, `swagger/components${languageSuffix}${ext}`);
|
|
144
|
+
await this.writeOutput(format, swagger, `swagger/example${languageSuffix}${ext}`);
|
|
141
145
|
}
|
|
142
146
|
}
|
|
143
147
|
createSwagger(schemas, links = {}) {
|
|
@@ -164,6 +168,9 @@ let SwaggerGenerationService = class SwaggerGenerationService {
|
|
|
164
168
|
for (const classId of this.store.findSubjects(core_1.ns.rdf('type'), core_1.ns.owl('Class'))) {
|
|
165
169
|
if (hasRootClasses && !this.store.isRootClass(classId))
|
|
166
170
|
continue;
|
|
171
|
+
/* Abstract classes should never be materialized as endpoint */
|
|
172
|
+
if (this.store.isAbstractClass(classId))
|
|
173
|
+
continue;
|
|
167
174
|
const filteredLinks = {};
|
|
168
175
|
let label = (_a = (0, core_1.getApplicationProfileLabel)(classId, this.store, this.configuration.language)) === null || _a === void 0 ? void 0 : _a.value;
|
|
169
176
|
const definition = (_b = (0, core_1.getApplicationProfileDefinition)(classId, this.store, this.configuration.language)) === null || _b === void 0 ? void 0 : _b.value;
|
|
@@ -217,48 +224,48 @@ let SwaggerGenerationService = class SwaggerGenerationService {
|
|
|
217
224
|
/* Error codes follow the RFC 7807 */
|
|
218
225
|
400: {
|
|
219
226
|
description: 'Invalid data supplied.',
|
|
220
|
-
content: this.
|
|
221
|
-
links: this.
|
|
227
|
+
content: this.getProblemdetailsContent(),
|
|
228
|
+
links: this.getProblemdetailsLink(label),
|
|
222
229
|
},
|
|
223
230
|
401: {
|
|
224
231
|
description: 'Invalid authorization.',
|
|
225
|
-
content: this.
|
|
226
|
-
links: this.
|
|
232
|
+
content: this.getProblemdetailsContent(),
|
|
233
|
+
links: this.getProblemdetailsLink(label),
|
|
227
234
|
},
|
|
228
235
|
403: {
|
|
229
236
|
description: 'Authentication failed.',
|
|
230
|
-
content: this.
|
|
231
|
-
links: this.
|
|
237
|
+
content: this.getProblemdetailsContent(),
|
|
238
|
+
links: this.getProblemdetailsLink(label),
|
|
232
239
|
},
|
|
233
240
|
404: {
|
|
234
241
|
description: 'Resource not found.',
|
|
235
|
-
content: this.
|
|
236
|
-
links: this.
|
|
242
|
+
content: this.getProblemdetailsContent(),
|
|
243
|
+
links: this.getProblemdetailsLink(label),
|
|
237
244
|
},
|
|
238
245
|
412: {
|
|
239
246
|
description: 'Pre-condition failed.',
|
|
240
|
-
content: this.
|
|
241
|
-
links: this.
|
|
247
|
+
content: this.getProblemdetailsContent(),
|
|
248
|
+
links: this.getProblemdetailsLink(label),
|
|
242
249
|
},
|
|
243
250
|
500: {
|
|
244
251
|
description: 'Unexpected Server Error.',
|
|
245
|
-
content: this.
|
|
246
|
-
links: this.
|
|
252
|
+
content: this.getProblemdetailsContent(),
|
|
253
|
+
links: this.getProblemdetailsLink(label),
|
|
247
254
|
},
|
|
248
255
|
502: {
|
|
249
256
|
description: 'Bad Gateway.',
|
|
250
|
-
content: this.
|
|
251
|
-
links: this.
|
|
257
|
+
content: this.getProblemdetailsContent(),
|
|
258
|
+
links: this.getProblemdetailsLink(label),
|
|
252
259
|
},
|
|
253
260
|
503: {
|
|
254
261
|
description: 'Service unavailable.',
|
|
255
|
-
content: this.
|
|
256
|
-
links: this.
|
|
262
|
+
content: this.getProblemdetailsContent(),
|
|
263
|
+
links: this.getProblemdetailsLink(label),
|
|
257
264
|
},
|
|
258
265
|
504: {
|
|
259
266
|
description: 'Gateway Timeout.',
|
|
260
|
-
content: this.
|
|
261
|
-
links: this.
|
|
267
|
+
content: this.getProblemdetailsContent(),
|
|
268
|
+
links: this.getProblemdetailsLink(label),
|
|
262
269
|
},
|
|
263
270
|
},
|
|
264
271
|
},
|
|
@@ -268,6 +275,32 @@ let SwaggerGenerationService = class SwaggerGenerationService {
|
|
|
268
275
|
swagger.components = {
|
|
269
276
|
schemas: {},
|
|
270
277
|
};
|
|
278
|
+
/* Add minimal ProblemDetail in case it is not present, but needed for example Swagger */
|
|
279
|
+
swagger.components.schemas['Problemdetail'] = {
|
|
280
|
+
title: 'Problemdetail',
|
|
281
|
+
type: 'object',
|
|
282
|
+
description: 'Meer gedetailleerde beschrijving van de fout in een HTTP response.',
|
|
283
|
+
properties: {
|
|
284
|
+
type: {
|
|
285
|
+
type: 'string',
|
|
286
|
+
format: 'uri',
|
|
287
|
+
},
|
|
288
|
+
title: {
|
|
289
|
+
type: 'string',
|
|
290
|
+
},
|
|
291
|
+
status: {
|
|
292
|
+
type: 'integer',
|
|
293
|
+
format: 'int64',
|
|
294
|
+
},
|
|
295
|
+
detail: {
|
|
296
|
+
type: 'string',
|
|
297
|
+
},
|
|
298
|
+
instance: {
|
|
299
|
+
type: 'string',
|
|
300
|
+
format: 'uri',
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
};
|
|
271
304
|
for (const schemaLabel of Object.keys(schemas))
|
|
272
305
|
swagger.components.schemas[schemaLabel] = schemas[schemaLabel];
|
|
273
306
|
return swagger;
|
|
@@ -382,9 +415,17 @@ let SwaggerGenerationService = class SwaggerGenerationService {
|
|
|
382
415
|
this.logger.error(`Unknown cardinality for attribute ${attributeId.value}`);
|
|
383
416
|
continue;
|
|
384
417
|
}
|
|
418
|
+
/* Expanded JSON-LD depends on configuration */
|
|
419
|
+
let expanded = this.configuration.expanded;
|
|
420
|
+
if (this.configuration.excludeClassesExpanded.includes(label)) {
|
|
421
|
+
expanded = false;
|
|
422
|
+
}
|
|
423
|
+
if (this.configuration.excludePropertiesExpanded.includes(`${label}.${attributeLabel}`)) {
|
|
424
|
+
expanded = false;
|
|
425
|
+
}
|
|
385
426
|
/* Arrays must be introduced into the schema if the max cardinality is 2 or more */
|
|
386
427
|
const description = `${attributeDefinition}${attributeUsageNote ? ' ' + attributeUsageNote : ''}`;
|
|
387
|
-
const properties = (0, Properties_1.mapProperties)(attributeDatatypeId, attributeDatatypeLabel, subclasses, attributeDatatypeAbstract, this.configuration.excludeClasses);
|
|
428
|
+
const properties = (0, Properties_1.mapProperties)(attributeDatatypeId, attributeDatatypeLabel, subclasses, attributeDatatypeAbstract, this.configuration.excludeClasses, expanded);
|
|
388
429
|
// If mapProperties returns nothing, the property pointed to an excluded class (this.configuration.excludeClasses)
|
|
389
430
|
if (!properties) {
|
|
390
431
|
continue;
|
|
@@ -397,13 +438,22 @@ let SwaggerGenerationService = class SwaggerGenerationService {
|
|
|
397
438
|
if (isPrimitive) {
|
|
398
439
|
/* Wrap primitive property in its own named schema to avoid naming collisions */
|
|
399
440
|
const schemaName = `${label}.${attributeLabel}`;
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
441
|
+
if (expanded) {
|
|
442
|
+
schemas[schemaName] = {
|
|
443
|
+
title: schemaName,
|
|
444
|
+
type: 'object',
|
|
445
|
+
description: description,
|
|
446
|
+
properties: properties,
|
|
447
|
+
required: requiredProperties,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
schemas[schemaName] = {
|
|
452
|
+
title: schemaName,
|
|
453
|
+
description: description,
|
|
454
|
+
...properties,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
407
457
|
item = { $ref: `#/components/schemas/${schemaName}` };
|
|
408
458
|
}
|
|
409
459
|
else {
|
|
@@ -537,7 +587,10 @@ let SwaggerGenerationService = class SwaggerGenerationService {
|
|
|
537
587
|
async writeOutput(outputFormat, obj, outputPath) {
|
|
538
588
|
const isYaml = outputFormat === core_1.OutputFormat.Yaml;
|
|
539
589
|
const data = isYaml
|
|
540
|
-
? yaml.dump(JSON.parse(JSON.stringify(obj)), {
|
|
590
|
+
? yaml.dump(JSON.parse(JSON.stringify(obj)), {
|
|
591
|
+
noRefs: true,
|
|
592
|
+
lineWidth: -1,
|
|
593
|
+
})
|
|
541
594
|
: JSON.stringify(obj, null, 2);
|
|
542
595
|
const filePath = path.join(this.configuration.output, outputPath);
|
|
543
596
|
(0, core_1.ensureOutputDirectory)(path.dirname(filePath));
|
|
@@ -19,6 +19,10 @@ class SwaggerGenerationServiceRunner extends core_1.AppRunner {
|
|
|
19
19
|
})
|
|
20
20
|
.option('versionAPI', { describe: 'API version.' })
|
|
21
21
|
.option('language', { describe: 'API language tag.', default: 'nl' })
|
|
22
|
+
.option('primaryLanguage', {
|
|
23
|
+
describe: 'The primary language of the API. Output files for this language keep their original name, while other languages get a `_{language}` suffix.',
|
|
24
|
+
default: 'nl',
|
|
25
|
+
})
|
|
22
26
|
.option('title', {
|
|
23
27
|
describe: 'API title.',
|
|
24
28
|
type: 'string',
|
|
@@ -46,6 +50,21 @@ class SwaggerGenerationServiceRunner extends core_1.AppRunner {
|
|
|
46
50
|
describe: 'Disable the creation of links.',
|
|
47
51
|
default: false,
|
|
48
52
|
boolean: true,
|
|
53
|
+
})
|
|
54
|
+
.option('expanded', {
|
|
55
|
+
describe: 'Use JSON-LD expanded format instead of default compact format.',
|
|
56
|
+
default: false,
|
|
57
|
+
boolean: true,
|
|
58
|
+
})
|
|
59
|
+
.option('excludeClassesExpanded', {
|
|
60
|
+
describe: 'A list of class names to exclude from expanding their properties with JSON-LD expansion.',
|
|
61
|
+
type: 'string',
|
|
62
|
+
array: true,
|
|
63
|
+
})
|
|
64
|
+
.option('excludePropertiesExpanded', {
|
|
65
|
+
describe: 'A list of property names to exclude from JSON-LD expansion.',
|
|
66
|
+
type: 'string',
|
|
67
|
+
array: true,
|
|
49
68
|
})
|
|
50
69
|
.option('silent', {
|
|
51
70
|
describe: 'All logs are suppressed',
|
|
@@ -66,6 +85,7 @@ class SwaggerGenerationServiceRunner extends core_1.AppRunner {
|
|
|
66
85
|
'title',
|
|
67
86
|
'contextURL',
|
|
68
87
|
'baseURL',
|
|
88
|
+
'language'
|
|
69
89
|
])
|
|
70
90
|
.help('h')
|
|
71
91
|
.alias('h', 'help');
|
|
@@ -13,6 +13,11 @@ export declare class SwaggerGenerationServiceConfiguration implements IConfigura
|
|
|
13
13
|
* The language of the labels that are used in the context
|
|
14
14
|
*/
|
|
15
15
|
private _language;
|
|
16
|
+
/**
|
|
17
|
+
* The primary language of the API. Output files for this language keep their
|
|
18
|
+
* original name, while files for other languages get a `_{language}` suffix.
|
|
19
|
+
*/
|
|
20
|
+
private _primaryLanguage;
|
|
16
21
|
/**
|
|
17
22
|
* Swagger version
|
|
18
23
|
*/
|
|
@@ -73,10 +78,23 @@ export declare class SwaggerGenerationServiceConfiguration implements IConfigura
|
|
|
73
78
|
* Whether to disable the creation of links
|
|
74
79
|
*/
|
|
75
80
|
private _disableLinks;
|
|
81
|
+
/**
|
|
82
|
+
* Whether to use expanded JSON-LD format or not
|
|
83
|
+
*/
|
|
84
|
+
private _expanded;
|
|
85
|
+
/**
|
|
86
|
+
* An array of class names to be excluded from expansion
|
|
87
|
+
*/
|
|
88
|
+
private _excludeClassesExpanded;
|
|
89
|
+
/**
|
|
90
|
+
* An array of property names to be excluded from expansion
|
|
91
|
+
*/
|
|
92
|
+
private _excludePropertiesExpanded;
|
|
76
93
|
createFromCli(params: YargsParams): Promise<void>;
|
|
77
94
|
get input(): string;
|
|
78
95
|
get output(): string;
|
|
79
96
|
get language(): string;
|
|
97
|
+
get primaryLanguage(): string;
|
|
80
98
|
get versionSwagger(): string;
|
|
81
99
|
get versionAPI(): string;
|
|
82
100
|
get title(): string;
|
|
@@ -92,4 +110,7 @@ export declare class SwaggerGenerationServiceConfiguration implements IConfigura
|
|
|
92
110
|
get excludeProperties(): string[];
|
|
93
111
|
get outputFormat(): OutputFormat[];
|
|
94
112
|
get disableLinks(): boolean;
|
|
113
|
+
get expanded(): boolean;
|
|
114
|
+
get excludeClassesExpanded(): string[];
|
|
115
|
+
get excludePropertiesExpanded(): string[];
|
|
95
116
|
}
|
|
@@ -14,6 +14,7 @@ let SwaggerGenerationServiceConfiguration = class SwaggerGenerationServiceConfig
|
|
|
14
14
|
this._input = params.input;
|
|
15
15
|
this._output = params.output;
|
|
16
16
|
this._language = params.language;
|
|
17
|
+
this._primaryLanguage = params.primaryLanguage;
|
|
17
18
|
this._versionSwagger = params.versionSwagger;
|
|
18
19
|
this._versionAPI = params.versionAPI;
|
|
19
20
|
this._title = params.title;
|
|
@@ -29,6 +30,9 @@ let SwaggerGenerationServiceConfiguration = class SwaggerGenerationServiceConfig
|
|
|
29
30
|
this._excludeProperties = params.excludeProperties;
|
|
30
31
|
this._outputFormat = params.outputFormat;
|
|
31
32
|
this._disableLinks = params.disableLinks;
|
|
33
|
+
this._expanded = params.expanded;
|
|
34
|
+
this._excludeClassesExpanded = params.excludeClassesExpanded;
|
|
35
|
+
this._excludePropertiesExpanded = (params.excludePropertiesExpanded);
|
|
32
36
|
}
|
|
33
37
|
get input() {
|
|
34
38
|
if (!this._input) {
|
|
@@ -48,6 +52,10 @@ let SwaggerGenerationServiceConfiguration = class SwaggerGenerationServiceConfig
|
|
|
48
52
|
}
|
|
49
53
|
return this._language;
|
|
50
54
|
}
|
|
55
|
+
get primaryLanguage() {
|
|
56
|
+
/* Default to Dutch, which is the primary language of the OSLO standards */
|
|
57
|
+
return this._primaryLanguage || 'nl';
|
|
58
|
+
}
|
|
51
59
|
get versionSwagger() {
|
|
52
60
|
if (!this._versionSwagger) {
|
|
53
61
|
throw new Error(`Trying to access property "versionSwagger" before it was set.`);
|
|
@@ -108,6 +116,15 @@ let SwaggerGenerationServiceConfiguration = class SwaggerGenerationServiceConfig
|
|
|
108
116
|
get disableLinks() {
|
|
109
117
|
return !!this._disableLinks;
|
|
110
118
|
}
|
|
119
|
+
get expanded() {
|
|
120
|
+
return !!this._expanded;
|
|
121
|
+
}
|
|
122
|
+
get excludeClassesExpanded() {
|
|
123
|
+
return this._excludeClassesExpanded || [];
|
|
124
|
+
}
|
|
125
|
+
get excludePropertiesExpanded() {
|
|
126
|
+
return this._excludePropertiesExpanded || [];
|
|
127
|
+
}
|
|
111
128
|
};
|
|
112
129
|
SwaggerGenerationServiceConfiguration = __decorate([
|
|
113
130
|
(0, inversify_1.injectable)()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const mapProperties: (datatype: string, label: string, subclasses: string[], abstract: boolean, excludeClasses: string[]) => object | undefined;
|
|
1
|
+
export declare const mapProperties: (datatype: string, label: string, subclasses: string[], abstract: boolean, excludeClasses: string[], expanded: boolean) => object | undefined;
|
package/lib/enums/Properties.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.mapProperties = void 0;
|
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-loss-of-precision */
|
|
5
5
|
const core_1 = require("@oslo-flanders/core");
|
|
6
6
|
/* eslint-disable max-len */
|
|
7
|
-
const
|
|
7
|
+
const PropertiesExpanded = new Map([
|
|
8
8
|
[core_1.ns.rdf('langString').value, { '@value': { type: 'string' }, '@language': { type: 'string', pattern: '^nl$' } }],
|
|
9
9
|
[core_1.ns.rdfs('Literal').value, { '@value': { type: 'string' }, '@type': { type: 'string' } }],
|
|
10
10
|
[core_1.ns.xsd('string').value, { '@value': { type: 'string' } }],
|
|
@@ -32,12 +32,49 @@ const Properties = new Map([
|
|
|
32
32
|
[core_1.ns.xsd('decimal').value, { '@value': { type: 'string', pattern: '(+|-)?([0-9]+(.[0-9]*)?|.[0-9]+)' }, '@type': { type: 'string', pattern: '^Decimal$' } }],
|
|
33
33
|
[core_1.ns.xsd('language').value, { '@value': { type: 'string', pattern: '^[a-z]{2,3}(-[A-Z]{2})?' }, '@type': { type: 'string', pattern: '^Language$' } }],
|
|
34
34
|
]);
|
|
35
|
+
/* JSON-LD context provides values for @type and @language for primitive datatypes */
|
|
36
|
+
const PropertiesCompacted = new Map([
|
|
37
|
+
[core_1.ns.rdf('langString').value, { type: 'string' }],
|
|
38
|
+
[core_1.ns.rdfs('Literal').value, { type: 'string' }],
|
|
39
|
+
[core_1.ns.xsd('string').value, { type: 'string' }],
|
|
40
|
+
[core_1.ns.xsd('anyURI').value, { type: 'string', format: 'uri' }],
|
|
41
|
+
[core_1.ns.xsd('dateTime').value, { type: 'string', format: 'date-time' }],
|
|
42
|
+
[core_1.ns.xsd('date').value, { type: 'string', format: 'date' }],
|
|
43
|
+
[core_1.ns.xsd('boolean').value, { type: 'boolean' }],
|
|
44
|
+
[core_1.ns.xsd('integer').value, { type: 'number', format: 'int64' }],
|
|
45
|
+
[core_1.ns.xsd('long').value, { type: 'number', format: 'int64', minimum: -9223372036854776000, maximum: 9223372036854776000 }],
|
|
46
|
+
[core_1.ns.xsd('float').value, { type: 'number', format: 'float' }],
|
|
47
|
+
[core_1.ns.xsd('double').value, { type: 'number', format: 'double' }],
|
|
48
|
+
[core_1.ns.xsd('int').value, { type: 'number', format: 'int32', minimum: -2147483648, maximum: 2147483647 }],
|
|
49
|
+
[core_1.ns.xsd('short').value, { type: 'number', format: 'int32', minimum: -32768, maximum: 32767 }],
|
|
50
|
+
[core_1.ns.xsd('byte').value, { type: 'number', format: 'int32', minimum: -128, maximum: 127 }],
|
|
51
|
+
[core_1.ns.xsd('hexBinary').value, { type: 'string', format: 'binary' }],
|
|
52
|
+
[core_1.ns.xsd('base64Binary').value, { type: 'string', format: 'byte' }],
|
|
53
|
+
[core_1.ns.xsd('nonNegativeInteger').value, { type: 'number', format: 'int64' }],
|
|
54
|
+
[core_1.ns.xsd('nonPositiveInteger').value, { type: 'number', format: 'int64' }],
|
|
55
|
+
[core_1.ns.xsd('negativeInteger').value, { type: 'number', format: 'int64', maximum: 0 }],
|
|
56
|
+
[core_1.ns.xsd('positiveInteger').value, { type: 'number', format: 'int64', minimum: 1 }],
|
|
57
|
+
[core_1.ns.xsd('unsignedLong').value, { type: 'number', format: 'int64', minimum: 0, maximum: 18446744073709552000 }],
|
|
58
|
+
[core_1.ns.xsd('unsignedInt').value, { type: 'number', format: 'int32', minimum: 0, maximum: 4294967295 }],
|
|
59
|
+
[core_1.ns.xsd('unsignedShort').value, { type: 'number', format: 'int32', minimum: 0, maximum: 65535 }],
|
|
60
|
+
[core_1.ns.xsd('unsignedByte').value, { type: 'number', format: 'int32', minimum: 0, maximum: 255 }],
|
|
61
|
+
[core_1.ns.xsd('decimal').value, { type: 'string', pattern: '(+|-)?([0-9]+(.[0-9]*)?|.[0-9]+)' }],
|
|
62
|
+
[core_1.ns.xsd('language').value, { type: 'string', pattern: '^[a-z]{2,3}(-[A-Z]{2})?' }],
|
|
63
|
+
]);
|
|
35
64
|
/* eslint-enable max-len*/
|
|
36
|
-
const mapProperties = (datatype, label, subclasses, abstract, excludeClasses) => {
|
|
65
|
+
const mapProperties = (datatype, label, subclasses, abstract, excludeClasses, expanded) => {
|
|
37
66
|
/* Primitive data type conversion from Linked Data to Swagger */
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
67
|
+
if (expanded) {
|
|
68
|
+
if (PropertiesExpanded.has(datatype)) {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
70
|
+
return PropertiesExpanded.get(datatype);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
if (PropertiesCompacted.has(datatype)) {
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
76
|
+
return PropertiesCompacted.get(datatype);
|
|
77
|
+
}
|
|
41
78
|
}
|
|
42
79
|
const oneOf = [];
|
|
43
80
|
// Add the superclass to the list if it's not abstract and not excluded
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslo-flanders/swagger-generator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Generate OpenAPI Swagger YAML documentation.",
|
|
5
5
|
"author": "Digitaal Vlaanderen <https://data.vlaanderen.be/id/organisatie/OVO002949>",
|
|
6
6
|
"homepage": "https://github.com/informatievlaanderen/OSLO-UML-Transformer/tree/main/packages/oslo-generator-swagger#readme",
|