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.

ApiProperty for unknown keys (dictionaries)

See original GitHub issue

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

If my schema is contain dictionaries (properties with unknown key) I dont know how create schema descriptions for it like here https://swagger.io/docs/specification/data-models/dictionaries/

Example:

class ColorDto {
  @ApiProperty()
  hex: string;
  
  @ApiProperty()
  rgb: string;
}

class RainbowDto {
  @ApiProperty()
  name: string;
  
  @???????
  colors: { [key: string] : ColorDto }
}

Describe the solution you’d like

class ColorDto {
  @ApiProperty()
  hex: string;
  
  @ApiProperty()
  rgb: string;
}

class RainbowDto {
  @ApiProperty()
  name: string;
  
  @ApiAdditionalProperty({
     type: ColorDto
  })
  colors: { [key: string] : ColorDto }
}

Teachability, documentation, adoption, migration strategy

No response

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

This is super often problem, and I dont know how to solve this trouble for now…

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:8
  • Comments:5

github_iconTop GitHub Comments

4reactions
madmxgcommented, Mar 17, 2022

Workaround

@Controller('api/v1/some-resource')
export class SomeResourceController {
  @ApiOkResponse({
    description: 'Some description.',
    schema: {
      type: 'object',
      example: {
        'key1': {
          name: 'string',
          date: 'string',
        },
        'key2': {
          name: 'string',
          date: 'string',
        },
      },
      additionalProperties: {
        $ref: '#/components/schemas/NameOfSomeDto',
      },
    },
  })
  public async readSomeResource() {}
}
1reaction
voidberg1commented, Jun 3, 2022

Any updates on this? Unfortunately, it seems decorators cannot be attached to index signatures. 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dictionaries, Hashmaps, Associative Arrays - Swagger
A dictionary (also known as a map, hashmap or associative array) is a set of key/value ... OpenAPI lets you define dictionaries where...
Read more >
How to define swagger property that is an unknown name?
I need to define a swagger property that doesn't have a known name. { "type": "object", "properties": { "?????": ...
Read more >
Fix Swagger Validator errors in Power Platform connectors
Check to see if the x-ms-editor is only set to dictionary when the schema is of type object and set to additional properties...
Read more >
Types and Parameters - OpenAPI - Documentation | NestJS
import { ApiProperty } from '@nestjs/swagger'; export class CreateCatDto ... In order to explicitly set the type of the property, use the type...
Read more >
Loading JSON data from Cloud Storage | BigQuery
If you want to ignore values in a row that are not present in the table's schema, then select Unknown values. For Encryption,...
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