Skip to content

Commit 959c2fc

Browse files
constantantclaude
andcommitted
docs(openapi-resource-gen): update generated mock file example for options? param
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7d61ea9 commit 959c2fc

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

tools/openapi-resource-gen/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Each `.mock.ts` file exports a single `provide{Operation}Mock(initialBehavior?)`
139139
// pet/find-pets-by-status.mock.ts (generated)
140140
import { FactoryProvider } from '@angular/core';
141141
import { provideMockResource } from '@constantant/openapi-resource-mocks';
142-
import type { ProviderInitialBehavior, MockResourceMeta } from '@constantant/openapi-resource-mocks';
142+
import type { ProviderInitialBehavior, MockProviderOptions, MockResourceMeta } from '@constantant/openapi-resource-mocks';
143143
import { FIND_PETS_BY_STATUS } from './find-pets-by-status.token';
144144
import type { FindPetsByStatusResponse } from './find-pets-by-status.token';
145145

@@ -153,13 +153,16 @@ const _meta: MockResourceMeta = {
153153

154154
export function provideFindPetsByStatusMock(
155155
initialBehavior?: ProviderInitialBehavior<FindPetsByStatusResponse>,
156+
options?: MockProviderOptions,
156157
): FactoryProvider {
157-
return provideMockResource(FIND_PETS_BY_STATUS, 'FIND_PETS_BY_STATUS', initialBehavior, _meta);
158+
return provideMockResource(FIND_PETS_BY_STATUS, 'FIND_PETS_BY_STATUS', initialBehavior, _meta, options);
158159
}
159160
```
160161

161162
Each mock file also embeds a `MockResourceMeta` const with `specId`, `operationId`, `path`, `method`, and `tag`. The DevTools panel reads this metadata to pre-populate the Respond tab's schema display — no manual configuration needed.
162163

164+
The optional `options` argument (second param on the wrapper) is passed through to `provideMockResource`. The main use is `keyDiscriminator` — see [`@constantant/openapi-resource-mocks`](https://www.npmjs.com/package/@constantant/openapi-resource-mocks) for details.
165+
163166
The token name string key is always in sync — renaming an operation in the spec and
164167
regenerating updates both the token constant and its key automatically.
165168

@@ -182,6 +185,9 @@ provideFindPetsByStatusMock({
182185
value: [{ id: 1, name: 'Rex', status: 'available', photoUrls: [] }],
183186
delay: 500,
184187
})
188+
189+
// With keyDiscriminator for list-row components (second argument)
190+
provideFindPetsByStatusMock(undefined, { keyDiscriminator: () => inject(PET_ID).toString() })
185191
```
186192

187193
`initialBehavior` supports:

0 commit comments

Comments
 (0)