diff --git a/config.json b/config.json index 5b731bf..809d195 100644 --- a/config.json +++ b/config.json @@ -13,6 +13,7 @@ "cb223aa9f88db46557ee5722f347055a69e0b3df", "ed347a1958f584f2a891e15521cffe7aff754a62", "b7a315c559cb457723c726c1b49f07c35f2bd8a9", - "9a38bf8d99187663fbb905e4aba0205735accf32" + "9a38bf8d99187663fbb905e4aba0205735accf32", + "15798b0700f9685e8dd3b7511de83c21e7acce02" ] } diff --git a/dist/schema.json b/dist/schema.json index 3916c3d..f9bf6cc 100644 --- a/dist/schema.json +++ b/dist/schema.json @@ -14981,7 +14981,7 @@ ], "responses": { "200": { - "description": "Hash of timeline key and associated [Marker]", + "description": "Hash of String (Enumerable, anyOf `home` or `notifications`) key and associated [Marker] value", "headers": { "X-RateLimit-Limit": { "description": "Number of requests permitted per time period", @@ -15006,11 +15006,27 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Marker" + "type": "object", + "additionalProperties": { + "$ref": "#/components/schemas/Marker" + }, + "propertyNames": { + "enum": [ + "home", + "notifications" + ] + } }, - "examples": { - "Marker200Example": { - "$ref": "#/components/examples/Marker200Example" + "example": { + "notifications": { + "last_read_id": "35098814", + "version": 361, + "updated_at": "2019-11-26T22:37:25.239Z" + }, + "home": { + "last_read_id": "103206604258487607", + "version": 468, + "updated_at": "2019-11-26T22:37:25.235Z" } } } @@ -15130,7 +15146,7 @@ ], "responses": { "200": { - "description": "[Marker]", + "description": "Hash of String (Enumerable, anyOf `home` or `notifications`) key and associated [Marker] value", "headers": { "X-RateLimit-Limit": { "description": "Number of requests permitted per time period", @@ -15155,11 +15171,22 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Marker" + "type": "object", + "additionalProperties": { + "$ref": "#/components/schemas/Marker" + }, + "propertyNames": { + "enum": [ + "home", + "notifications" + ] + } }, - "examples": { - "Marker200Example": { - "$ref": "#/components/examples/Marker200Example" + "example": { + "home": { + "last_read_id": "103194548672408537", + "version": 462, + "updated_at": "2019-11-24T19:39:39.337Z" } } } @@ -40332,21 +40359,6 @@ ] } }, - "Marker200Example": { - "summary": "Example for Marker", - "value": { - "notifications": { - "last_read_id": "35098814", - "version": 361, - "updated_at": "2019-11-26T22:37:25.239Z" - }, - "home": { - "last_read_id": "103206604258487607", - "version": 468, - "updated_at": "2019-11-26T22:37:25.235Z" - } - } - }, "MediaAttachment200Example": { "summary": "Example for MediaAttachment", "value": { diff --git a/src/generators/TypeParser.ts b/src/generators/TypeParser.ts index 11e8e91..561b5b7 100644 --- a/src/generators/TypeParser.ts +++ b/src/generators/TypeParser.ts @@ -204,6 +204,42 @@ class TypeParser { } } + // Handle Hash with enumerable keys pattern: + // "Hash of String (Enumerable, anyOf `home` or `notifications`) key and associated [Entity] value" + const hashEnumMatch = returns.match( + /Hash of String \(Enumerable,\s*anyOf\s+([^)]+)\)\s+key and associated \[([^\]]+)\]/i + ); + if (hashEnumMatch) { + const enumValuesStr = hashEnumMatch[1]; + const entityName = hashEnumMatch[2]; + const sanitizedEntityName = + this.utilityHelpers.sanitizeSchemaName(entityName); + + // Extract enum values from backtick-quoted strings + const enumValues = enumValuesStr + .match(/`([^`]+)`/g) + ?.map((val) => val.replace(/`/g, '')); + + // Check if the entity exists in the components.schemas + if (spec.components?.schemas?.[sanitizedEntityName]) { + const schema: OpenAPIProperty = { + type: 'object', + additionalProperties: { + $ref: `#/components/schemas/${sanitizedEntityName}`, + }, + }; + + // Add propertyNames constraint with enum if we found enum values + if (enumValues && enumValues.length > 0) { + schema.propertyNames = { + enum: enumValues, + }; + } + + return schema; + } + } + // Handle array responses: "Array of String", "Array of Integer", etc. const basicArrayMatch = returns.match(/Array of (\w+)/i); if (basicArrayMatch) { diff --git a/src/interfaces/OpenAPISchema.ts b/src/interfaces/OpenAPISchema.ts index d5bd268..3ab7bfa 100644 --- a/src/interfaces/OpenAPISchema.ts +++ b/src/interfaces/OpenAPISchema.ts @@ -68,6 +68,9 @@ interface OpenAPIProperty { required?: string[]; example?: any; additionalProperties?: OpenAPIProperty | boolean; + propertyNames?: { + enum?: string[]; + }; } interface OpenAPISchema {