Tsoa: v3.x @example tag does not work on model properties

Created on 12 Mar 2020  路  3Comments  路  Source: lukeautry/tsoa

Sorting

  • I'm submitting a ...

    • [ ] bug report
    • [x] feature request
    • [ ] support request
  • I confirm that I

    • [x] used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

@example tags placed on models should add examples to their respective properties

export interface TestInput {
    /**
     * a number prop
     * @example 2
     */
    number: number;
    string: string;
}
"TestInput": {
  "properties": {
    "number": {
      "type": "number",
      "format": "double",
      "description": "a number prop",
      "example": 2
    },
    "string": {
      "type": "string"
    }
  },
  "required": [
    "number",
    "string"
  ],
  "type": "object",
  "additionalProperties": true
}

Current Behavior

No example is generated for properties.

export interface TestInput {
    /**
     * a number prop
     * @example 2
     */
    number: number;
    string: string;
}
"TestInput": {
  "properties": {
    "number": {
      "type": "number",
      "format": "double",
      "description": "a number prop"
    },
    "string": {
      "type": "string"
    }
  },
  "required": [
    "number",
    "string"
  ],
  "type": "object",
  "additionalProperties": true
}

Context (Environment)

Version of the library: v3.x
Version of NodeJS: 12.16.1

  • Confirm you were using yarn not npm: [x]

Detailed Description

When writing complex models, it is much more ergonomic to include examples above individual properties. Additionally, the inconsistency for @example support can be confusing. This should be a fairly simple change.

Breaking change?

Not that I can tell

enhancement help wanted

Most helpful comment

I submitted a PR for this feature adding @example support for both parameters and properties

All 3 comments

I like the idea, but I'd add on that we don't support @example for parameters either, i.e.:

/**
 * @example name This is an example for name
 */
@Post('PostParamExample')
public async postParamExample(@Query() name: string): Promise<void> {
  return;
}

That seems like a pretty simple change as well. My opinion is that @example should work everywhere description does.

I submitted a PR for this feature adding @example support for both parameters and properties

Was this page helpful?
0 / 5 - 0 ratings