Skip to content

Commit 90d39f5

Browse files
authored
fix(content): build single-type auth model (#52)
* feat(http-requests): cleanup * fix: build single-type auth schema for non ref on ref components * feat: cleanup * feat: cleanup * feat: update jsdocs
1 parent 841209b commit 90d39f5

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

http-requests/requests.http

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,3 @@ Content-Type: application/json
107107
}
108108
}
109109
}
110-
111-
###

microservices/content/src/services/single-type-meta.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ class SingleTypeMeta {
8080

8181
for (const component of components) {
8282
const { alias, schema } = component;
83-
const prefix = !isNested ? 'DynamicModel' : '';
83+
84+
const prefix = isNested ? '' : 'DynamicModel';
8485
const aliasKey = `${prefix}${ucfirst(singleTypeAlias)}`;
8586

8687
const newProperties = {
@@ -111,29 +112,57 @@ class SingleTypeMeta {
111112
}
112113

113114
if (type === InputType.COMPONENT) {
114-
const { id } = field as IComponentSchema;
115+
/**
116+
* Extract ref from component
117+
*/
118+
const { id: inputId } = field as IComponentSchema;
115119

116120
const nestedCustomComponents: ComponentEntity[] =
117-
await this.componentRepository.getChildrenComponentById(id);
121+
await this.componentRepository.getChildrenComponentById(inputId);
118122

119123
if (!nestedCustomComponents?.length) {
120124
continue;
121125
}
122126

127+
const nestedData = await this.buildMetaSchema({
128+
components: nestedCustomComponents,
129+
isNested: true,
130+
singleTypeAlias: alias,
131+
});
132+
133+
/**
134+
* Extracted component from ref
135+
*/
136+
const extractedComponent = nestedData?.properties?.[0];
137+
138+
/**
139+
* Check if nested component data isn't declared as the refComponent(id) => refComponent(id) => dataComponent
140+
* If isn't ref component spread nested data to parent component
141+
*/
142+
if (nestedData?.properties?.[name] && extractedComponent) {
143+
newProperties.properties[alias].properties.data.properties = {
144+
...newProperties.properties[alias].properties.data.properties,
145+
...nestedData.properties,
146+
};
147+
continue;
148+
}
149+
150+
/**
151+
* If ref component wrap and spread nested
152+
*/
123153
newProperties.properties[alias].properties.data.properties[name] = {
124154
type: 'object',
125155
properties: {
126156
id: { type: 'string' },
127-
data: await this.buildMetaSchema({
128-
components: nestedCustomComponents,
129-
isNested: true,
130-
singleTypeAlias: alias,
131-
}),
157+
data: nestedData,
132158
},
133159
};
134160
continue;
135161
}
136162

163+
/**
164+
* If is primitive
165+
*/
137166
newProperties.properties[alias].properties.data.properties[name] = {
138167
type: this.getSchemaType(type),
139168
};

0 commit comments

Comments
 (0)