ng-openapi 0.1.8-pr-14-bugfix-working-directory-ee4104d.0 → 0.1.8

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.
Files changed (4) hide show
  1. package/cli.cjs +47 -98
  2. package/index.d.ts +5 -2
  3. package/index.js +45 -41
  4. package/package.json +1 -1
package/cli.cjs CHANGED
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
 
27
27
  // src/lib/cli.ts
28
28
  var import_commander = require("commander");
29
- var path10 = __toESM(require("path"));
29
+ var path11 = __toESM(require("path"));
30
30
  var fs4 = __toESM(require("fs"));
31
31
 
32
32
  // src/lib/core/generator.ts
@@ -212,12 +212,12 @@ function extractPaths(swaggerPaths = {}, methods = [
212
212
  "head"
213
213
  ]) {
214
214
  const paths = [];
215
- Object.entries(swaggerPaths).forEach(([path11, pathItem]) => {
215
+ Object.entries(swaggerPaths).forEach(([path12, pathItem]) => {
216
216
  methods.forEach((method) => {
217
217
  if (pathItem[method]) {
218
218
  const operation = pathItem[method];
219
219
  paths.push({
220
- path: path11,
220
+ path: path12,
221
221
  method: method.toUpperCase(),
222
222
  operationId: operation.operationId,
223
223
  summary: operation.summary,
@@ -426,6 +426,22 @@ var BASE_INTERCEPTOR_HEADER_COMMENT = /* @__PURE__ */ __name((clientName) => def
426
426
  var fs = __toESM(require("fs"));
427
427
  var path = __toESM(require("path"));
428
428
  var yaml = __toESM(require("js-yaml"));
429
+
430
+ // ../shared/src/utils/functions/is-url.ts
431
+ function isUrl(input) {
432
+ try {
433
+ const url = new URL(input);
434
+ return [
435
+ "http:",
436
+ "https:"
437
+ ].includes(url.protocol);
438
+ } catch {
439
+ return false;
440
+ }
441
+ }
442
+ __name(isUrl, "isUrl");
443
+
444
+ // ../shared/src/core/swagger-parser.ts
429
445
  var SwaggerParser = class _SwaggerParser {
430
446
  static {
431
447
  __name(this, "SwaggerParser");
@@ -444,20 +460,12 @@ var SwaggerParser = class _SwaggerParser {
444
460
  return new _SwaggerParser(spec, config);
445
461
  }
446
462
  static async loadContent(pathOrUrl) {
447
- if (_SwaggerParser.isUrl(pathOrUrl)) {
463
+ if (isUrl(pathOrUrl)) {
448
464
  return await _SwaggerParser.fetchUrlContent(pathOrUrl);
449
465
  } else {
450
466
  return fs.readFileSync(pathOrUrl, "utf8");
451
467
  }
452
468
  }
453
- static isUrl(input) {
454
- try {
455
- new URL(input);
456
- return true;
457
- } catch {
458
- return false;
459
- }
460
- }
461
469
  static async fetchUrlContent(url) {
462
470
  try {
463
471
  const response = await fetch(url, {
@@ -489,7 +497,7 @@ var SwaggerParser = class _SwaggerParser {
489
497
  }
490
498
  static parseSpecContent(content, pathOrUrl) {
491
499
  let format;
492
- if (_SwaggerParser.isUrl(pathOrUrl)) {
500
+ if (isUrl(pathOrUrl)) {
493
501
  const urlPath = new URL(pathOrUrl).pathname.toLowerCase();
494
502
  if (urlPath.endsWith(".json")) {
495
503
  format = "json";
@@ -2168,12 +2176,12 @@ var ServiceGenerator = class _ServiceGenerator {
2168
2176
  }
2169
2177
  groupPathsByController(paths) {
2170
2178
  const groups = {};
2171
- paths.forEach((path11) => {
2179
+ paths.forEach((path12) => {
2172
2180
  let controllerName = "Default";
2173
- if (path11.tags && path11.tags.length > 0) {
2174
- controllerName = path11.tags[0];
2181
+ if (path12.tags && path12.tags.length > 0) {
2182
+ controllerName = path12.tags[0];
2175
2183
  } else {
2176
- const pathParts = path11.path.split("/").filter((p) => p && !p.startsWith("{"));
2184
+ const pathParts = path12.path.split("/").filter((p) => p && !p.startsWith("{"));
2177
2185
  if (pathParts.length > 1) {
2178
2186
  controllerName = pascalCase(pathParts[1]);
2179
2187
  }
@@ -2182,7 +2190,7 @@ var ServiceGenerator = class _ServiceGenerator {
2182
2190
  if (!groups[controllerName]) {
2183
2191
  groups[controllerName] = [];
2184
2192
  }
2185
- groups[controllerName].push(path11);
2193
+ groups[controllerName].push(path12);
2186
2194
  });
2187
2195
  return groups;
2188
2196
  }
@@ -2337,28 +2345,22 @@ var ServiceIndexGenerator = class {
2337
2345
 
2338
2346
  // src/lib/core/generator.ts
2339
2347
  var fs3 = __toESM(require("fs"));
2340
- function isUrl(input) {
2341
- try {
2342
- new URL(input);
2343
- return true;
2344
- } catch {
2345
- return false;
2348
+ var path10 = __toESM(require("path"));
2349
+ function validateInput(inputPath) {
2350
+ if (isUrl(inputPath)) {
2351
+ return;
2346
2352
  }
2347
- }
2348
- __name(isUrl, "isUrl");
2349
- function validateInput(input) {
2350
- if (isUrl(input)) {
2351
- const url = new URL(input);
2352
- if (![
2353
- "http:",
2354
- "https:"
2355
- ].includes(url.protocol)) {
2356
- throw new Error(`Unsupported URL protocol: ${url.protocol}. Only HTTP and HTTPS are supported.`);
2357
- }
2358
- } else {
2359
- if (!fs3.existsSync(input)) {
2360
- throw new Error(`Input file not found: ${input}`);
2361
- }
2353
+ if (!fs3.existsSync(inputPath)) {
2354
+ throw new Error(`Input file not found: ${inputPath}`);
2355
+ }
2356
+ const extension = path10.extname(inputPath).toLowerCase();
2357
+ const supportedExtensions = [
2358
+ ".json",
2359
+ ".yaml",
2360
+ ".yml"
2361
+ ];
2362
+ if (!supportedExtensions.includes(extension)) {
2363
+ throw new Error(`Failed to parse ${extension || "specification"}. Supported formats are .json, .yaml, and .yml.`);
2362
2364
  }
2363
2365
  }
2364
2366
  __name(validateInput, "validateInput");
@@ -2442,7 +2444,7 @@ var version = "0.1.7";
2442
2444
  // src/lib/cli.ts
2443
2445
  var program = new import_commander.Command();
2444
2446
  async function loadConfigFile(configPath) {
2445
- const resolvedPath = path10.resolve(configPath);
2447
+ const resolvedPath = path11.resolve(configPath);
2446
2448
  if (!fs4.existsSync(resolvedPath)) {
2447
2449
  throw new Error(`Configuration file not found: ${resolvedPath}`);
2448
2450
  }
@@ -2456,12 +2458,12 @@ async function loadConfigFile(configPath) {
2456
2458
  if (!config.input || !config.output) {
2457
2459
  throw new Error('Configuration must include "input" and "output" properties');
2458
2460
  }
2459
- const configDir = path10.dirname(resolvedPath);
2460
- if (!isUrl2(config.input) && !path10.isAbsolute(config.input)) {
2461
- config.input = path10.resolve(configDir, config.input);
2461
+ const configDir = path11.dirname(resolvedPath);
2462
+ if (!isUrl(config.input) && !path11.isAbsolute(config.input)) {
2463
+ config.input = path11.resolve(configDir, config.input);
2462
2464
  }
2463
- if (!path10.isAbsolute(config.output)) {
2464
- config.output = path10.resolve(configDir, config.output);
2465
+ if (!path11.isAbsolute(config.output)) {
2466
+ config.output = path11.resolve(configDir, config.output);
2465
2467
  }
2466
2468
  return config;
2467
2469
  } catch (error) {
@@ -2469,65 +2471,12 @@ async function loadConfigFile(configPath) {
2469
2471
  }
2470
2472
  }
2471
2473
  __name(loadConfigFile, "loadConfigFile");
2472
- function validateInputExtension(inputPath) {
2473
- const extension = path10.extname(inputPath).toLowerCase();
2474
- const supportedExtensions = [
2475
- ".json",
2476
- ".yaml",
2477
- ".yml"
2478
- ];
2479
- if (!supportedExtensions.includes(extension)) {
2480
- throw new Error(`Failed to parse ${extension || "specification"}. Supported formats are .json, .yaml, and .yml.`);
2481
- }
2482
- }
2483
- __name(validateInputExtension, "validateInputExtension");
2484
- function isUrl2(input) {
2485
- try {
2486
- new URL(input);
2487
- return true;
2488
- } catch {
2489
- return false;
2490
- }
2491
- }
2492
- __name(isUrl2, "isUrl");
2493
- function validateInput2(inputPath) {
2494
- if (isUrl2(inputPath)) {
2495
- const url = new URL(inputPath);
2496
- if (![
2497
- "http:",
2498
- "https:"
2499
- ].includes(url.protocol)) {
2500
- throw new Error(`Unsupported URL protocol: ${url.protocol}. Only HTTP and HTTPS are supported.`);
2501
- }
2502
- return;
2503
- }
2504
- if (!fs4.existsSync(inputPath)) {
2505
- throw new Error(`Input file not found: ${inputPath}`);
2506
- }
2507
- const extension = path10.extname(inputPath).toLowerCase();
2508
- const supportedExtensions = [
2509
- ".json",
2510
- ".yaml",
2511
- ".yml"
2512
- ];
2513
- if (!supportedExtensions.includes(extension)) {
2514
- throw new Error(`Failed to parse ${extension || "specification"}. Supported formats are .json, .yaml, and .yml.`);
2515
- }
2516
- }
2517
- __name(validateInput2, "validateInput");
2518
2474
  async function generateFromOptions(options) {
2519
2475
  try {
2520
2476
  if (options.config) {
2521
2477
  const config = await loadConfigFile(options.config);
2522
- if (!isUrl2(config.input)) {
2523
- if (!fs4.existsSync(config.input)) {
2524
- throw new Error(`Input file not found: ${config.input}`);
2525
- }
2526
- validateInputExtension(config.input);
2527
- }
2528
2478
  await generateFromConfig(config);
2529
2479
  } else if (options.input) {
2530
- validateInput2(options.input);
2531
2480
  const config = {
2532
2481
  input: options.input,
2533
2482
  output: options.output || "./src/generated",
package/index.d.ts CHANGED
@@ -149,7 +149,6 @@ declare class SwaggerParser {
149
149
  private constructor();
150
150
  static create(swaggerPathOrUrl: string, config: GeneratorConfig): Promise<SwaggerParser>;
151
151
  private static loadContent;
152
- private static isUrl;
153
152
  private static fetchUrlContent;
154
153
  private static parseSpecContent;
155
154
  private static detectFormat;
@@ -270,9 +269,13 @@ declare const PROVIDER_GENERATOR_HEADER_COMMENT: string;
270
269
  declare const BASE_INTERCEPTOR_HEADER_COMMENT: (clientName: string) => string;
271
270
  declare const HTTP_RESOURCE_GENERATOR_HEADER_COMMENT: (resourceName: string) => string;
272
271
 
272
+ /**
273
+ * Validates input (file or URL)
274
+ */
275
+ declare function validateInput(inputPath: string): void;
273
276
  /**
274
277
  * Generates Angular services and types from a configuration object
275
278
  */
276
279
  declare function generateFromConfig(config: GeneratorConfig): Promise<void>;
277
280
 
278
- export { BASE_INTERCEPTOR_HEADER_COMMENT, type EnumValueObject, type GeneratorConfig, type GetMethodGenerationContext, HTTP_RESOURCE_GENERATOR_HEADER_COMMENT, type IPluginGenerator, type IPluginGeneratorClass, type IPluginGeneratorConstructor, MAIN_INDEX_GENERATOR_HEADER_COMMENT, type MethodGenerationContext, type NgOpenapiClientConfig, PROVIDER_GENERATOR_HEADER_COMMENT, type Parameter, type PathInfo, type RequestBody, SERVICE_GENERATOR_HEADER_COMMENT, SERVICE_INDEX_GENERATOR_HEADER_COMMENT, type SwaggerDefinition, SwaggerParser, type SwaggerResponse, type SwaggerSpec, TYPE_GENERATOR_HEADER_COMMENT, type TypeSchema, camelCase, collectUsedTypes, escapeString, extractPaths, generateFromConfig, getBasePathTokenName, getClientContextTokenName, getResponseType, getResponseTypeFromResponse, getTypeScriptType, hasDuplicateFunctionNames, inferResponseTypeFromContentType, isPrimitiveType, kebabCase, nullableType, pascalCase, type placeHolder };
281
+ export { BASE_INTERCEPTOR_HEADER_COMMENT, type EnumValueObject, type GeneratorConfig, type GetMethodGenerationContext, HTTP_RESOURCE_GENERATOR_HEADER_COMMENT, type IPluginGenerator, type IPluginGeneratorClass, type IPluginGeneratorConstructor, MAIN_INDEX_GENERATOR_HEADER_COMMENT, type MethodGenerationContext, type NgOpenapiClientConfig, PROVIDER_GENERATOR_HEADER_COMMENT, type Parameter, type PathInfo, type RequestBody, SERVICE_GENERATOR_HEADER_COMMENT, SERVICE_INDEX_GENERATOR_HEADER_COMMENT, type SwaggerDefinition, SwaggerParser, type SwaggerResponse, type SwaggerSpec, TYPE_GENERATOR_HEADER_COMMENT, type TypeSchema, camelCase, collectUsedTypes, escapeString, extractPaths, generateFromConfig, getBasePathTokenName, getClientContextTokenName, getResponseType, getResponseTypeFromResponse, getTypeScriptType, hasDuplicateFunctionNames, inferResponseTypeFromContentType, isPrimitiveType, kebabCase, nullableType, pascalCase, type placeHolder, validateInput };
package/index.js CHANGED
@@ -96,7 +96,8 @@ __export(index_exports, {
96
96
  isPrimitiveType: () => isPrimitiveType,
97
97
  kebabCase: () => kebabCase,
98
98
  nullableType: () => nullableType,
99
- pascalCase: () => pascalCase
99
+ pascalCase: () => pascalCase,
100
+ validateInput: () => validateInput
100
101
  });
101
102
  module.exports = __toCommonJS(index_exports);
102
103
 
@@ -288,12 +289,12 @@ function extractPaths(swaggerPaths = {}, methods = [
288
289
  "head"
289
290
  ]) {
290
291
  const paths = [];
291
- Object.entries(swaggerPaths).forEach(([path10, pathItem]) => {
292
+ Object.entries(swaggerPaths).forEach(([path11, pathItem]) => {
292
293
  methods.forEach((method) => {
293
294
  if (pathItem[method]) {
294
295
  const operation = pathItem[method];
295
296
  paths.push({
296
- path: path10,
297
+ path: path11,
297
298
  method: method.toUpperCase(),
298
299
  operationId: operation.operationId,
299
300
  summary: operation.summary,
@@ -508,6 +509,22 @@ var HTTP_RESOURCE_GENERATOR_HEADER_COMMENT = /* @__PURE__ */ __name((resourceNam
508
509
  var fs = __toESM(require("fs"));
509
510
  var path = __toESM(require("path"));
510
511
  var yaml = __toESM(require("js-yaml"));
512
+
513
+ // ../shared/src/utils/functions/is-url.ts
514
+ function isUrl(input) {
515
+ try {
516
+ const url = new URL(input);
517
+ return [
518
+ "http:",
519
+ "https:"
520
+ ].includes(url.protocol);
521
+ } catch (e) {
522
+ return false;
523
+ }
524
+ }
525
+ __name(isUrl, "isUrl");
526
+
527
+ // ../shared/src/core/swagger-parser.ts
511
528
  var _SwaggerParser = class _SwaggerParser {
512
529
  constructor(spec, config) {
513
530
  __publicField(this, "spec");
@@ -527,21 +544,13 @@ var _SwaggerParser = class _SwaggerParser {
527
544
  }
528
545
  static loadContent(pathOrUrl) {
529
546
  return __async(this, null, function* () {
530
- if (_SwaggerParser.isUrl(pathOrUrl)) {
547
+ if (isUrl(pathOrUrl)) {
531
548
  return yield _SwaggerParser.fetchUrlContent(pathOrUrl);
532
549
  } else {
533
550
  return fs.readFileSync(pathOrUrl, "utf8");
534
551
  }
535
552
  });
536
553
  }
537
- static isUrl(input) {
538
- try {
539
- new URL(input);
540
- return true;
541
- } catch (e) {
542
- return false;
543
- }
544
- }
545
554
  static fetchUrlContent(url) {
546
555
  return __async(this, null, function* () {
547
556
  try {
@@ -575,7 +584,7 @@ var _SwaggerParser = class _SwaggerParser {
575
584
  }
576
585
  static parseSpecContent(content, pathOrUrl) {
577
586
  let format;
578
- if (_SwaggerParser.isUrl(pathOrUrl)) {
587
+ if (isUrl(pathOrUrl)) {
579
588
  const urlPath = new URL(pathOrUrl).pathname.toLowerCase();
580
589
  if (urlPath.endsWith(".json")) {
581
590
  format = "json";
@@ -2261,12 +2270,12 @@ var _ServiceGenerator = class _ServiceGenerator {
2261
2270
  }
2262
2271
  groupPathsByController(paths) {
2263
2272
  const groups = {};
2264
- paths.forEach((path10) => {
2273
+ paths.forEach((path11) => {
2265
2274
  let controllerName = "Default";
2266
- if (path10.tags && path10.tags.length > 0) {
2267
- controllerName = path10.tags[0];
2275
+ if (path11.tags && path11.tags.length > 0) {
2276
+ controllerName = path11.tags[0];
2268
2277
  } else {
2269
- const pathParts = path10.path.split("/").filter((p) => p && !p.startsWith("{"));
2278
+ const pathParts = path11.path.split("/").filter((p) => p && !p.startsWith("{"));
2270
2279
  if (pathParts.length > 1) {
2271
2280
  controllerName = pascalCase(pathParts[1]);
2272
2281
  }
@@ -2275,7 +2284,7 @@ var _ServiceGenerator = class _ServiceGenerator {
2275
2284
  if (!groups[controllerName]) {
2276
2285
  groups[controllerName] = [];
2277
2286
  }
2278
- groups[controllerName].push(path10);
2287
+ groups[controllerName].push(path11);
2279
2288
  });
2280
2289
  return groups;
2281
2290
  }
@@ -2431,28 +2440,22 @@ var ServiceIndexGenerator = _ServiceIndexGenerator;
2431
2440
 
2432
2441
  // src/lib/core/generator.ts
2433
2442
  var fs3 = __toESM(require("fs"));
2434
- function isUrl(input) {
2435
- try {
2436
- new URL(input);
2437
- return true;
2438
- } catch (e) {
2439
- return false;
2440
- }
2441
- }
2442
- __name(isUrl, "isUrl");
2443
- function validateInput(input) {
2444
- if (isUrl(input)) {
2445
- const url = new URL(input);
2446
- if (![
2447
- "http:",
2448
- "https:"
2449
- ].includes(url.protocol)) {
2450
- throw new Error(`Unsupported URL protocol: ${url.protocol}. Only HTTP and HTTPS are supported.`);
2451
- }
2452
- } else {
2453
- if (!fs3.existsSync(input)) {
2454
- throw new Error(`Input file not found: ${input}`);
2455
- }
2443
+ var path10 = __toESM(require("path"));
2444
+ function validateInput(inputPath) {
2445
+ if (isUrl(inputPath)) {
2446
+ return;
2447
+ }
2448
+ if (!fs3.existsSync(inputPath)) {
2449
+ throw new Error(`Input file not found: ${inputPath}`);
2450
+ }
2451
+ const extension = path10.extname(inputPath).toLowerCase();
2452
+ const supportedExtensions = [
2453
+ ".json",
2454
+ ".yaml",
2455
+ ".yml"
2456
+ ];
2457
+ if (!supportedExtensions.includes(extension)) {
2458
+ throw new Error(`Failed to parse ${extension || "specification"}. Supported formats are .json, .yaml, and .yml.`);
2456
2459
  }
2457
2460
  }
2458
2461
  __name(validateInput, "validateInput");
@@ -2556,6 +2559,7 @@ __name(generateFromConfig, "generateFromConfig");
2556
2559
  isPrimitiveType,
2557
2560
  kebabCase,
2558
2561
  nullableType,
2559
- pascalCase
2562
+ pascalCase,
2563
+ validateInput
2560
2564
  });
2561
2565
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ng-openapi",
3
- "version": "0.1.8-pr-14-bugfix-working-directory-ee4104d.0",
3
+ "version": "0.1.8",
4
4
  "description": "Generate Angular services and TypeScript types from OpenAPI/Swagger specifications",
5
5
  "keywords": [
6
6
  "ng-openapi",