@qualisero/openapi-endpoint 0.18.1 → 0.18.3

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 (3) hide show
  1. package/README.md +2 -2
  2. package/dist/cli.js +32 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # OpenApiEndpoint
2
2
 
3
- [![npm version](https://badge.fury.io/js/@qualisero%2Fopenapi-endpoint.svg?refresh=20260225)](https://badge.fury.io/js/@qualisero%2Fopenapi-endpoint)
4
- [![CI](https://github.com/qualisero/openapi-endpoint/workflows/CI/badge.svg?refresh=20260225)](https://github.com/qualisero/openapi-endpoint/actions/workflows/ci.yml)
3
+ [![npm version](https://badge.fury.io/js/@qualisero%2Fopenapi-endpoint.svg?v=0.18.1)](https://badge.fury.io/js/@qualisero%2Fopenapi-endpoint)
4
+ [![CI](https://github.com/qualisero/openapi-endpoint/workflows/CI/badge.svg?refresh=20260226)](https://github.com/qualisero/openapi-endpoint/actions/workflows/ci.yml)
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
  [![Documentation](https://img.shields.io/badge/docs-online-brightgreen.svg)](https://qualisero.github.io/openapi-endpoint/)
7
7
 
package/dist/cli.js CHANGED
@@ -359,25 +359,47 @@ function addEnumIfUnique(enumName, enumValues, sourcePath, enums, seenEnumValues
359
359
  /**
360
360
  * Extracts all enums from an OpenAPI spec.
361
361
  * Walks through:
362
- * 1. components.schemas and their properties
362
+ * 1. components.schemas and their properties (inline enum or $ref to enum schema)
363
363
  * 2. Operation parameters (query, header, path, cookie)
364
364
  * Deduplicates by comparing enum value sets.
365
365
  */
366
366
  function extractEnumsFromSpec(openApiSpec) {
367
367
  const enums = [];
368
368
  const seenEnumValues = new Map(); // Maps JSON stringified values -> enum name (for deduplication)
369
+ // Build lookup of schemas that ARE enums (have enum property on the schema itself)
370
+ const schemaEnumLookup = new Map();
371
+ if (openApiSpec.components?.schemas) {
372
+ for (const [schemaName, schema] of Object.entries(openApiSpec.components.schemas)) {
373
+ if (schema.enum && Array.isArray(schema.enum)) {
374
+ const enumValues = schema.enum.filter((v) => v !== null);
375
+ if (enumValues.length > 0) {
376
+ schemaEnumLookup.set(schemaName, enumValues);
377
+ }
378
+ }
379
+ }
380
+ }
381
+ // Helper to resolve enum values from a schema (inline or $ref)
382
+ function resolveEnumValues(schema) {
383
+ // Inline enum
384
+ if (schema.enum && Array.isArray(schema.enum)) {
385
+ const enumValues = schema.enum.filter((v) => v !== null);
386
+ return enumValues.length > 0 ? enumValues : null;
387
+ }
388
+ // $ref to an enum schema
389
+ if (typeof schema.$ref === 'string') {
390
+ const refName = schema.$ref.split('/').pop();
391
+ return schemaEnumLookup.get(refName) ?? null;
392
+ }
393
+ return null;
394
+ }
369
395
  // Extract from components.schemas
370
396
  if (openApiSpec.components?.schemas) {
371
397
  for (const [schemaName, schema] of Object.entries(openApiSpec.components.schemas)) {
372
398
  if (!schema.properties)
373
399
  continue;
374
400
  for (const [propName, propSchema] of Object.entries(schema.properties)) {
375
- if (!propSchema.enum || !Array.isArray(propSchema.enum))
376
- continue;
377
- // Filter out null values from enum array
378
- const enumValues = propSchema.enum.filter((v) => v !== null);
379
- // Skip if all values were null
380
- if (enumValues.length === 0)
401
+ const enumValues = resolveEnumValues(propSchema);
402
+ if (!enumValues)
381
403
  continue;
382
404
  // Use schema name as-is (already PascalCase), convert property name from snake_case
383
405
  const enumName = schemaName + toPascalCase(propName);
@@ -401,10 +423,10 @@ function extractEnumsFromSpec(openApiSpec) {
401
423
  const paramName = paramObj.name;
402
424
  const paramIn = paramObj.in;
403
425
  const paramSchema = paramObj.schema;
404
- if (!paramName || !paramIn || !paramSchema?.enum)
426
+ if (!paramName || !paramIn || !paramSchema)
405
427
  continue;
406
- const enumValues = paramSchema.enum.filter((v) => v !== null);
407
- if (enumValues.length === 0)
428
+ const enumValues = resolveEnumValues(paramSchema);
429
+ if (!enumValues)
408
430
  continue;
409
431
  // Create a descriptive name: OperationName + ParamName
410
432
  const operationName = op.operationId
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qualisero/openapi-endpoint",
3
- "version": "0.18.1",
3
+ "version": "0.18.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/qualisero/openapi-endpoint.git"