Skip to content

Commit 27e95a3

Browse files
authored
feat(compass-collection): Match sample values field name to backend - CLOUDP-350280 (#7435)
* fix(compass-collection): Fix field name mismatch in Mock Data Generator API - Change 'sample_values' to 'sampleValues' in FieldInfo interface to match backend API expectations - Update all test files to use the new field name - Resolves 400 Bad Request error when generating faker mappings The backend API expects 'sampleValues' (camelCase) but frontend was sending 'sample_values' (snake_case), causing the LLM request to fail with 'Invalid request' error. Fixes CLOUDP-350280 * Revert comment
1 parent ffd956b commit 27e95a3

File tree

6 files changed

+69
-69
lines changed

6 files changed

+69
-69
lines changed

packages/compass-collection/src/components/collection-header/collection-header.spec.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ describe('CollectionHeader [Component]', function () {
429429
schemaAnalysis: {
430430
status: SCHEMA_ANALYSIS_STATE_COMPLETE,
431431
processedSchema: {
432-
field1: { type: 'String', sample_values: ['value1'] },
432+
field1: { type: 'String', sampleValues: ['value1'] },
433433
},
434434
schemaMetadata: {
435435
maxNestingDepth: 2, // Below the limit of 4
@@ -485,7 +485,7 @@ describe('CollectionHeader [Component]', function () {
485485
schemaAnalysis: {
486486
status: SCHEMA_ANALYSIS_STATE_COMPLETE,
487487
processedSchema: {
488-
field1: { type: 'String', sample_values: ['value1'] },
488+
field1: { type: 'String', sampleValues: ['value1'] },
489489
},
490490
schemaMetadata: {
491491
maxNestingDepth: 4, // Exceeds the limit
@@ -514,7 +514,7 @@ describe('CollectionHeader [Component]', function () {
514514
schemaAnalysis: {
515515
status: SCHEMA_ANALYSIS_STATE_COMPLETE,
516516
processedSchema: {
517-
field1: { type: 'String', sample_values: ['value1'] },
517+
field1: { type: 'String', sampleValues: ['value1'] },
518518
},
519519
schemaMetadata: {
520520
maxNestingDepth: 2,
@@ -541,7 +541,7 @@ describe('CollectionHeader [Component]', function () {
541541
schemaAnalysis: {
542542
status: SCHEMA_ANALYSIS_STATE_COMPLETE,
543543
processedSchema: {
544-
field1: { type: 'String', sample_values: ['value1'] },
544+
field1: { type: 'String', sampleValues: ['value1'] },
545545
},
546546
schemaMetadata: {
547547
maxNestingDepth: 2,
@@ -576,7 +576,7 @@ describe('CollectionHeader [Component]', function () {
576576
schemaAnalysis: {
577577
status: SCHEMA_ANALYSIS_STATE_COMPLETE,
578578
processedSchema: {
579-
field1: { type: 'String', sample_values: ['value1'] },
579+
field1: { type: 'String', sampleValues: ['value1'] },
580580
},
581581
schemaMetadata: {
582582
maxNestingDepth: 2,

packages/compass-collection/src/components/mock-data-generator-modal/mock-data-generator-modal.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const defaultSchemaAnalysisState: SchemaAnalysisState = {
2727
name: {
2828
type: 'String',
2929
probability: 1.0,
30-
sample_values: ['John', 'Jane'],
30+
sampleValues: ['John', 'Jane'],
3131
},
3232
},
3333
arrayLengthMap: {},
@@ -510,7 +510,7 @@ describe('MockDataGeneratorModal', () => {
510510
type: {
511511
type: 'String',
512512
probability: 1.0,
513-
sample_values: ['cat', 'dog'],
513+
sampleValues: ['cat', 'dog'],
514514
},
515515
},
516516
sampleDocument: { name: 'Peaches', age: 10, type: 'cat' },

packages/compass-collection/src/components/mock-data-generator-modal/to-simplified-field-info.spec.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@ describe('toSimplifiedFieldInfo', function () {
77
const input = {
88
'user.name': {
99
type: 'String' as const,
10-
sample_values: ['John'],
10+
sampleValues: ['John'],
1111
probability: 1.0,
1212
},
1313
'user.age': {
1414
type: 'Number' as const,
15-
sample_values: [25, 30],
15+
sampleValues: [25, 30],
1616
probability: 0.8,
1717
},
1818
'user.profile.bio': {
1919
type: 'String' as const,
20-
sample_values: ['Software engineer'],
20+
sampleValues: ['Software engineer'],
2121
probability: 0.9,
2222
},
2323
'user.profile.isVerified': {
2424
type: 'Boolean' as const,
25-
sample_values: [true, false],
25+
sampleValues: [true, false],
2626
probability: 0.7,
2727
},
2828
'metadata.createdAt': {
2929
type: 'Date' as const,
30-
sample_values: [new Date('2023-01-01')],
30+
sampleValues: [new Date('2023-01-01')],
3131
probability: 1.0,
3232
},
3333
'metadata.objectId': {
3434
type: 'ObjectId' as const,
35-
sample_values: ['642d766b7300158b1f22e972'],
35+
sampleValues: ['642d766b7300158b1f22e972'],
3636
probability: 1.0,
3737
},
3838
};
@@ -61,32 +61,32 @@ describe('toSimplifiedFieldInfo', function () {
6161
const input = {
6262
'tags[]': {
6363
type: 'String' as const,
64-
sample_values: ['red', 'blue', 'green'],
64+
sampleValues: ['red', 'blue', 'green'],
6565
probability: 1.0,
6666
},
6767
'scores[]': {
6868
type: 'Number' as const,
69-
sample_values: [85, 92, 78],
69+
sampleValues: [85, 92, 78],
7070
probability: 0.9,
7171
},
7272
'matrix[][]': {
7373
type: 'Number' as const,
74-
sample_values: [1, 2, 3, 4],
74+
sampleValues: [1, 2, 3, 4],
7575
probability: 1.0,
7676
},
7777
'flags[]': {
7878
type: 'Boolean' as const,
79-
sample_values: [true, false],
79+
sampleValues: [true, false],
8080
probability: 0.8,
8181
},
8282
'timestamps[]': {
8383
type: 'Date' as const,
84-
sample_values: [new Date('2023-01-01'), new Date('2023-06-15')],
84+
sampleValues: [new Date('2023-01-01'), new Date('2023-06-15')],
8585
probability: 0.7,
8686
},
8787
'ids[]': {
8888
type: 'ObjectId' as const,
89-
sample_values: ['642d766b7300158b1f22e972', '642d766b7300158b1f22e973'],
89+
sampleValues: ['642d766b7300158b1f22e972', '642d766b7300158b1f22e973'],
9090
probability: 1.0,
9191
},
9292
};
@@ -109,32 +109,32 @@ describe('toSimplifiedFieldInfo', function () {
109109
const input = {
110110
'items[].id': {
111111
type: 'Number' as const,
112-
sample_values: [1, 2],
112+
sampleValues: [1, 2],
113113
probability: 1.0,
114114
},
115115
'items[].name': {
116116
type: 'String' as const,
117-
sample_values: ['Item A', 'Item B'],
117+
sampleValues: ['Item A', 'Item B'],
118118
probability: 1.0,
119119
},
120120
'items[].metadata.createdBy': {
121121
type: 'String' as const,
122-
sample_values: ['admin', 'user'],
122+
sampleValues: ['admin', 'user'],
123123
probability: 0.9,
124124
},
125125
'items[].metadata.tags[]': {
126126
type: 'String' as const,
127-
sample_values: ['urgent', 'review', 'approved'],
127+
sampleValues: ['urgent', 'review', 'approved'],
128128
probability: 0.8,
129129
},
130130
'items[].price': {
131131
type: 'Decimal128' as const,
132-
sample_values: [19.99, 29.99],
132+
sampleValues: [19.99, 29.99],
133133
probability: 0.95,
134134
},
135135
'items[].binary': {
136136
type: 'Binary' as const,
137-
sample_values: ['dGVzdA=='],
137+
sampleValues: ['dGVzdA=='],
138138
probability: 0.3,
139139
},
140140
};
@@ -162,62 +162,62 @@ describe('toSimplifiedFieldInfo', function () {
162162
const input = {
163163
'cube[][][]': {
164164
type: 'Number' as const,
165-
sample_values: [1, 2, 3, 4, 5, 6, 7, 8],
165+
sampleValues: [1, 2, 3, 4, 5, 6, 7, 8],
166166
probability: 1.0,
167167
},
168168
'matrix[][].x': {
169169
type: 'Number' as const,
170-
sample_values: [1, 3],
170+
sampleValues: [1, 3],
171171
probability: 1.0,
172172
},
173173
'matrix[][].y': {
174174
type: 'Number' as const,
175-
sample_values: [2, 4],
175+
sampleValues: [2, 4],
176176
probability: 1.0,
177177
},
178178
'teams[].members[]': {
179179
type: 'String' as const,
180-
sample_values: ['Alice', 'Bob', 'Charlie'],
180+
sampleValues: ['Alice', 'Bob', 'Charlie'],
181181
probability: 1.0,
182182
},
183183
'teams[].name': {
184184
type: 'String' as const,
185-
sample_values: ['Team A', 'Team B'],
185+
sampleValues: ['Team A', 'Team B'],
186186
probability: 1.0,
187187
},
188188
'complex[][].data[]': {
189189
type: 'Long' as const,
190-
sample_values: [123456789, 987654321],
190+
sampleValues: [123456789, 987654321],
191191
probability: 0.9,
192192
},
193193
'complex[][].regex': {
194194
type: 'RegExp' as const,
195-
sample_values: ['pattern'],
195+
sampleValues: ['pattern'],
196196
probability: 0.6,
197197
},
198198
'complex[][].code': {
199199
type: 'Code' as const,
200-
sample_values: ['function() {}'],
200+
sampleValues: ['function() {}'],
201201
probability: 0.4,
202202
},
203203
'nested[][].symbols[]': {
204204
type: 'Symbol' as const,
205-
sample_values: ['symbol1', 'symbol2'],
205+
sampleValues: ['symbol1', 'symbol2'],
206206
probability: 0.5,
207207
},
208208
'timestamps[][].created': {
209209
type: 'Timestamp' as const,
210-
sample_values: [4294967297],
210+
sampleValues: [4294967297],
211211
probability: 0.8,
212212
},
213213
'keys[][].max': {
214214
type: 'MaxKey' as const,
215-
sample_values: ['MaxKey'],
215+
sampleValues: ['MaxKey'],
216216
probability: 0.2,
217217
},
218218
'keys[][].min': {
219219
type: 'MinKey' as const,
220-
sample_values: ['MinKey'],
220+
sampleValues: ['MinKey'],
221221
probability: 0.2,
222222
},
223223
};

packages/compass-collection/src/schema-analysis-types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type SchemaAnalysisErrorState = {
3131
};
3232

3333
/**
34-
* Primitive values that can appear in sample_values after BSON-to-primitive conversion.
34+
* Primitive values that can appear in sampleValues after BSON-to-primitive conversion.
3535
* These are the JavaScript primitive equivalents of BSON values.
3636
*/
3737
export type SampleValue =
@@ -47,7 +47,7 @@ export type SampleValue =
4747
*/
4848
export interface FieldInfo {
4949
type: MongoDBFieldType; // MongoDB primitive type
50-
sample_values?: SampleValue[]; // Primitive sample values (limited to 10)
50+
sampleValues?: SampleValue[]; // Primitive sample values (limited to 10)
5151
probability?: number; // 0.0 - 1.0 field frequency
5252
}
5353

0 commit comments

Comments
 (0)