@oslo-flanders/swagger-generator 3.0.0 → 3.0.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.
@@ -17,4 +17,12 @@ export declare class SwaggerGenerationService implements IService {
17
17
  createSchemas(): Object;
18
18
  createLinks(): Object;
19
19
  writeOutput(outputFormat: OutputFormat, obj: Object, outputPath: string): Promise<void>;
20
+ /**
21
+ * Create a self-contained copy of the components object where all `$ref`
22
+ * pointers to `#/components/schemas/<name>` are replaced by the actual
23
+ * schema definition inline. Resolves recursively so that nested `$ref`
24
+ * references are also inlined. Circular references are preserved as `$ref`
25
+ * to avoid infinite recursion.
26
+ */
27
+ private resolveRefs;
20
28
  }
@@ -128,6 +128,8 @@ let SwaggerGenerationService = class SwaggerGenerationService {
128
128
  ...(Object.keys(links).length > 0 ? { links } : {}),
129
129
  },
130
130
  };
131
+ /* Create embedded (self-contained) variant with all $ref resolved inline */
132
+ const embeddedComponents = this.resolveRefs(components, schemas);
131
133
  /* Create Swagger endpoint paths as example */
132
134
  const swagger = this.createSwagger(schemas, links);
133
135
  /* Only append the language suffix when the generated language differs from the primary language */
@@ -141,6 +143,7 @@ let SwaggerGenerationService = class SwaggerGenerationService {
141
143
  for (const label of Object.keys(links))
142
144
  await this.writeOutput(format, links[label], `swagger/components/links/${label}${languageSuffix}${ext}`);
143
145
  await this.writeOutput(format, components, `swagger/components${languageSuffix}${ext}`);
146
+ await this.writeOutput(format, embeddedComponents, `swagger/_embedded${languageSuffix}${ext}`);
144
147
  await this.writeOutput(format, swagger, `swagger/example${languageSuffix}${ext}`);
145
148
  }
146
149
  }
@@ -596,6 +599,71 @@ let SwaggerGenerationService = class SwaggerGenerationService {
596
599
  (0, core_1.ensureOutputDirectory)(path.dirname(filePath));
597
600
  await (0, promises_1.writeFile)(filePath, data);
598
601
  }
602
+ /**
603
+ * Create a self-contained copy of the components object where all `$ref`
604
+ * pointers to `#/components/schemas/<name>` are replaced by the actual
605
+ * schema definition inline. Resolves recursively so that nested `$ref`
606
+ * references are also inlined. Circular references are preserved as `$ref`
607
+ * to avoid infinite recursion.
608
+ */
609
+ resolveRefs(components, schemas) {
610
+ const embedded = JSON.parse(JSON.stringify(components));
611
+ const resolving = new Set();
612
+ function walk(obj) {
613
+ if (!obj || typeof obj !== 'object') {
614
+ return;
615
+ }
616
+ if (Array.isArray(obj)) {
617
+ for (let i = 0; i < obj.length; i++) {
618
+ if (obj[i] !== null && typeof obj[i] === 'object' && obj[i].$ref) {
619
+ const match = obj[i].$ref.match(/^#\/components\/schemas\/(.+)$/);
620
+ if (match && schemas[match[1]]) {
621
+ if (resolving.has(match[1])) {
622
+ // Circular reference – keep the $ref as-is
623
+ continue;
624
+ }
625
+ resolving.add(match[1]);
626
+ obj[i] = JSON.parse(JSON.stringify(schemas[match[1]]));
627
+ walk(obj[i]);
628
+ resolving.delete(match[1]);
629
+ }
630
+ }
631
+ else {
632
+ walk(obj[i]);
633
+ }
634
+ }
635
+ }
636
+ else {
637
+ for (const key of Object.keys(obj)) {
638
+ if (key === '$ref' &&
639
+ typeof obj[key] === 'string' &&
640
+ obj.$ref.startsWith('#/components/schemas/')) {
641
+ continue;
642
+ }
643
+ if (obj[key] !== null &&
644
+ typeof obj[key] === 'object' &&
645
+ obj[key].$ref) {
646
+ const match = obj[key].$ref.match(/^#\/components\/schemas\/(.+)$/);
647
+ if (match && schemas[match[1]]) {
648
+ if (resolving.has(match[1])) {
649
+ // Circular reference – keep the $ref as-is
650
+ continue;
651
+ }
652
+ resolving.add(match[1]);
653
+ obj[key] = JSON.parse(JSON.stringify(schemas[match[1]]));
654
+ walk(obj[key]);
655
+ resolving.delete(match[1]);
656
+ }
657
+ }
658
+ else {
659
+ walk(obj[key]);
660
+ }
661
+ }
662
+ }
663
+ }
664
+ walk(embedded);
665
+ return embedded;
666
+ }
599
667
  };
600
668
  SwaggerGenerationService = __decorate([
601
669
  (0, inversify_1.injectable)(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslo-flanders/swagger-generator",
3
- "version": "3.0.0",
3
+ "version": "3.0.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",