@goast/core 0.3.3 → 0.3.4

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.
@@ -18,7 +18,8 @@ function determineSchemaKind(ctx, schema) {
18
18
  return 'oneOf';
19
19
  }
20
20
  else if (schema.type !== 'object' && (schema.allOf || schema.anyOf)) {
21
- return 'combined';
21
+ const hasProperties = (schema.properties && Object.keys(schema.properties).length > 0) || schema.additionalProperties;
22
+ return hasProperties ? 'object' : 'combined';
22
23
  }
23
24
  else if (Array.isArray(schema.type)) {
24
25
  return 'multi-type';
@@ -79,76 +79,57 @@ function transformSchema(ctx, schema) {
79
79
  ctx.schemas.set(schemaSource, completeSchema);
80
80
  return completeSchema;
81
81
  }
82
- const schemaTransformers = {
83
- oneOf: (schema, context) => {
84
- var _a, _b;
85
- return ({
86
- oneOf: (_b = (_a = schema.oneOf) === null || _a === void 0 ? void 0 : _a.map((s) => transformSchema(context, s))) !== null && _b !== void 0 ? _b : [],
87
- });
88
- },
89
- string: (schema) => ({
90
- type: 'string',
82
+ function allExtensionsTransformer(schema, context) {
83
+ var _a, _b, _c, _d, _e, _f;
84
+ return {
85
+ oneOf: (_b = (_a = schema.oneOf) === null || _a === void 0 ? void 0 : _a.map((s) => transformSchema(context, s))) !== null && _b !== void 0 ? _b : [],
91
86
  format: schema.format,
92
87
  pattern: schema.pattern,
93
88
  minLength: schema.minLength,
94
89
  maxLength: schema.maxLength,
95
- }),
96
- number: (schema) => ({
97
- type: 'number',
98
- format: schema.format,
99
90
  minimum: schema.minimum,
100
91
  maximum: schema.maximum,
92
+ properties: (0, helpers_1.transformSchemaProperties)(context, schema, transformSchema),
93
+ additionalProperties: (0, helpers_1.transformAdditionalProperties)(context, schema, transformSchema),
94
+ allOf: (_d = (_c = schema.allOf) === null || _c === void 0 ? void 0 : _c.map((s) => transformSchema(context, s))) !== null && _d !== void 0 ? _d : [],
95
+ anyOf: (_f = (_e = schema.anyOf) === null || _e === void 0 ? void 0 : _e.map((s) => transformSchema(context, s))) !== null && _f !== void 0 ? _f : [],
96
+ items: schema.items ? transformSchema(context, schema.items) : undefined,
97
+ minItems: schema.minItems,
98
+ maxItems: schema.maxItems,
99
+ };
100
+ }
101
+ const schemaTransformers = {
102
+ oneOf: (schema, context) => ({
103
+ ...allExtensionsTransformer(schema, context),
104
+ }),
105
+ string: (schema, context) => ({
106
+ type: 'string',
107
+ ...allExtensionsTransformer(schema, context),
108
+ }),
109
+ number: (schema, context) => ({
110
+ type: 'number',
111
+ ...allExtensionsTransformer(schema, context),
101
112
  }),
102
- boolean: (schema) => ({ type: 'boolean', format: schema.format }),
103
- object: (schema, context) => {
104
- var _a, _b, _c, _d;
105
- return ({
106
- type: 'object',
107
- properties: (0, helpers_1.transformSchemaProperties)(context, schema, transformSchema),
108
- format: schema.format,
109
- additionalProperties: (0, helpers_1.transformAdditionalProperties)(context, schema, transformSchema),
110
- allOf: (_b = (_a = schema.allOf) === null || _a === void 0 ? void 0 : _a.map((s) => transformSchema(context, s))) !== null && _b !== void 0 ? _b : [],
111
- anyOf: (_d = (_c = schema.anyOf) === null || _c === void 0 ? void 0 : _c.map((s) => transformSchema(context, s))) !== null && _d !== void 0 ? _d : [],
112
- });
113
- },
114
- integer: (schema) => ({
113
+ boolean: (schema, context) => ({ type: 'boolean', ...allExtensionsTransformer(schema, context) }),
114
+ object: (schema, context) => ({
115
+ type: 'object',
116
+ ...allExtensionsTransformer(schema, context),
117
+ }),
118
+ integer: (schema, context) => ({
115
119
  type: 'integer',
116
- format: schema.format,
117
- minimum: schema.minimum,
118
- maximum: schema.maximum,
120
+ ...allExtensionsTransformer(schema, context),
119
121
  }),
120
122
  array: (schema, context) => ({
121
123
  type: 'array',
122
- items: schema.items ? transformSchema(context, schema.items) : undefined,
123
- minItems: schema.minItems,
124
- maxItems: schema.maxItems,
124
+ ...allExtensionsTransformer(schema, context),
125
+ }),
126
+ combined: (schema, context) => ({
127
+ ...allExtensionsTransformer(schema, context),
128
+ }),
129
+ 'multi-type': (schema, context) => ({
130
+ type: schema.type,
131
+ ...allExtensionsTransformer(schema, context),
125
132
  }),
126
- combined: (schema, context) => {
127
- var _a, _b, _c, _d;
128
- return ({
129
- allOf: (_b = (_a = schema.allOf) === null || _a === void 0 ? void 0 : _a.map((s) => transformSchema(context, s))) !== null && _b !== void 0 ? _b : [],
130
- anyOf: (_d = (_c = schema.anyOf) === null || _c === void 0 ? void 0 : _c.map((s) => transformSchema(context, s))) !== null && _d !== void 0 ? _d : [],
131
- });
132
- },
133
- 'multi-type': (schema, context) => {
134
- var _a, _b, _c, _d;
135
- return ({
136
- type: schema.type,
137
- items: schema.items ? transformSchema(context, schema.items) : undefined,
138
- minItems: schema.minItems,
139
- maxItems: schema.maxItems,
140
- minimum: schema.minimum,
141
- maximum: schema.maximum,
142
- format: schema.format,
143
- properties: (0, helpers_1.transformSchemaProperties)(context, schema, transformSchema),
144
- additionalProperties: (0, helpers_1.transformAdditionalProperties)(context, schema, transformSchema),
145
- allOf: (_b = (_a = schema.allOf) === null || _a === void 0 ? void 0 : _a.map((s) => transformSchema(context, s))) !== null && _b !== void 0 ? _b : [],
146
- anyOf: (_d = (_c = schema.anyOf) === null || _c === void 0 ? void 0 : _c.map((s) => transformSchema(context, s))) !== null && _d !== void 0 ? _d : [],
147
- maxLength: schema.maxLength,
148
- minLength: schema.minLength,
149
- pattern: schema.pattern,
150
- });
151
- },
152
133
  null: () => ({ type: 'null' }),
153
134
  unknown: () => ({}),
154
135
  };
@@ -9,6 +9,9 @@ function resolveAnyOfAndAllOf(schema, ignoreNonObjectParts) {
9
9
  }
10
10
  const required = new Set(schema.required);
11
11
  const properties = new Map();
12
+ if ('properties' in schema) {
13
+ schema.properties.forEach((prop) => properties.set(prop.name, prop));
14
+ }
12
15
  collectSubSchemaProperties(schema.allOf, properties, required, false);
13
16
  collectSubSchemaProperties(schema.anyOf, properties, required, true);
14
17
  const initialAdditionalProperties = schema.kind === 'object' ? schema.additionalProperties : undefined;
@@ -6,7 +6,8 @@ export function determineSchemaKind(ctx, schema) {
6
6
  return 'oneOf';
7
7
  }
8
8
  else if (schema.type !== 'object' && (schema.allOf || schema.anyOf)) {
9
- return 'combined';
9
+ const hasProperties = (schema.properties && Object.keys(schema.properties).length > 0) || schema.additionalProperties;
10
+ return hasProperties ? 'object' : 'combined';
10
11
  }
11
12
  else if (Array.isArray(schema.type)) {
12
13
  return 'multi-type';
@@ -76,76 +76,57 @@ export function transformSchema(ctx, schema) {
76
76
  ctx.schemas.set(schemaSource, completeSchema);
77
77
  return completeSchema;
78
78
  }
79
- const schemaTransformers = {
80
- oneOf: (schema, context) => {
81
- var _a, _b;
82
- return ({
83
- oneOf: (_b = (_a = schema.oneOf) === null || _a === void 0 ? void 0 : _a.map((s) => transformSchema(context, s))) !== null && _b !== void 0 ? _b : [],
84
- });
85
- },
86
- string: (schema) => ({
87
- type: 'string',
79
+ function allExtensionsTransformer(schema, context) {
80
+ var _a, _b, _c, _d, _e, _f;
81
+ return {
82
+ oneOf: (_b = (_a = schema.oneOf) === null || _a === void 0 ? void 0 : _a.map((s) => transformSchema(context, s))) !== null && _b !== void 0 ? _b : [],
88
83
  format: schema.format,
89
84
  pattern: schema.pattern,
90
85
  minLength: schema.minLength,
91
86
  maxLength: schema.maxLength,
92
- }),
93
- number: (schema) => ({
94
- type: 'number',
95
- format: schema.format,
96
87
  minimum: schema.minimum,
97
88
  maximum: schema.maximum,
89
+ properties: transformSchemaProperties(context, schema, transformSchema),
90
+ additionalProperties: transformAdditionalProperties(context, schema, transformSchema),
91
+ allOf: (_d = (_c = schema.allOf) === null || _c === void 0 ? void 0 : _c.map((s) => transformSchema(context, s))) !== null && _d !== void 0 ? _d : [],
92
+ anyOf: (_f = (_e = schema.anyOf) === null || _e === void 0 ? void 0 : _e.map((s) => transformSchema(context, s))) !== null && _f !== void 0 ? _f : [],
93
+ items: schema.items ? transformSchema(context, schema.items) : undefined,
94
+ minItems: schema.minItems,
95
+ maxItems: schema.maxItems,
96
+ };
97
+ }
98
+ const schemaTransformers = {
99
+ oneOf: (schema, context) => ({
100
+ ...allExtensionsTransformer(schema, context),
101
+ }),
102
+ string: (schema, context) => ({
103
+ type: 'string',
104
+ ...allExtensionsTransformer(schema, context),
105
+ }),
106
+ number: (schema, context) => ({
107
+ type: 'number',
108
+ ...allExtensionsTransformer(schema, context),
98
109
  }),
99
- boolean: (schema) => ({ type: 'boolean', format: schema.format }),
100
- object: (schema, context) => {
101
- var _a, _b, _c, _d;
102
- return ({
103
- type: 'object',
104
- properties: transformSchemaProperties(context, schema, transformSchema),
105
- format: schema.format,
106
- additionalProperties: transformAdditionalProperties(context, schema, transformSchema),
107
- allOf: (_b = (_a = schema.allOf) === null || _a === void 0 ? void 0 : _a.map((s) => transformSchema(context, s))) !== null && _b !== void 0 ? _b : [],
108
- anyOf: (_d = (_c = schema.anyOf) === null || _c === void 0 ? void 0 : _c.map((s) => transformSchema(context, s))) !== null && _d !== void 0 ? _d : [],
109
- });
110
- },
111
- integer: (schema) => ({
110
+ boolean: (schema, context) => ({ type: 'boolean', ...allExtensionsTransformer(schema, context) }),
111
+ object: (schema, context) => ({
112
+ type: 'object',
113
+ ...allExtensionsTransformer(schema, context),
114
+ }),
115
+ integer: (schema, context) => ({
112
116
  type: 'integer',
113
- format: schema.format,
114
- minimum: schema.minimum,
115
- maximum: schema.maximum,
117
+ ...allExtensionsTransformer(schema, context),
116
118
  }),
117
119
  array: (schema, context) => ({
118
120
  type: 'array',
119
- items: schema.items ? transformSchema(context, schema.items) : undefined,
120
- minItems: schema.minItems,
121
- maxItems: schema.maxItems,
121
+ ...allExtensionsTransformer(schema, context),
122
+ }),
123
+ combined: (schema, context) => ({
124
+ ...allExtensionsTransformer(schema, context),
125
+ }),
126
+ 'multi-type': (schema, context) => ({
127
+ type: schema.type,
128
+ ...allExtensionsTransformer(schema, context),
122
129
  }),
123
- combined: (schema, context) => {
124
- var _a, _b, _c, _d;
125
- return ({
126
- allOf: (_b = (_a = schema.allOf) === null || _a === void 0 ? void 0 : _a.map((s) => transformSchema(context, s))) !== null && _b !== void 0 ? _b : [],
127
- anyOf: (_d = (_c = schema.anyOf) === null || _c === void 0 ? void 0 : _c.map((s) => transformSchema(context, s))) !== null && _d !== void 0 ? _d : [],
128
- });
129
- },
130
- 'multi-type': (schema, context) => {
131
- var _a, _b, _c, _d;
132
- return ({
133
- type: schema.type,
134
- items: schema.items ? transformSchema(context, schema.items) : undefined,
135
- minItems: schema.minItems,
136
- maxItems: schema.maxItems,
137
- minimum: schema.minimum,
138
- maximum: schema.maximum,
139
- format: schema.format,
140
- properties: transformSchemaProperties(context, schema, transformSchema),
141
- additionalProperties: transformAdditionalProperties(context, schema, transformSchema),
142
- allOf: (_b = (_a = schema.allOf) === null || _a === void 0 ? void 0 : _a.map((s) => transformSchema(context, s))) !== null && _b !== void 0 ? _b : [],
143
- anyOf: (_d = (_c = schema.anyOf) === null || _c === void 0 ? void 0 : _c.map((s) => transformSchema(context, s))) !== null && _d !== void 0 ? _d : [],
144
- maxLength: schema.maxLength,
145
- minLength: schema.minLength,
146
- pattern: schema.pattern,
147
- });
148
- },
149
130
  null: () => ({ type: 'null' }),
150
131
  unknown: () => ({}),
151
132
  };
@@ -5,6 +5,9 @@ export function resolveAnyOfAndAllOf(schema, ignoreNonObjectParts) {
5
5
  }
6
6
  const required = new Set(schema.required);
7
7
  const properties = new Map();
8
+ if ('properties' in schema) {
9
+ schema.properties.forEach((prop) => properties.set(prop.name, prop));
10
+ }
8
11
  collectSubSchemaProperties(schema.allOf, properties, required, false);
9
12
  collectSubSchemaProperties(schema.anyOf, properties, required, true);
10
13
  const initialAdditionalProperties = schema.kind === 'object' ? schema.additionalProperties : undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goast/core",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
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": [
@@ -7,6 +7,7 @@ export declare function determineSchemaKind<T extends {
7
7
  anyOf?: unknown;
8
8
  type?: string | string[];
9
9
  properties?: Record<string, unknown>;
10
+ additionalProperties?: unknown;
10
11
  }>(ctx: OpenApiTransformerContext, schema: T): ApiSchemaKind;
11
12
  export declare function determineSchemaName(schema: {
12
13
  title?: string;