swagger
swagger copied to clipboard
Swagger does not correctly show schema for nested response data
Bug Report
Current behavior
Consider the Cat sample, but the cat entity contains a "preferredFood" field that is the cat's preferred food as a "Food" entity and the Food entity, in turn, contains a field "vendor" that is a Vendor entity that supplies the food. When rendering swagger for the Cat API, we see the details of the preferredFood field's object, but we see only that the "vendor" field is an object, but no details about that object.
Input Code
https://github.com/pvogel1967/11-swagger
Expected behavior
Cat > {
age , etc.
preferredFood > {
weight, etc.
vendor > {
name: string
example: Purina
The name of the vendor
address: string
example: 1600 Pennsylvania Ave, N.W., Washington, DC. 20500
The mailing address of the vendor
}
}
}
Possible Solution
Environment
Nest version: 7.6.15
For Tooling issues:
- Node version: 14.15.5
- Platform: Mac
Others:
any update on this? i'm facing the same issue
Something wrong with schemas. Temporary solution. You can use oneOf keyword and getSchemaPath method:
@Type(() => YourClass)
@ValidateNested()
@ApiProperty({
description: 'Test',
oneOf: [{ $ref: getSchemaPath(YourClass) }],
type: () => YourClass,
})
public readonly yourField: YourClass;
Docs: https://docs.nestjs.com/openapi/types-and-parameters
Something wrong with schemas. Temporary solution. You can use oneOf keyword and getSchemaPath method:
@Type(() => YourClass) @ValidateNested() @ApiProperty({ description: 'Test', oneOf: [{ $ref: getSchemaPath(YourClass) }], type: () => YourClass, }) public readonly yourField: YourClass;
Docs: https://docs.nestjs.com/openapi/types-and-parameters
Nothing change when update this temporary solution
Any updates on this issue !!!
Would you like to create a PR for this issue?
same here, is there a way to fix it?
The problem is that the title somehow get erased. Setting the title manually will fix the issue.
No title:
@ApiProperty({
type: StoreAvailability,
description: 'Store availability configuration',
})
availability!: StoreAvailability;
With title:
@ApiProperty({
type: StoreAvailability,
title: 'StoreAvailability',
description: 'Store availability configuration',
})
availability!: StoreAvailability;