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 decorator required property #1682

Closed
2 of 4 tasks
antspk opened this issue Nov 19, 2021 · 10 comments
Closed
2 of 4 tasks

ApiProperty decorator required property #1682

antspk opened this issue Nov 19, 2021 · 10 comments

Comments

@antspk
Copy link

antspk commented Nov 19, 2021

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When using @ApiProperty decorator should be able to provide raw definition as documented here: https://docs.nestjs.com/openapi/types-and-parameters#raw-definitions.

However if try to provide raw definition like this:

@ApiProperty({
  type: 'object',
  required: ['name', 'status'],
  properties: {
    name: {
      type: 'string',
      example: 'ErrorName',
    },
    status: {
      type: 'number',
      example: '400',
    },
  },
})

It's doesn't accept required property as an array which I'm assuming it should if it were following the structure documented here: https://swagger.io/docs/specification/data-models/data-types/#required

Minimum reproduction code

https://github.com/antspk/swagger-bug

Steps to reproduce

  1. npm i
  2. uncomment src/app.error.ts line 8

Expected behavior

It should allow providing required property as a string array which would map to the properties object.

Package version

5.1.5

NestJS version

8.2.2

Node.js version

16.13.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@loginov-rocks
Copy link

+1, gives error: TS2322: Type 'string[]' is not assignable to type 'boolean'

@micalevisk
Copy link
Member

looks like this 'raw' definition wasn't designed to follow the OpenAPI spec(?)

You can see here:

the real raw definition (I guess), is called SchemaObject

But then, the one used by @ApiProperty extends it but without the required field:

export interface SchemaObjectMetadata
extends Omit<SchemaObject, 'type' | 'required'> {

@cleitinif
Copy link

+1

6 similar comments
@omidh14
Copy link

omidh14 commented Oct 3, 2022

+1

@dmiranda2791
Copy link

+1

@ondrejmoris
Copy link

+1

@rafakwolf
Copy link

+1

@Notalifeform
Copy link

+1

@lunkums
Copy link

lunkums commented Feb 7, 2024

+1

@kamilmysliwiec
Copy link
Member

92df199

@nestjs nestjs locked and limited conversation to collaborators Oct 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests