|
I'm running into issues with generating operation schemas. I'm trying to separate operation schemas into their own folder, but when I generate the schemas, almost everything is just going into the base schema directory. Is Orval deciding what is Operational and what isn't based solely on the naming convention? As an example endpoint in my NestJS backend, I have a route that has @ApiParam({
name: 'accountId',
description: 'Account ID',
required: true,
type: Number,
})
@ApiParam({
name: 'houseId',
description: 'House ID',
required: true,
type: Number,
})
@ApiQuery({
name: 'dogBreedId',
required: true,
})
@Get('/:house-id/latest-dog')
@UseGuards(ReadHouseGuard)
@ApiResponse({
status: 200,
description: 'Latest dog associated with the house',
type: Dog,
})
async getLatestDog(
@Param() params: GetHouseLatestDogParamsDTO,
@Query() query: GetHouseLatestDogQueryDTO
) {
const response = await this.houseService.getLatestDog
params.houseId,
query.dogBreedId,
params.accountId
);
return response;
} |
Replies: 1 comment
|
Orval is not deciding this only from the generated name. It mostly follows the shape of the OpenAPI document it receives. In your example there are three different things:
So the inconsistency is probably coming from the emitted OpenAPI spec rather than Orval looking at NestJS decorators directly. The quickest way to confirm is to inspect the generated JSON/YAML: paths:
/...:
get:
parameters:
- in: path
name: accountId
- in: path
name: houseId
- in: query
name: dogBreedId
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Dog'If the params DTOs are not present under For more predictable output, make the OpenAPI source explicit:
In short: response DTOs commonly become shared schemas; path/query parameters commonly remain operation-level unless the OpenAPI document references a reusable component for them. |
Orval is not deciding this only from the generated name. It mostly follows the shape of the OpenAPI document it receives.
In your example there are three different things:
@ApiResponse({ type: Dog })usually becomes a reusable component schema such as#/components/schemas/Dog, so Orval puts it in the normal schemas area.@ApiParam(...)path params are OpenAPI parameters, not a DTO schema reference. Orval can generate them as function arguments or inline parameter handling instead of creating a separate operation schema file.{operationName}Paramsstyle schema/type.So t…