You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[4] dist/api-spec.json:84:25 at #/components/schemas/CreateCatDto/properties/nullableOwner/nullable
The `type` field must be defined when the `nullable` field is used.
82 | },
83 | "nullableOwner": {
84 | "nullable": true,
85 | "description": "The user that owns the cat",
86 | "allOf": [
Error was generated by the struct rule.
Is there an existing issue for this?
#2948 seems similar but was closed as fixed and I'm presuming it was incorporated into the 8.x branch.
Current behavior
With the plugin enabled and looking at the Typescript code a property like:
, it generates the schema's property like:
Redocly's linter flags as an error:
Minimum reproduction code
https://github.com/drewish/swagger-nullable-poc
Steps to reproduce
Setup the repro repo:
Start it up to generate the swagger file (main.ts is saving a copy)
Then use redocly to lint the file:
There are unrelated errors I didn't bother cleaning up. The relevant one is:
Expected behavior
One workaround I've see for this (microsoft/typespec#4584) was to just add
type: 'object'
as a sibling:That renders nicely in Redocly's UI:
![Image](https://private-user-images.githubusercontent.com/68750/406768996-7460e9b9-4758-4964-8e39-144223bc3bfb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNzQyODIsIm5iZiI6MTczOTI3Mzk4MiwicGF0aCI6Ii82ODc1MC80MDY3Njg5OTYtNzQ2MGU5YjktNDc1OC00OTY0LThlMzktMTQ0MjIzYmMzYmZiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDExMzk0MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTE1YzM1NzM2ZjhjNmFjMGYyZTM0NDIwNGU3MDE5MzhjY2IwMDgzZjFlZjdmOTYxY2Q0NmYyOGVhMWI3OTQ3ZDAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.7kZ8nixQGFE6-PeDlkgc8yfyZvZYuucLs7RqnA8gCHQ)
![Image](https://private-user-images.githubusercontent.com/68750/406769072-a6be29c9-109b-46f3-ba18-ec93215fe503.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNzQyODIsIm5iZiI6MTczOTI3Mzk4MiwicGF0aCI6Ii82ODc1MC80MDY3NjkwNzItYTZiZTI5YzktMTA5Yi00NmYzLWJhMTgtZWM5MzIxNWZlNTAzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDExMzk0MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTM5ZWFjYmQzZjY1NGE4YzRlNmUyYmZlMDAzZTkxMmZlMWQyMDJiZGZiMmZkMTVkNTkwNTNmN2E4OTU0ODU1YmQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.kyFtBgKgu2YEFctNVfav2WN7_JMM0a068eGUpNi_46A)
And looks the same in SwaggerUI:
It seems like in
ModelClassVisitor.createTypePropertyAssignments()
, when we create the nullable property:swagger/lib/plugin/visitors/model-class.visitor.ts
Lines 437 to 443 in 8cb1ee8
We could also add
type: 'object'
.But, we'd also need a change in
SchemaObjectFactory.extractPropertiesFromType()
to keep it from deleting the type:swagger/lib/services/schema-object-factory.ts
Line 214 in 8cb1ee8
Package version
11.0.3
NestJS version
11.0.1
Node.js version
v20.16.0
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: