Skip to content

Commit 2559944

Browse files
authored
Merge pull request #528 from abraham/markers
Fix hash response parsing
2 parents c43c49c + fd0fc01 commit 2559944

File tree

4 files changed

+78
-26
lines changed

4 files changed

+78
-26
lines changed

config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"cb223aa9f88db46557ee5722f347055a69e0b3df",
1414
"ed347a1958f584f2a891e15521cffe7aff754a62",
1515
"b7a315c559cb457723c726c1b49f07c35f2bd8a9",
16-
"9a38bf8d99187663fbb905e4aba0205735accf32"
16+
"9a38bf8d99187663fbb905e4aba0205735accf32",
17+
"15798b0700f9685e8dd3b7511de83c21e7acce02"
1718
]
1819
}

dist/schema.json

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14981,7 +14981,7 @@
1498114981
],
1498214982
"responses": {
1498314983
"200": {
14984-
"description": "Hash of timeline key and associated [Marker]",
14984+
"description": "Hash of String (Enumerable, anyOf `home` or `notifications`) key and associated [Marker] value",
1498514985
"headers": {
1498614986
"X-RateLimit-Limit": {
1498714987
"description": "Number of requests permitted per time period",
@@ -15006,11 +15006,27 @@
1500615006
"content": {
1500715007
"application/json": {
1500815008
"schema": {
15009-
"$ref": "#/components/schemas/Marker"
15009+
"type": "object",
15010+
"additionalProperties": {
15011+
"$ref": "#/components/schemas/Marker"
15012+
},
15013+
"propertyNames": {
15014+
"enum": [
15015+
"home",
15016+
"notifications"
15017+
]
15018+
}
1501015019
},
15011-
"examples": {
15012-
"Marker200Example": {
15013-
"$ref": "#/components/examples/Marker200Example"
15020+
"example": {
15021+
"notifications": {
15022+
"last_read_id": "35098814",
15023+
"version": 361,
15024+
"updated_at": "2019-11-26T22:37:25.239Z"
15025+
},
15026+
"home": {
15027+
"last_read_id": "103206604258487607",
15028+
"version": 468,
15029+
"updated_at": "2019-11-26T22:37:25.235Z"
1501415030
}
1501515031
}
1501615032
}
@@ -15130,7 +15146,7 @@
1513015146
],
1513115147
"responses": {
1513215148
"200": {
15133-
"description": "[Marker]",
15149+
"description": "Hash of String (Enumerable, anyOf `home` or `notifications`) key and associated [Marker] value",
1513415150
"headers": {
1513515151
"X-RateLimit-Limit": {
1513615152
"description": "Number of requests permitted per time period",
@@ -15155,11 +15171,22 @@
1515515171
"content": {
1515615172
"application/json": {
1515715173
"schema": {
15158-
"$ref": "#/components/schemas/Marker"
15174+
"type": "object",
15175+
"additionalProperties": {
15176+
"$ref": "#/components/schemas/Marker"
15177+
},
15178+
"propertyNames": {
15179+
"enum": [
15180+
"home",
15181+
"notifications"
15182+
]
15183+
}
1515915184
},
15160-
"examples": {
15161-
"Marker200Example": {
15162-
"$ref": "#/components/examples/Marker200Example"
15185+
"example": {
15186+
"home": {
15187+
"last_read_id": "103194548672408537",
15188+
"version": 462,
15189+
"updated_at": "2019-11-24T19:39:39.337Z"
1516315190
}
1516415191
}
1516515192
}
@@ -40332,21 +40359,6 @@
4033240359
]
4033340360
}
4033440361
},
40335-
"Marker200Example": {
40336-
"summary": "Example for Marker",
40337-
"value": {
40338-
"notifications": {
40339-
"last_read_id": "35098814",
40340-
"version": 361,
40341-
"updated_at": "2019-11-26T22:37:25.239Z"
40342-
},
40343-
"home": {
40344-
"last_read_id": "103206604258487607",
40345-
"version": 468,
40346-
"updated_at": "2019-11-26T22:37:25.235Z"
40347-
}
40348-
}
40349-
},
4035040362
"MediaAttachment200Example": {
4035140363
"summary": "Example for MediaAttachment",
4035240364
"value": {

src/generators/TypeParser.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,42 @@ class TypeParser {
204204
}
205205
}
206206

207+
// Handle Hash with enumerable keys pattern:
208+
// "Hash of String (Enumerable, anyOf `home` or `notifications`) key and associated [Entity] value"
209+
const hashEnumMatch = returns.match(
210+
/Hash of String \(Enumerable,\s*anyOf\s+([^)]+)\)\s+key and associated \[([^\]]+)\]/i
211+
);
212+
if (hashEnumMatch) {
213+
const enumValuesStr = hashEnumMatch[1];
214+
const entityName = hashEnumMatch[2];
215+
const sanitizedEntityName =
216+
this.utilityHelpers.sanitizeSchemaName(entityName);
217+
218+
// Extract enum values from backtick-quoted strings
219+
const enumValues = enumValuesStr
220+
.match(/`([^`]+)`/g)
221+
?.map((val) => val.replace(/`/g, ''));
222+
223+
// Check if the entity exists in the components.schemas
224+
if (spec.components?.schemas?.[sanitizedEntityName]) {
225+
const schema: OpenAPIProperty = {
226+
type: 'object',
227+
additionalProperties: {
228+
$ref: `#/components/schemas/${sanitizedEntityName}`,
229+
},
230+
};
231+
232+
// Add propertyNames constraint with enum if we found enum values
233+
if (enumValues && enumValues.length > 0) {
234+
schema.propertyNames = {
235+
enum: enumValues,
236+
};
237+
}
238+
239+
return schema;
240+
}
241+
}
242+
207243
// Handle array responses: "Array of String", "Array of Integer", etc.
208244
const basicArrayMatch = returns.match(/Array of (\w+)/i);
209245
if (basicArrayMatch) {

src/interfaces/OpenAPISchema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ interface OpenAPIProperty {
6868
required?: string[];
6969
example?: any;
7070
additionalProperties?: OpenAPIProperty | boolean;
71+
propertyNames?: {
72+
enum?: string[];
73+
};
7174
}
7275

7376
interface OpenAPISchema {

0 commit comments

Comments
 (0)