enlace-openapi 0.0.1-beta.5 → 0.0.1-beta.6

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/cli.js CHANGED
@@ -418,12 +418,17 @@ function formDataTypeToSchema(formDataType, ctx) {
418
418
  function generateOpenAPISpec(endpoints, schemas, options = {}) {
419
419
  const { title = "API", version = "1.0.0", description, baseUrl } = options;
420
420
  const paths = {};
421
+ const tagSet = /* @__PURE__ */ new Set();
421
422
  for (const endpoint of endpoints) {
422
423
  if (!paths[endpoint.path]) {
423
424
  paths[endpoint.path] = {};
424
425
  }
425
426
  const pathItem = paths[endpoint.path];
426
- const operation = createOperation(endpoint);
427
+ const tag = getTagFromPath(endpoint.path);
428
+ const operation = createOperation(endpoint, tag);
429
+ if (tag) {
430
+ tagSet.add(tag);
431
+ }
427
432
  pathItem[endpoint.method] = operation;
428
433
  if (endpoint.pathParams.length > 0 && !pathItem.parameters) {
429
434
  pathItem.parameters = endpoint.pathParams.map((param) => ({
@@ -434,6 +439,7 @@ function generateOpenAPISpec(endpoints, schemas, options = {}) {
434
439
  }));
435
440
  }
436
441
  }
442
+ const tags = [...tagSet].sort().map((name) => ({ name }));
437
443
  const spec = {
438
444
  openapi: "3.0.0",
439
445
  info: {
@@ -448,6 +454,9 @@ function generateOpenAPISpec(endpoints, schemas, options = {}) {
448
454
  if (baseUrl) {
449
455
  spec.servers = [{ url: baseUrl }];
450
456
  }
457
+ if (tags.length > 0) {
458
+ spec.tags = tags;
459
+ }
451
460
  if (schemas.size > 0) {
452
461
  spec.components = {
453
462
  schemas: Object.fromEntries(schemas)
@@ -455,7 +464,15 @@ function generateOpenAPISpec(endpoints, schemas, options = {}) {
455
464
  }
456
465
  return spec;
457
466
  }
458
- function createOperation(endpoint) {
467
+ function getTagFromPath(path2) {
468
+ const segments = path2.split("/").filter(Boolean);
469
+ const firstSegment = segments[0];
470
+ if (!firstSegment || firstSegment.startsWith("{")) {
471
+ return void 0;
472
+ }
473
+ return firstSegment;
474
+ }
475
+ function createOperation(endpoint, tag) {
459
476
  const operation = {
460
477
  responses: {
461
478
  "200": {
@@ -463,6 +480,9 @@ function createOperation(endpoint) {
463
480
  }
464
481
  }
465
482
  };
483
+ if (tag) {
484
+ operation.tags = [tag];
485
+ }
466
486
  if (hasContent(endpoint.responseSchema)) {
467
487
  operation.responses["200"].content = {
468
488
  "application/json": {
package/dist/cli.mjs CHANGED
@@ -395,12 +395,17 @@ function formDataTypeToSchema(formDataType, ctx) {
395
395
  function generateOpenAPISpec(endpoints, schemas, options = {}) {
396
396
  const { title = "API", version = "1.0.0", description, baseUrl } = options;
397
397
  const paths = {};
398
+ const tagSet = /* @__PURE__ */ new Set();
398
399
  for (const endpoint of endpoints) {
399
400
  if (!paths[endpoint.path]) {
400
401
  paths[endpoint.path] = {};
401
402
  }
402
403
  const pathItem = paths[endpoint.path];
403
- const operation = createOperation(endpoint);
404
+ const tag = getTagFromPath(endpoint.path);
405
+ const operation = createOperation(endpoint, tag);
406
+ if (tag) {
407
+ tagSet.add(tag);
408
+ }
404
409
  pathItem[endpoint.method] = operation;
405
410
  if (endpoint.pathParams.length > 0 && !pathItem.parameters) {
406
411
  pathItem.parameters = endpoint.pathParams.map((param) => ({
@@ -411,6 +416,7 @@ function generateOpenAPISpec(endpoints, schemas, options = {}) {
411
416
  }));
412
417
  }
413
418
  }
419
+ const tags = [...tagSet].sort().map((name) => ({ name }));
414
420
  const spec = {
415
421
  openapi: "3.0.0",
416
422
  info: {
@@ -425,6 +431,9 @@ function generateOpenAPISpec(endpoints, schemas, options = {}) {
425
431
  if (baseUrl) {
426
432
  spec.servers = [{ url: baseUrl }];
427
433
  }
434
+ if (tags.length > 0) {
435
+ spec.tags = tags;
436
+ }
428
437
  if (schemas.size > 0) {
429
438
  spec.components = {
430
439
  schemas: Object.fromEntries(schemas)
@@ -432,7 +441,15 @@ function generateOpenAPISpec(endpoints, schemas, options = {}) {
432
441
  }
433
442
  return spec;
434
443
  }
435
- function createOperation(endpoint) {
444
+ function getTagFromPath(path2) {
445
+ const segments = path2.split("/").filter(Boolean);
446
+ const firstSegment = segments[0];
447
+ if (!firstSegment || firstSegment.startsWith("{")) {
448
+ return void 0;
449
+ }
450
+ return firstSegment;
451
+ }
452
+ function createOperation(endpoint, tag) {
436
453
  const operation = {
437
454
  responses: {
438
455
  "200": {
@@ -440,6 +457,9 @@ function createOperation(endpoint) {
440
457
  }
441
458
  }
442
459
  };
460
+ if (tag) {
461
+ operation.tags = [tag];
462
+ }
443
463
  if (hasContent(endpoint.responseSchema)) {
444
464
  operation.responses["200"].content = {
445
465
  "application/json": {
package/dist/index.d.mts CHANGED
@@ -56,6 +56,10 @@ type OpenAPIPathItem = {
56
56
  delete?: OpenAPIOperation;
57
57
  parameters?: OpenAPIParameter[];
58
58
  };
59
+ type OpenAPITag = {
60
+ name: string;
61
+ description?: string;
62
+ };
59
63
  type OpenAPISpec = {
60
64
  openapi: "3.0.0";
61
65
  info: {
@@ -67,6 +71,7 @@ type OpenAPISpec = {
67
71
  url: string;
68
72
  description?: string;
69
73
  }[];
74
+ tags?: OpenAPITag[];
70
75
  paths: Record<string, OpenAPIPathItem>;
71
76
  components?: {
72
77
  schemas?: Record<string, JSONSchema>;
@@ -105,4 +110,4 @@ type GeneratorOptions = {
105
110
  };
106
111
  declare function generateOpenAPISpec(endpoints: ParsedEndpoint[], schemas: Map<string, JSONSchema>, options?: GeneratorOptions): OpenAPISpec;
107
112
 
108
- export { type CLIOptions, type JSONSchema, type OpenAPIOperation, type OpenAPIParameter, type OpenAPIPathItem, type OpenAPIRequestBody, type OpenAPISpec, type ParsedEndpoint, generateOpenAPISpec, parseSchema };
113
+ export { type CLIOptions, type JSONSchema, type OpenAPIOperation, type OpenAPIParameter, type OpenAPIPathItem, type OpenAPIRequestBody, type OpenAPISpec, type OpenAPITag, type ParsedEndpoint, generateOpenAPISpec, parseSchema };
package/dist/index.d.ts CHANGED
@@ -56,6 +56,10 @@ type OpenAPIPathItem = {
56
56
  delete?: OpenAPIOperation;
57
57
  parameters?: OpenAPIParameter[];
58
58
  };
59
+ type OpenAPITag = {
60
+ name: string;
61
+ description?: string;
62
+ };
59
63
  type OpenAPISpec = {
60
64
  openapi: "3.0.0";
61
65
  info: {
@@ -67,6 +71,7 @@ type OpenAPISpec = {
67
71
  url: string;
68
72
  description?: string;
69
73
  }[];
74
+ tags?: OpenAPITag[];
70
75
  paths: Record<string, OpenAPIPathItem>;
71
76
  components?: {
72
77
  schemas?: Record<string, JSONSchema>;
@@ -105,4 +110,4 @@ type GeneratorOptions = {
105
110
  };
106
111
  declare function generateOpenAPISpec(endpoints: ParsedEndpoint[], schemas: Map<string, JSONSchema>, options?: GeneratorOptions): OpenAPISpec;
107
112
 
108
- export { type CLIOptions, type JSONSchema, type OpenAPIOperation, type OpenAPIParameter, type OpenAPIPathItem, type OpenAPIRequestBody, type OpenAPISpec, type ParsedEndpoint, generateOpenAPISpec, parseSchema };
113
+ export { type CLIOptions, type JSONSchema, type OpenAPIOperation, type OpenAPIParameter, type OpenAPIPathItem, type OpenAPIRequestBody, type OpenAPISpec, type OpenAPITag, type ParsedEndpoint, generateOpenAPISpec, parseSchema };
package/dist/index.js CHANGED
@@ -426,12 +426,17 @@ function formDataTypeToSchema(formDataType, ctx) {
426
426
  function generateOpenAPISpec(endpoints, schemas, options = {}) {
427
427
  const { title = "API", version = "1.0.0", description, baseUrl } = options;
428
428
  const paths = {};
429
+ const tagSet = /* @__PURE__ */ new Set();
429
430
  for (const endpoint of endpoints) {
430
431
  if (!paths[endpoint.path]) {
431
432
  paths[endpoint.path] = {};
432
433
  }
433
434
  const pathItem = paths[endpoint.path];
434
- const operation = createOperation(endpoint);
435
+ const tag = getTagFromPath(endpoint.path);
436
+ const operation = createOperation(endpoint, tag);
437
+ if (tag) {
438
+ tagSet.add(tag);
439
+ }
435
440
  pathItem[endpoint.method] = operation;
436
441
  if (endpoint.pathParams.length > 0 && !pathItem.parameters) {
437
442
  pathItem.parameters = endpoint.pathParams.map((param) => ({
@@ -442,6 +447,7 @@ function generateOpenAPISpec(endpoints, schemas, options = {}) {
442
447
  }));
443
448
  }
444
449
  }
450
+ const tags = [...tagSet].sort().map((name) => ({ name }));
445
451
  const spec = {
446
452
  openapi: "3.0.0",
447
453
  info: {
@@ -456,6 +462,9 @@ function generateOpenAPISpec(endpoints, schemas, options = {}) {
456
462
  if (baseUrl) {
457
463
  spec.servers = [{ url: baseUrl }];
458
464
  }
465
+ if (tags.length > 0) {
466
+ spec.tags = tags;
467
+ }
459
468
  if (schemas.size > 0) {
460
469
  spec.components = {
461
470
  schemas: Object.fromEntries(schemas)
@@ -463,7 +472,15 @@ function generateOpenAPISpec(endpoints, schemas, options = {}) {
463
472
  }
464
473
  return spec;
465
474
  }
466
- function createOperation(endpoint) {
475
+ function getTagFromPath(path2) {
476
+ const segments = path2.split("/").filter(Boolean);
477
+ const firstSegment = segments[0];
478
+ if (!firstSegment || firstSegment.startsWith("{")) {
479
+ return void 0;
480
+ }
481
+ return firstSegment;
482
+ }
483
+ function createOperation(endpoint, tag) {
467
484
  const operation = {
468
485
  responses: {
469
486
  "200": {
@@ -471,6 +488,9 @@ function createOperation(endpoint) {
471
488
  }
472
489
  }
473
490
  };
491
+ if (tag) {
492
+ operation.tags = [tag];
493
+ }
474
494
  if (hasContent(endpoint.responseSchema)) {
475
495
  operation.responses["200"].content = {
476
496
  "application/json": {
package/dist/index.mjs CHANGED
@@ -389,12 +389,17 @@ function formDataTypeToSchema(formDataType, ctx) {
389
389
  function generateOpenAPISpec(endpoints, schemas, options = {}) {
390
390
  const { title = "API", version = "1.0.0", description, baseUrl } = options;
391
391
  const paths = {};
392
+ const tagSet = /* @__PURE__ */ new Set();
392
393
  for (const endpoint of endpoints) {
393
394
  if (!paths[endpoint.path]) {
394
395
  paths[endpoint.path] = {};
395
396
  }
396
397
  const pathItem = paths[endpoint.path];
397
- const operation = createOperation(endpoint);
398
+ const tag = getTagFromPath(endpoint.path);
399
+ const operation = createOperation(endpoint, tag);
400
+ if (tag) {
401
+ tagSet.add(tag);
402
+ }
398
403
  pathItem[endpoint.method] = operation;
399
404
  if (endpoint.pathParams.length > 0 && !pathItem.parameters) {
400
405
  pathItem.parameters = endpoint.pathParams.map((param) => ({
@@ -405,6 +410,7 @@ function generateOpenAPISpec(endpoints, schemas, options = {}) {
405
410
  }));
406
411
  }
407
412
  }
413
+ const tags = [...tagSet].sort().map((name) => ({ name }));
408
414
  const spec = {
409
415
  openapi: "3.0.0",
410
416
  info: {
@@ -419,6 +425,9 @@ function generateOpenAPISpec(endpoints, schemas, options = {}) {
419
425
  if (baseUrl) {
420
426
  spec.servers = [{ url: baseUrl }];
421
427
  }
428
+ if (tags.length > 0) {
429
+ spec.tags = tags;
430
+ }
422
431
  if (schemas.size > 0) {
423
432
  spec.components = {
424
433
  schemas: Object.fromEntries(schemas)
@@ -426,7 +435,15 @@ function generateOpenAPISpec(endpoints, schemas, options = {}) {
426
435
  }
427
436
  return spec;
428
437
  }
429
- function createOperation(endpoint) {
438
+ function getTagFromPath(path2) {
439
+ const segments = path2.split("/").filter(Boolean);
440
+ const firstSegment = segments[0];
441
+ if (!firstSegment || firstSegment.startsWith("{")) {
442
+ return void 0;
443
+ }
444
+ return firstSegment;
445
+ }
446
+ function createOperation(endpoint, tag) {
430
447
  const operation = {
431
448
  responses: {
432
449
  "200": {
@@ -434,6 +451,9 @@ function createOperation(endpoint) {
434
451
  }
435
452
  }
436
453
  };
454
+ if (tag) {
455
+ operation.tags = [tag];
456
+ }
437
457
  if (hasContent(endpoint.responseSchema)) {
438
458
  operation.responses["200"].content = {
439
459
  "application/json": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "enlace-openapi",
3
- "version": "0.0.1-beta.5",
3
+ "version": "0.0.1-beta.6",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "enlace-openapi": "./dist/cli.mjs"