Skip to content

Commit 12a1fa7

Browse files
committed
test: add tuple-form coverage and fix gateway-tuple snapshot
The gateway-tuple test config (added in orval-labs#3693) was relying on sanitize() to strip {param} placeholders from the route — accidental coupling that broke once overridden operationNames stopped being sanitized. Drop the path-param route from the spec since it isn't what the test demonstrates. Add tuple-form coverage for the $/_ preservation fix, asserting both the methodName (verbatim) and the typeName (pascal-cased by getters) land in the expected places.
1 parent 5d25737 commit 12a1fa7

3 files changed

Lines changed: 39 additions & 26 deletions

File tree

packages/orval/src/generate-spec.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,44 @@ describe('generateSpec - operationName tuple [methodName, typeName]', () => {
16061606
}
16071607
});
16081608

1609+
it('preserves underscores and $ in overridden operationName tuple form (#3775)', async () => {
1610+
const workspace = await createTempWorkspace();
1611+
const targetFile = path.join(workspace, 'endpoints.ts');
1612+
1613+
try {
1614+
const options = await normalizeOptions(
1615+
{
1616+
input: { target: GATEWAY_SPEC },
1617+
output: {
1618+
target: './endpoints.ts',
1619+
client: 'axios',
1620+
override: {
1621+
operationName: (_operation, route, _verb) => {
1622+
const segments = route.split('/').filter(Boolean);
1623+
// methodName: short, typeName: long; both carry $ and _.
1624+
return [`$${segments.at(-1)}`, `$${segments.join('_')}`];
1625+
},
1626+
},
1627+
},
1628+
},
1629+
workspace,
1630+
);
1631+
1632+
await generateSpec(workspace, options);
1633+
1634+
const content = await fs.readFile(targetFile, 'utf-8');
1635+
1636+
// Method name preserved verbatim, including $ and _.
1637+
expect(content).toContain('$items');
1638+
expect(content).toContain('$products');
1639+
// Type name (pascal-cased by getters) carries the longer typeName base.
1640+
expect(content).toContain('ApiCatalogItemsResult');
1641+
expect(content).toContain('ApiInventoryProductsResult');
1642+
} finally {
1643+
await rm(workspace, { recursive: true, force: true });
1644+
}
1645+
});
1646+
16091647
it('produces globally unique type names across tags in tags-split mode', async () => {
16101648
const workspace = await createTempWorkspace();
16111649

tests/__snapshots__/axios/gateway-tuple-tags-split/catalog/catalog.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,7 @@ export const getCatalog = (axiosInstance: AxiosInstance = axios) => {
2525
): Promise<AxiosResponse<Product>> => {
2626
return axiosInstance.post(`/api/catalog/products`, product, options);
2727
};
28-
const getProductsproductId = (
29-
productId: string,
30-
options?: AxiosRequestConfig,
31-
): Promise<AxiosResponse<Product>> => {
32-
return axiosInstance.get(`/api/catalog/products/${productId}`, options);
33-
};
34-
return { getProducts, postProducts, getProductsproductId };
28+
return { getProducts, postProducts };
3529
};
3630
export type GetCatalogProductsResult = AxiosResponse<Product>;
3731
export type PostCatalogProductsResult = AxiosResponse<Product>;
38-
export type GetCatalogProductsproductIdResult = AxiosResponse<Product>;

tests/specifications/gateway-tuple.yaml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,6 @@ paths:
3737
application/json:
3838
schema:
3939
$ref: '#/components/schemas/Product'
40-
/api/catalog/products/{productId}:
41-
get:
42-
tags:
43-
- catalog
44-
operationId: getCatalogProductById
45-
parameters:
46-
- name: productId
47-
in: path
48-
required: true
49-
schema:
50-
type: string
51-
responses:
52-
'200':
53-
description: A single product
54-
content:
55-
application/json:
56-
schema:
57-
$ref: '#/components/schemas/Product'
5840
/api/inventory/stock:
5941
get:
6042
tags:

0 commit comments

Comments
 (0)