Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ApiProperty with type: 'object' does not compile in some cases #3163

Closed
2 tasks done
flovouin opened this issue Nov 13, 2024 · 3 comments
Closed
2 tasks done

@ApiProperty with type: 'object' does not compile in some cases #3163

flovouin opened this issue Nov 13, 2024 · 3 comments

Comments

@flovouin
Copy link

Did you read the migration guide?

  • I have read the whole migration guide

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Potential Commit/PR that introduced the regression

92df199

Versions

7.4.2 -> 8.0.0

Describe the regression

SchemaObjectMetadata, which is used by the @ApiProperty decorator, has become more restrictive. Previously, type could be any string (amongst others). Now, if the type is 'object', it must also provide properties, and required applies to... the properties of the object itself?
I would assume the minimum reproduction code is a valid JSONSchema. How do I express it using the @ApiProperty decorator?

Minimum reproduction code

@ApiProperty({
    required: true,
    description: 'Some description.',
    type: 'object',
    additionalProperties: { type: 'boolean' },
})

Expected behavior

The minimum reproduction code compiles.

Other

No response

@kamilmysliwiec
Copy link
Member

Now, if the type is 'object', it must also provide properties, and required applies to... the properties of the object itself?

Correct

What would you like to accomplish that's not doable with the current API?

@flovouin
Copy link
Author

flovouin commented Nov 15, 2024

I'd like to express something similar to the minimum reproduction code: the property is of type object, and this object only defines additionalProperties. For example the TypeScript class and resulting JSONSchema would be something like:

class MyEntity {
  @ApiProperty({
    // This does not compile with version 8.
    required: true,  // In this example, `required` is `true`, but it could be `false` (in which case the property could have the value `undefined`).
    type: 'object',
    additionalProperties: { type: 'boolean' },
  })
  myObjectProperty: Record<string, bool>;
}
title: MyEntity
type: object
properties:
  myObjectProperty:
    type: object
    additionalProperties:
      type: boolean
required:
  - myObjectProperty

Depending on the use case, I want to be able to declare myObjectProperty as required or not.

@kamilmysliwiec
Copy link
Member

Ah pardon me, I forgot to update the types to include the newly added selfRequired attribute that you can use for this. Fixed in this PR #3169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants