swaggular 0.2.3 → 0.2.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.
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ async function main() {
|
|
|
16
16
|
try {
|
|
17
17
|
const parsed = (0, args_1.getParseArgs)(process.argv.slice(2));
|
|
18
18
|
const variables = (0, variables_1.toVariables)(parsed);
|
|
19
|
+
console.log('Generating interfaces and services using Swaggular@' + process.env.npm_package_version);
|
|
19
20
|
swagger_parser_1.SwaggerParser.parse(variables.input, {
|
|
20
21
|
mode: variables.groupingMode,
|
|
21
22
|
segmentsToIgnore: variables.segmentsToIgnore,
|
|
@@ -154,7 +154,11 @@ function generateComponentsSchemas() {
|
|
|
154
154
|
const interData = {
|
|
155
155
|
name: key,
|
|
156
156
|
type: 'interface',
|
|
157
|
-
imports: properties
|
|
157
|
+
imports: properties
|
|
158
|
+
.filter((p) => !(0, type_guard_1.isNativeType)(p.type))
|
|
159
|
+
.map((p) => {
|
|
160
|
+
return p.type.replaceAll('[]', '');
|
|
161
|
+
}),
|
|
158
162
|
properties,
|
|
159
163
|
};
|
|
160
164
|
const generic = (0, generic_types_1.isGenericType)(interData);
|
|
@@ -175,7 +179,7 @@ function generateInterfacesFiles(locations) {
|
|
|
175
179
|
const filesContent = [];
|
|
176
180
|
for (const [key, value] of Object.entries(interfacesData)) {
|
|
177
181
|
const location = [value.type === 'enum' ? 'enums' : 'dtos', ...(locations?.[key] ?? [])];
|
|
178
|
-
const content = generateContent(value, location.length);
|
|
182
|
+
const content = generateContent(value, location.length + 1);
|
|
179
183
|
const extraName = value.type === 'enum' ? 'enum' : 'dto';
|
|
180
184
|
filesContent.push({
|
|
181
185
|
location: location,
|
|
@@ -188,9 +192,8 @@ function generateInterfacesFiles(locations) {
|
|
|
188
192
|
}
|
|
189
193
|
function generateContent(interfaceData, deep = 0) {
|
|
190
194
|
const imports = [...interfaceData.imports];
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
: '';
|
|
195
|
+
const path = '../'.repeat(deep);
|
|
196
|
+
const importsTemplate = imports.length > 0 ? `import { ${imports.join(', ')} } from "${path}models";` : '';
|
|
194
197
|
if (interfaceData.type === 'interface') {
|
|
195
198
|
const content = `${importsTemplate}\n\nexport interface ${interfaceData.name} ${interfaceData.extendsFrom && interfaceData.extendsFrom.length > 0 ? `extends ${interfaceData.extendsFrom.join(', ')}` : ''} {
|
|
196
199
|
${interfaceData.properties
|