@oslo-flanders/swagger-generator 1.1.1 → 1.2.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.
@@ -10,6 +10,7 @@ export declare class SwaggerGenerationService implements IService {
10
10
  private getProbleemdetailsLink;
11
11
  private getContact;
12
12
  private getLicense;
13
+ private schemaExists;
13
14
  init(): Promise<void>;
14
15
  run(): Promise<void>;
15
16
  createSwagger(schemas: any, links: any): Object;
@@ -89,6 +89,15 @@ let SwaggerGenerationService = class SwaggerGenerationService {
89
89
  url: this.configuration.licenseURL,
90
90
  };
91
91
  }
92
+ /* The schema already exists in the model. This would mean that there are identical labels, which isn't ideal
93
+ https://vlaamseoverheid.atlassian.net/browse/DATAST-2249?atlOrigin=eyJpIjoiMWYyZjVmOTFhMWExNDc4MmIwMGQxNjhkMjJmN2NhZGUiLCJwIjoiaiJ9
94
+ */
95
+ schemaExists(schema, label) {
96
+ if (schema[label]) {
97
+ this.logger.warn(`[SwaggerGenerationService]: Schema already exists for the label (${label}) and will be overwritten.`);
98
+ }
99
+ return !!schema[label];
100
+ }
92
101
  async init() {
93
102
  return this.store.addQuadsFromFile(this.configuration.input);
94
103
  }
@@ -252,7 +261,7 @@ let SwaggerGenerationService = class SwaggerGenerationService {
252
261
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
253
262
  const schemas = {};
254
263
  /* Create schema for each enumeration */
255
- for (const enumId of this.store.findSubjects(core_1.ns.oslo('assignedURI'), core_1.ns.skos('Concept'))) {
264
+ for (const enumId of this.store.getEnumerations()) {
256
265
  let label = (_a = (0, core_1.getApplicationProfileLabel)(enumId, this.store, this.configuration.language)) === null || _a === void 0 ? void 0 : _a.value;
257
266
  if (!label) {
258
267
  this.logger.error(`Unknown enum label for ${enumId.value}`);
@@ -260,6 +269,7 @@ let SwaggerGenerationService = class SwaggerGenerationService {
260
269
  }
261
270
  /* Class labels should be always pascal cased */
262
271
  label = (0, core_1.toPascalCase)(label);
272
+ this.schemaExists(schemas, label);
263
273
  schemas[label] = {
264
274
  title: label,
265
275
  type: 'object',
@@ -277,7 +287,9 @@ let SwaggerGenerationService = class SwaggerGenerationService {
277
287
  for (const classId of [
278
288
  ...this.store.findSubjects(core_1.ns.rdf('type'), core_1.ns.owl('Class')),
279
289
  ...this.store.findSubjects(core_1.ns.rdf('type'), core_1.ns.rdfs('Datatype')),
280
- ]) {
290
+ ]
291
+ // Extra filter to exclude all the enumerations since these are mentioned twice in the intermedairy format under enums and classes
292
+ .filter((val) => !(0, core_1.isEnumeration)(this.store, val))) {
281
293
  const assignedUri = this.store.getAssignedUri(classId);
282
294
  /* Primitive datatypes may not be generated */
283
295
  if (assignedUri && [...core_1.DataTypes.values()].includes(assignedUri.value))
@@ -412,6 +424,7 @@ let SwaggerGenerationService = class SwaggerGenerationService {
412
424
  },
413
425
  };
414
426
  }
427
+ this.schemaExists(schemas, label);
415
428
  /* Create components for each schema */
416
429
  schemas[label] = {
417
430
  title: label,
@@ -30,6 +30,7 @@ const Properties = new Map([
30
30
  [core_1.ns.xsd('unsignedShort').value, { '@value': { type: 'number', format: 'int32', minimum: 0, maximum: 65535 }, '@type': { type: 'string', pattern: '^UnsignedShort$' } }],
31
31
  [core_1.ns.xsd('unsignedByte').value, { '@value': { type: 'number', format: 'int32', minimum: 0, maximum: 255 }, '@type': { type: 'string', pattern: '^UnsignedByte$' } }],
32
32
  [core_1.ns.xsd('decimal').value, { '@value': { type: 'string', pattern: '(+|-)?([0-9]+(.[0-9]*)?|.[0-9]+)' }, '@type': { type: 'string', pattern: '^Decimal$' } }],
33
+ [core_1.ns.xsd('language').value, { '@value': { type: 'string', pattern: '^[a-z]{2,3}(-[A-Z]{2})?' }, '@type': { type: 'string', pattern: '^Language$' } }],
33
34
  ]);
34
35
  /* eslint-enable max-len*/
35
36
  const mapProperties = (datatype, label, subclasses, abstract, excludeClasses) => {
@@ -91,3 +91,6 @@ export interface SwaggerLink {
91
91
  parameters: Record<string, string>;
92
92
  description: string;
93
93
  }
94
+ export interface Schema {
95
+ [key: string]: any;
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslo-flanders/swagger-generator",
3
- "version": "1.1.1",
3
+ "version": "1.2.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",
@@ -40,7 +40,7 @@
40
40
  "@types/streamify-array": "^1.0.0"
41
41
  },
42
42
  "dependencies": {
43
- "@oslo-flanders/core": "^1.1.0",
43
+ "@oslo-flanders/core": "^1.2.0",
44
44
  "inversify": "^6.0.1",
45
45
  "n3": "^2.0.0",
46
46
  "rdf-data-factory": "^2.0.0",