Skip to content

Commit 083f0f7

Browse files
constantantclaude
andcommitted
fix: deduplicate toCamelCase and guard importJson item shape
- Export toCamelCase from render-token.ts and import it in render-msw-file.ts instead of maintaining a second copy - Guard each mock entry in applyScenario with typeof m?.key === 'string' so malformed importJson payloads (nulls, bare numbers, etc.) skip silently instead of throwing a TypeError Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5894270 commit 083f0f7

3 files changed

Lines changed: 3 additions & 9 deletions

File tree

apps/devtools-panel/src/app/scenario-store.token.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const SCENARIO_STORE = new InjectionToken<ScenarioStore>('SCENARIO_STORE'
6262

6363
function applyScenario(scenario: Scenario): void {
6464
for (const m of scenario.mocks) {
65+
if (typeof m?.key !== 'string') continue;
6566
if (!bridge.mocks().has(m.key)) continue;
6667
if (m.value !== undefined) {
6768
bridge.sendControl(m.key, 'resolve', { value: m.value });

tools/openapi-resource-gen/src/generators/api-resource/render-msw-file.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import type { EndpointModel } from './endpoint-model';
2-
import { toPascalCase } from './render-token';
3-
4-
function toCamelCase(str: string): string {
5-
const parts = str.split(/[-_.]+/).filter(Boolean);
6-
if (parts.length === 0) return str;
7-
const first = parts[0].charAt(0).toLowerCase() + parts[0].slice(1);
8-
return first + parts.slice(1).map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join('');
9-
}
2+
import { toPascalCase, toCamelCase } from './render-token';
103

114
/** Convert OpenAPI path template {param} to MSW :param notation. */
125
function toMswPath(apiPath: string): string {

tools/openapi-resource-gen/src/generators/api-resource/render-token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function toPascalCase(str: string): string {
99
.join('');
1010
}
1111

12-
function toCamelCase(str: string): string {
12+
export function toCamelCase(str: string): string {
1313
const parts = str.split(/[-_.]+/).filter(Boolean);
1414
const first = parts[0].charAt(0).toLowerCase() + parts[0].slice(1);
1515
return first + parts.slice(1).map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join('');

0 commit comments

Comments
 (0)