@qualisero/openapi-endpoint 0.18.0 → 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.
- package/README.md +2 -2
- package/dist/cli.js +32 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# OpenApiEndpoint
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/js/@qualisero%2Fopenapi-endpoint)
|
|
4
|
+
[](https://github.com/qualisero/openapi-endpoint/actions/workflows/ci.yml)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
[](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
|
-
|
|
376
|
-
|
|
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
|
|
426
|
+
if (!paramName || !paramIn || !paramSchema)
|
|
405
427
|
continue;
|
|
406
|
-
const enumValues = paramSchema
|
|
407
|
-
if (enumValues
|
|
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
|
|
@@ -1147,7 +1169,6 @@ import {
|
|
|
1147
1169
|
type QueryReturn,
|
|
1148
1170
|
type MutationReturn,
|
|
1149
1171
|
type LazyQueryReturn,
|
|
1150
|
-
type LazyQueryFetchOptions,
|
|
1151
1172
|
type ReactiveOr,
|
|
1152
1173
|
type NoExcessReturn,
|
|
1153
1174
|
type MaybeRefOrGetter,
|