Skip to content

Commit 5fe2076

Browse files
committed
Few fixes for SAM schema transformation
1 parent b5c33df commit 5fe2076

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/schema/GetSamSchemaTask.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const logger = LoggerFactory.getLogger('GetSamSchemaTask');
1010

1111
export class GetSamSchemaTask extends GetSchemaTask {
1212
private static readonly SAM_SCHEMA_URL =
13-
'https://raw.githubusercontent.com/aws/serverless-application-model/refs/heads/main/schema_source/sam.schema.json';
13+
'https://raw.githubusercontent.com/aws/serverless-application-model/refs/heads/develop/samtranslator/schema/schema.json';
1414

1515
@Measure({ name: 'getSchemas' })
1616
override async runImpl(dataStore: DataStore): Promise<void> {

src/schema/SamSchemaTransformer.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const SamSchemaTransformer = {
5959
typeName: resourceType,
6060
description: SAM_RESOURCE_DESCRIPTIONS.get(resourceType) ?? `${resourceType} resource`,
6161
documentationUrl: SAM_DOCUMENTATION_URLS.get(resourceType) ?? '',
62-
properties: (propertiesSchema?.properties as Record<string, unknown>) ?? {},
62+
properties: this.resolvePropertyTypes(propertiesSchema?.properties as Record<string, unknown> ?? {}, samSchema.definitions),
6363
definitions: samSchema.definitions,
6464
additionalProperties: false,
6565
required: (propertiesSchema?.required as string[]) ?? [],
@@ -75,4 +75,47 @@ export const SamSchemaTransformer = {
7575

7676
return resourceSchemas;
7777
},
78+
79+
resolvePropertyTypes(properties: Record<string, unknown>, definitions: Record<string, unknown>): Record<string, unknown> {
80+
const resolved: Record<string, unknown> = {};
81+
82+
for (const [key, value] of Object.entries(properties)) {
83+
resolved[key] = this.resolveProperty(value as Record<string, unknown>, definitions);
84+
}
85+
86+
return resolved;
87+
},
88+
89+
resolveProperty(property: Record<string, unknown>, definitions: Record<string, unknown>): Record<string, unknown> {
90+
// Convert markdownDescription to description for hover formatter
91+
if (property.markdownDescription && !property.description) {
92+
property = { ...property, description: property.markdownDescription };
93+
}
94+
95+
// If property already has a type, keep it
96+
if (property.type) {
97+
return property;
98+
}
99+
100+
// Handle allOf patterns
101+
if (property.allOf && Array.isArray(property.allOf)) {
102+
const allOfItem = property.allOf[0] as Record<string, unknown>;
103+
if (allOfItem?.$ref) {
104+
const resolved = this.resolveProperty(allOfItem, definitions);
105+
return { ...resolved, ...property, allOf: undefined };
106+
}
107+
}
108+
109+
// Handle $ref
110+
if (property.$ref) {
111+
const refKey = (property.$ref as string).replace('#/definitions/', '');
112+
const refDef = definitions[refKey] as Record<string, unknown>;
113+
if (refDef) {
114+
const resolved = this.resolveProperty(refDef, definitions);
115+
return { ...resolved, ...property, $ref: undefined };
116+
}
117+
}
118+
119+
return property;
120+
},
78121
};

0 commit comments

Comments
 (0)