@goast/core 0.3.4 → 0.3.5

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.
@@ -11,6 +11,7 @@ function collectOpenApi(apis) {
11
11
  collectDocument(data, apis);
12
12
  return data;
13
13
  }
14
+ const jsonSchemaProperties = ['$id', 'allOf', 'anyOf', 'oneOf', 'enum', 'not', 'properties', 'title', 'type'];
14
15
  function collectDocument(data, documents) {
15
16
  (0, helpers_1.collect)(data, documents, (data, document) => {
16
17
  var _a, _b, _c, _d, _e;
@@ -24,6 +25,9 @@ function collectDocument(data, documents) {
24
25
  (0, helpers_1.collectRecord)(data, (_d = document.components) === null || _d === void 0 ? void 0 : _d.responses, collectResponse);
25
26
  (0, helpers_1.collectRecord)(data, document.responses, collectResponse);
26
27
  (0, helpers_1.collectRecord)(data, (_e = document.components) === null || _e === void 0 ? void 0 : _e.headers, collectHeader);
28
+ if (Object.keys(document).some((key) => jsonSchemaProperties.includes(key))) {
29
+ collectSchema(data, document);
30
+ }
27
31
  });
28
32
  }
29
33
  function collectPaths(data, paths) {
@@ -92,9 +92,9 @@ class OpenApiParser {
92
92
  absoluteRefFile = path_1.default.resolve(path_1.default.dirname(file), refFile);
93
93
  }
94
94
  const doc = await this.loadDocument(absoluteRefFile);
95
- const value = getDeepProperty(doc.document, refPath.replace(/[/]/g, '.'));
95
+ const value = refPath ? getDeepProperty(doc.document, refPath.replace(/[/]/g, '.')) : doc.document;
96
96
  if (value && typeof value === 'object') {
97
- return this.dereference(absoluteRefFile, refPath, value);
97
+ return this.dereference(absoluteRefFile, refPath !== null && refPath !== void 0 ? refPath : '/', value);
98
98
  }
99
99
  return undefined;
100
100
  }
@@ -10,6 +10,7 @@ exports.determineEndpointName = determineEndpointName;
10
10
  exports.transformAdditionalProperties = transformAdditionalProperties;
11
11
  exports.transformSchemaProperties = transformSchemaProperties;
12
12
  exports.getOpenApiObjectIdentifier = getOpenApiObjectIdentifier;
13
+ const path_1 = require("path");
13
14
  const internal_utils_1 = require("../internal-utils");
14
15
  const utils_1 = require("../utils");
15
16
  const common_utils_1 = require("../utils/common.utils");
@@ -46,6 +47,8 @@ function determineSchemaName(schema, id) {
46
47
  if (!schema.$src) {
47
48
  console.log('woot?');
48
49
  }
50
+ if (schema.$src.path === '/')
51
+ return { name: (0, path_1.parse)(schema.$src.file).name, isGenerated: true };
49
52
  const schemaNameMatch = schema.$src.path.match(/(?<=\/components\/schemas\/|\/definitions\/)[^/]+$/i);
50
53
  if (schemaNameMatch) {
51
54
  return { name: schemaNameMatch[0], isGenerated: false };
@@ -77,7 +80,15 @@ function determineSchemaName(schema, id) {
77
80
  const parentSchemaMatch = schema.$src.path.match(/(.*)\/properties\/([^/]*)$/);
78
81
  if (parentSchemaMatch) {
79
82
  const parentSchema = (0, utils_1.getDeepProperty)(schema.$src.document, parentSchemaMatch[1].split('/').filter(Boolean));
80
- const parentSchemaName = determineSchemaName({ title: parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.title, $src: { path: parentSchemaMatch[1], document: schema.$src.document } }, id);
83
+ const parentSchemaName = determineSchemaName({
84
+ title: parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.title,
85
+ $src: {
86
+ file: schema.$src.file,
87
+ path: parentSchemaMatch[1],
88
+ document: schema.$src.document,
89
+ originalComponent: parentSchema,
90
+ },
91
+ }, id);
81
92
  if (!parentSchemaName.isGenerated) {
82
93
  return { name: `${parentSchemaName.name}_${parentSchemaMatch[2]}`, isGenerated: true };
83
94
  }
@@ -8,6 +8,7 @@ export function collectOpenApi(apis) {
8
8
  collectDocument(data, apis);
9
9
  return data;
10
10
  }
11
+ const jsonSchemaProperties = ['$id', 'allOf', 'anyOf', 'oneOf', 'enum', 'not', 'properties', 'title', 'type'];
11
12
  function collectDocument(data, documents) {
12
13
  collect(data, documents, (data, document) => {
13
14
  var _a, _b, _c, _d, _e;
@@ -21,6 +22,9 @@ function collectDocument(data, documents) {
21
22
  collectRecord(data, (_d = document.components) === null || _d === void 0 ? void 0 : _d.responses, collectResponse);
22
23
  collectRecord(data, document.responses, collectResponse);
23
24
  collectRecord(data, (_e = document.components) === null || _e === void 0 ? void 0 : _e.headers, collectHeader);
25
+ if (Object.keys(document).some((key) => jsonSchemaProperties.includes(key))) {
26
+ collectSchema(data, document);
27
+ }
24
28
  });
25
29
  }
26
30
  function collectPaths(data, paths) {
@@ -88,9 +88,9 @@ export class OpenApiParser {
88
88
  absoluteRefFile = path.resolve(path.dirname(file), refFile);
89
89
  }
90
90
  const doc = await this.loadDocument(absoluteRefFile);
91
- const value = getDeepProperty(doc.document, refPath.replace(/[/]/g, '.'));
91
+ const value = refPath ? getDeepProperty(doc.document, refPath.replace(/[/]/g, '.')) : doc.document;
92
92
  if (value && typeof value === 'object') {
93
- return this.dereference(absoluteRefFile, refPath, value);
93
+ return this.dereference(absoluteRefFile, refPath !== null && refPath !== void 0 ? refPath : '/', value);
94
94
  }
95
95
  return undefined;
96
96
  }
@@ -1,3 +1,4 @@
1
+ import { parse as parsePath } from 'path';
1
2
  import { isOpenApiObjectProperty } from '../internal-utils';
2
3
  import { getDeepProperty } from '../utils';
3
4
  import { isNullish } from '../utils/common.utils';
@@ -34,6 +35,8 @@ export function determineSchemaName(schema, id) {
34
35
  if (!schema.$src) {
35
36
  console.log('woot?');
36
37
  }
38
+ if (schema.$src.path === '/')
39
+ return { name: parsePath(schema.$src.file).name, isGenerated: true };
37
40
  const schemaNameMatch = schema.$src.path.match(/(?<=\/components\/schemas\/|\/definitions\/)[^/]+$/i);
38
41
  if (schemaNameMatch) {
39
42
  return { name: schemaNameMatch[0], isGenerated: false };
@@ -65,7 +68,15 @@ export function determineSchemaName(schema, id) {
65
68
  const parentSchemaMatch = schema.$src.path.match(/(.*)\/properties\/([^/]*)$/);
66
69
  if (parentSchemaMatch) {
67
70
  const parentSchema = getDeepProperty(schema.$src.document, parentSchemaMatch[1].split('/').filter(Boolean));
68
- const parentSchemaName = determineSchemaName({ title: parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.title, $src: { path: parentSchemaMatch[1], document: schema.$src.document } }, id);
71
+ const parentSchemaName = determineSchemaName({
72
+ title: parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.title,
73
+ $src: {
74
+ file: schema.$src.file,
75
+ path: parentSchemaMatch[1],
76
+ document: schema.$src.document,
77
+ originalComponent: parentSchema,
78
+ },
79
+ }, id);
69
80
  if (!parentSchemaName.isGenerated) {
70
81
  return { name: `${parentSchemaName.name}_${parentSchemaMatch[2]}`, isGenerated: true };
71
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goast/core",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "repository": "https://github.com/MaSch0212/goast.git",
5
5
  "description": "A tool designed to transform OpenAPI specifications into various forms with flexibility and extensibility at its core.",
6
6
  "keywords": [
@@ -1,6 +1,6 @@
1
1
  import { ApiSchemaKind, ApiSchemaAccessibility, ApiSchema, ApiSchemaProperty } from './api-types';
2
2
  import { OpenApiTransformerContext } from './types';
3
- import { Deref, OpenApiDocument, OpenApiObject } from '../parse';
3
+ import { Deref, DerefSource, OpenApiObject } from '../parse';
4
4
  export declare function determineSchemaKind<T extends {
5
5
  oneOf?: unknown;
6
6
  allOf?: unknown;
@@ -11,10 +11,7 @@ export declare function determineSchemaKind<T extends {
11
11
  }>(ctx: OpenApiTransformerContext, schema: T): ApiSchemaKind;
12
12
  export declare function determineSchemaName(schema: {
13
13
  title?: string;
14
- $src: {
15
- path: string;
16
- document: Deref<OpenApiDocument>;
17
- };
14
+ $src: DerefSource<any>;
18
15
  }, id: string): {
19
16
  name: string;
20
17
  isGenerated: boolean;