@oslo-flanders/swagger-generator 1.2.0 → 1.3.1
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 +3 -0
- package/lib/SwaggerGenerationService.d.ts +2 -2
- package/lib/SwaggerGenerationService.js +21 -10
- package/lib/SwaggerGenerationServiceRunner.js +6 -0
- package/lib/config/SwaggerGenerationServiceConfiguration.d.ts +6 -0
- package/lib/config/SwaggerGenerationServiceConfiguration.js +5 -0
- package/lib/enums/Properties.js +2 -2
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ The service is executed from the CLI and expects the following parameters:
|
|
|
37
37
|
| `--licenseURL` | URL of the license of the API | No | |
|
|
38
38
|
| `--excludeClasses` | Classes to exclude from the generated Swagger | No | Persoon Organisatie Test |
|
|
39
39
|
| `--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` |
|
|
40
41
|
| `--silent` | Suppress log messages | No | `true` or `false` (default) |
|
|
41
42
|
|
|
42
43
|
## Usage
|
|
@@ -46,4 +47,6 @@ oslo-generator-swagger --input report.jsonld --output swagger.json --language nl
|
|
|
46
47
|
oslo-generator-swagger --input report.jsonld --output swagger.json --language nl --versionSwagger 3.0.4 --versionAPI 1.0.0 --title "Mijn API" --description "Mijn API beschrijving." --contextURL http://example.com/context.jsonld --baseURL http://example.com --excludeClasses Persoon Organisatie
|
|
47
48
|
oslo-generator-swagger --input report.jsonld --output swagger.json --language nl --versionSwagger 3.0.4 --versionAPI 1.0.0 --title "Mijn API" --description "Mijn API beschrijving." --contextURL http://example.com/context.jsonld --baseURL http://example.com --excludeClasses Persoon --excludeProperties Persoon.voornaam
|
|
48
49
|
oslo-generator-swagger --input report.jsonld --output swagger.json --language nl --versionSwagger 3.0.4 --versionAPI 1.0.0 --title "Mijn API" --description "Mijn API beschrijving." --contextURL http://example.com/context.jsonld --baseURL http://example.com --excludeClasses GeregistreerdPersoon --excludeProperties Persoon.voornaam Persoon.achternaam
|
|
50
|
+
oslo-generator-swagger --input report.jsonld --output swagger.yaml --language nl --versionSwagger 3.0.4 --versionAPI 1.0.0 --title "Mijn API" --description "Mijn API beschrijving." --contextURL http://example.com/context.jsonld --baseURL http://example.com --outputFormat application/yaml
|
|
51
|
+
oslo-generator-swagger --input report.jsonld --output swagger --language nl --versionSwagger 3.0.4 --versionAPI 1.0.0 --title "Mijn API" --description "Mijn API beschrijving." --contextURL http://example.com/context.jsonld --baseURL http://example.com --outputFormat application/json application/yaml
|
|
49
52
|
```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IService } from '@oslo-flanders/core';
|
|
2
|
-
import { QuadStore, Logger } from '@oslo-flanders/core';
|
|
2
|
+
import { QuadStore, Logger, OutputFormat } from '@oslo-flanders/core';
|
|
3
3
|
import { SwaggerGenerationServiceConfiguration } from './config/SwaggerGenerationServiceConfiguration';
|
|
4
4
|
export declare class SwaggerGenerationService implements IService {
|
|
5
5
|
readonly logger: Logger;
|
|
@@ -16,5 +16,5 @@ export declare class SwaggerGenerationService implements IService {
|
|
|
16
16
|
createSwagger(schemas: any, links: any): Object;
|
|
17
17
|
createSchemas(): Object;
|
|
18
18
|
createLinks(): Object;
|
|
19
|
-
|
|
19
|
+
writeOutput(outputFormat: OutputFormat, obj: Object, outputPath: string): Promise<void>;
|
|
20
20
|
}
|
|
@@ -39,9 +39,14 @@ exports.SwaggerGenerationService = void 0;
|
|
|
39
39
|
const core_1 = require("@oslo-flanders/core");
|
|
40
40
|
const path = __importStar(require("path"));
|
|
41
41
|
const promises_1 = require("fs/promises");
|
|
42
|
+
const yaml = __importStar(require("js-yaml"));
|
|
42
43
|
const inversify_1 = require("inversify");
|
|
43
44
|
const SwaggerGenerationServiceConfiguration_1 = require("./config/SwaggerGenerationServiceConfiguration");
|
|
44
45
|
const Properties_1 = require("./enums/Properties");
|
|
46
|
+
const FILE_EXTENSIONS = {
|
|
47
|
+
[core_1.OutputFormat.Json]: '.json',
|
|
48
|
+
[core_1.OutputFormat.Yaml]: '.yaml',
|
|
49
|
+
};
|
|
45
50
|
let SwaggerGenerationService = class SwaggerGenerationService {
|
|
46
51
|
constructor(logger, config, store) {
|
|
47
52
|
this.logger = logger;
|
|
@@ -102,14 +107,10 @@ let SwaggerGenerationService = class SwaggerGenerationService {
|
|
|
102
107
|
return this.store.addQuadsFromFile(this.configuration.input);
|
|
103
108
|
}
|
|
104
109
|
async run() {
|
|
105
|
-
|
|
110
|
+
var _a;
|
|
111
|
+
/* Create schemas and links once, then write for each output format */
|
|
106
112
|
const schemas = this.createSchemas();
|
|
107
|
-
for (const label of Object.keys(schemas))
|
|
108
|
-
await this.writeJSON(schemas[label], `swagger/components/schemas/${label}.json`);
|
|
109
|
-
/* Create Swagger links */
|
|
110
113
|
const links = this.createLinks();
|
|
111
|
-
for (const label of Object.keys(links))
|
|
112
|
-
await this.writeJSON(links[label], `swagger/components/links/${label}.json`);
|
|
113
114
|
/* Create self-standing referenceable components */
|
|
114
115
|
const components = {
|
|
115
116
|
openapi: this.configuration.versionSwagger,
|
|
@@ -122,10 +123,17 @@ let SwaggerGenerationService = class SwaggerGenerationService {
|
|
|
122
123
|
},
|
|
123
124
|
components: { schemas, links },
|
|
124
125
|
};
|
|
125
|
-
await this.writeJSON(components, `swagger/components.json`);
|
|
126
126
|
/* Create Swagger endpoint paths as example */
|
|
127
127
|
const swagger = this.createSwagger(schemas, links);
|
|
128
|
-
|
|
128
|
+
for (const format of this.configuration.outputFormat) {
|
|
129
|
+
const ext = (_a = FILE_EXTENSIONS[format]) !== null && _a !== void 0 ? _a : '.json';
|
|
130
|
+
for (const label of Object.keys(schemas))
|
|
131
|
+
await this.writeOutput(format, schemas[label], `swagger/components/schemas/${label}${ext}`);
|
|
132
|
+
for (const label of Object.keys(links))
|
|
133
|
+
await this.writeOutput(format, links[label], `swagger/components/links/${label}${ext}`);
|
|
134
|
+
await this.writeOutput(format, components, `swagger/components${ext}`);
|
|
135
|
+
await this.writeOutput(format, swagger, `swagger/example${ext}`);
|
|
136
|
+
}
|
|
129
137
|
}
|
|
130
138
|
createSwagger(schemas, links) {
|
|
131
139
|
var _a, _b, _c;
|
|
@@ -516,8 +524,11 @@ let SwaggerGenerationService = class SwaggerGenerationService {
|
|
|
516
524
|
}
|
|
517
525
|
return links;
|
|
518
526
|
}
|
|
519
|
-
async
|
|
520
|
-
const
|
|
527
|
+
async writeOutput(outputFormat, obj, outputPath) {
|
|
528
|
+
const isYaml = outputFormat === core_1.OutputFormat.Yaml;
|
|
529
|
+
const data = isYaml
|
|
530
|
+
? yaml.dump(JSON.parse(JSON.stringify(obj)), { noRefs: true, lineWidth: -1 })
|
|
531
|
+
: JSON.stringify(obj, null, 2);
|
|
521
532
|
const filePath = path.join(this.configuration.output, outputPath);
|
|
522
533
|
(0, core_1.ensureOutputDirectory)(path.dirname(filePath));
|
|
523
534
|
await (0, promises_1.writeFile)(filePath, data);
|
|
@@ -46,6 +46,12 @@ class SwaggerGenerationServiceRunner extends core_1.AppRunner {
|
|
|
46
46
|
describe: 'All logs are suppressed',
|
|
47
47
|
default: false,
|
|
48
48
|
boolean: true,
|
|
49
|
+
})
|
|
50
|
+
.option('outputFormat', {
|
|
51
|
+
describe: 'Output format for the generated files. Can be specified multiple times.',
|
|
52
|
+
type: 'string',
|
|
53
|
+
array: true,
|
|
54
|
+
default: [core_1.OutputFormat.Json],
|
|
49
55
|
})
|
|
50
56
|
.demandOption([
|
|
51
57
|
'input',
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IConfiguration, YargsParams } from '@oslo-flanders/core';
|
|
2
|
+
import { OutputFormat } from '@oslo-flanders/core';
|
|
2
3
|
export declare class SwaggerGenerationServiceConfiguration implements IConfiguration {
|
|
3
4
|
/**
|
|
4
5
|
* Local path or URL to (OSLO compliant) RDF file to generate JSON-LD context from
|
|
@@ -64,6 +65,10 @@ export declare class SwaggerGenerationServiceConfiguration implements IConfigura
|
|
|
64
65
|
* An array of property names to be excluded from the generated output
|
|
65
66
|
*/
|
|
66
67
|
private _excludeProperties;
|
|
68
|
+
/**
|
|
69
|
+
* Output formats
|
|
70
|
+
*/
|
|
71
|
+
private _outputFormat;
|
|
67
72
|
createFromCli(params: YargsParams): Promise<void>;
|
|
68
73
|
get input(): string;
|
|
69
74
|
get output(): string;
|
|
@@ -81,4 +86,5 @@ export declare class SwaggerGenerationServiceConfiguration implements IConfigura
|
|
|
81
86
|
get licenseURL(): string | undefined;
|
|
82
87
|
get excludeClasses(): string[];
|
|
83
88
|
get excludeProperties(): string[];
|
|
89
|
+
get outputFormat(): OutputFormat[];
|
|
84
90
|
}
|
|
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.SwaggerGenerationServiceConfiguration = void 0;
|
|
10
|
+
const core_1 = require("@oslo-flanders/core");
|
|
10
11
|
const inversify_1 = require("inversify");
|
|
11
12
|
let SwaggerGenerationServiceConfiguration = class SwaggerGenerationServiceConfiguration {
|
|
12
13
|
async createFromCli(params) {
|
|
@@ -26,6 +27,7 @@ let SwaggerGenerationServiceConfiguration = class SwaggerGenerationServiceConfig
|
|
|
26
27
|
this._licenseURL = params.licenseURL;
|
|
27
28
|
this._excludeClasses = params.excludeClasses;
|
|
28
29
|
this._excludeProperties = params.excludeProperties;
|
|
30
|
+
this._outputFormat = params.outputFormat;
|
|
29
31
|
}
|
|
30
32
|
get input() {
|
|
31
33
|
if (!this._input) {
|
|
@@ -99,6 +101,9 @@ let SwaggerGenerationServiceConfiguration = class SwaggerGenerationServiceConfig
|
|
|
99
101
|
get excludeProperties() {
|
|
100
102
|
return this._excludeProperties || [];
|
|
101
103
|
}
|
|
104
|
+
get outputFormat() {
|
|
105
|
+
return this._outputFormat || [core_1.OutputFormat.Json];
|
|
106
|
+
}
|
|
102
107
|
};
|
|
103
108
|
SwaggerGenerationServiceConfiguration = __decorate([
|
|
104
109
|
(0, inversify_1.injectable)()
|
package/lib/enums/Properties.js
CHANGED
|
@@ -6,9 +6,9 @@ const core_1 = require("@oslo-flanders/core");
|
|
|
6
6
|
/* eslint-disable max-len */
|
|
7
7
|
const Properties = new Map([
|
|
8
8
|
[core_1.ns.rdf('langString').value, { '@value': { type: 'string' }, '@language': { type: 'string', pattern: '^nl$' } }],
|
|
9
|
-
[core_1.ns.rdfs('Literal').value, { '@value': { type: 'string' } }],
|
|
9
|
+
[core_1.ns.rdfs('Literal').value, { '@value': { type: 'string' }, '@type': { type: 'string' } }],
|
|
10
10
|
[core_1.ns.xsd('string').value, { '@value': { type: 'string' } }],
|
|
11
|
-
[core_1.ns.xsd('anyURI').value, { '@id': { type: 'string', format: 'uri' } }],
|
|
11
|
+
[core_1.ns.xsd('anyURI').value, { '@id': { type: 'string', format: 'uri' }, '@type': { type: 'string', pattern: '^AnyURI$' } }],
|
|
12
12
|
[core_1.ns.xsd('dateTime').value, { '@value': { type: 'string', format: 'date-time' }, '@type': { type: 'string', pattern: '^DateTime$' } }],
|
|
13
13
|
[core_1.ns.xsd('date').value, { '@value': { type: 'string', format: 'date' }, '@type': { type: 'string', pattern: '^Date$' } }],
|
|
14
14
|
[core_1.ns.xsd('boolean').value, { '@value': { type: 'boolean' }, '@type': { type: 'string', pattern: '^Boolean$' } }],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslo-flanders/swagger-generator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
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",
|
|
@@ -37,11 +37,13 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@rdfjs/types": "^2.0.0",
|
|
40
|
+
"@types/js-yaml": "^4.0.0",
|
|
40
41
|
"@types/streamify-array": "^1.0.0"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
43
44
|
"@oslo-flanders/core": "^1.2.0",
|
|
44
45
|
"inversify": "^6.0.1",
|
|
46
|
+
"js-yaml": "^4.1.0",
|
|
45
47
|
"n3": "^2.0.0",
|
|
46
48
|
"rdf-data-factory": "^2.0.0",
|
|
47
49
|
"rdf-parse": "^5.0.0",
|