question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: Two dimensional array Not Support by CLI Plugin

See original GitHub issue

I’m submitting a…


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I use Cli Plugin that auto add @ApiProperty. My DTO:

// ./dto/test-report.dto.ts
import { ValidateNested } from 'class-validator'
import { PlanExecutionDto } from './plan-execution.dto'
import { CreateTestReportDto } from './create-test-report.dto'
import { BugStatistics } from './bug-statistics.dto'
import { ManualPlanInfoDto } from './manual-plan-info.dto'
import { CaseExecutionDto } from './case-execution.dto'
import { ApiProperty } from '@nestjs/swagger'


export class TestReportDto {
  @ValidateNested()
  reportInfo!: CreateTestReportDto

  @ValidateNested()
  planInfo!: ManualPlanInfoDto

  @ValidateNested({ each: true })
  planExecution!: PlanExecutionDto[]

  // Here is the error line
  @ValidateNested({ each: true })
  caseExecution!: CaseExecutionDto[][]

  @ValidateNested()
  bugStatistics!: BugStatistics
}

The Swagger Output Piar:


{
  "components": {
    "schemas": {
      "TestReportDto": {
        "type": "object",
        "properties": {
          "reportInfo": {
            "description": "报告信息",
            "allOf": [
              {
                "$ref": "#/components/schemas/CreateTestReportDto"
              }
            ]
          },
          "planInfo": {
            "description": "计划信息",
            "allOf": [
              {
                "$ref": "#/components/schemas/ManualPlanInfoDto"
              }
            ]
          },
          "planExecution": {
            "description": "计划/轮次执行情况",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PlanExecutionDto"
            }
          },
          "caseExecution": {
            "type": "array",
            "items": {
              // Here is the error
              "$ref": "#/components/schemas/"
            }
          },
          "bugStatistics": {
            "description": "Bug 统计",
            "allOf": [
              {
                "$ref": "#/components/schemas/BugStatistics"
              }
            ]
          }
        },
        "required": [
          "reportInfo",
          "planInfo",
          "planExecution",
          "caseExecution",
          "bugStatistics"
        ]
      }
    }
  }
}

Expected behavior

The Swagger should be:

{
  "components": {
    "schemas": {
      "TestReportDto": {
        "type": "object",
        "properties": {
          "reportInfo": {
            "description": "报告信息",
            "allOf": [
              {
                "$ref": "#/components/schemas/CreateTestReportDto"
              }
            ]
          },
          "planInfo": {
            "description": "计划信息",
            "allOf": [
              {
                "$ref": "#/components/schemas/ManualPlanInfoDto"
              }
            ]
          },
          "planExecution": {
            "description": "计划/轮次执行情况",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PlanExecutionDto"
            }
          },
          // Here
          "caseExecution": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "$ref": "#/components/schemas/CaseExecutionDto"
              }
            }
          },
          "bugStatistics": {
            "description": "Bug 统计",
            "allOf": [
              {
                "$ref": "#/components/schemas/BugStatistics"
              }
            ]
          }
        },
        "required": [
          "reportInfo",
          "planInfo",
          "planExecution",
          "caseExecution",
          "bugStatistics"
        ]
      }
    }
  }
}

Minimal reproduction of the problem with instructions

  • Create a nestjs project with cli plugin.
  • add a DTO with Two dimensional array.
  • Generate swagger

What is the motivation / use case for changing the behavior?

Two-dimensional arrays are very common in data structures.

Environment


Nest version: X.Y.Z

 
For Tooling issues:
- Node version: v14.16.1
- Platform:  Mac

Others:

- @nestjs/core: 7.6.15
- @nestjs/swagger: 4.8.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Val-istar-Guocommented, May 12, 2021

I will create a project tonight.

0reactions
kamilmysliwieccommented, Jul 9, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Two-dimensional array in Swift - Stack Overflow
The 2D init using repeated values won't work. All the rows will point to the same sub-array, and thus no be uniquely writable....
Read more >
Cannot read property 'version' of undefined #2866 - GitHub
Im using Version 4.0.2 (+ @vue/cli-service-global@4.0.2) , installed today :O Other versions: Node v10.8 / npm ...
Read more >
Bug listing with status RESOLVED with resolution FIXED as at ...
Bug :2 - "How do I attach an ebuild. ... status:RESOLVED resolution:FIXED severity:enhancement · Bug:353 - "linux-sources: kdb module support will not build....
Read more >
Multidimensional Arrays - MATLAB & Simulink - MathWorks
A multidimensional array in MATLAB® is an array with more than two dimensions. In a matrix, the two dimensions are represented by rows...
Read more >
NVIDIA DRIVE OS Linux SDK API Reference ... - NVIDIA Developer
Not all geometry shader implementations have the ability to write the point size from ... A single layer of a two-dimensional array texture,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found