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

Example response attributes with negative values are omitted from swagger.json file #1289

Closed
2 of 4 tasks
thecampbells384 opened this issue Jul 26, 2022 · 1 comment · Fixed by #1319
Closed
2 of 4 tasks

Comments

@thecampbells384
Copy link

thecampbells384 commented Jul 26, 2022

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

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

Expected Behavior

When generating a response example, any attributes with a negative number should be included in the generated openapi spec.
Example code:

  interface User {

    id: number;
    email: string;
    name: string;
    status?: "Happy" | "Sad";
    phoneNumbers: string[];
  }
  
  @Route("users")
  export class UsersController extends Controller {
    @Example<User>({
      id: -1,
      email: "[email protected]",
      name: "Jimmy",
      phoneNumbers: ["778-234-5678"]
    })
    @Get("{userId}")
    public async getUser(
      @Path() userId: number,
      @Query() name?: string
    ): Promise<User> {
      return new UsersService().get(userId, name);
    }

should produce a swagger doc containing:

"responses": {
   				"200": {
   					"description": "Ok",
   					"content": {
   						"application/json": {
   							"schema": {
   								"$ref": "#/components/schemas/User"
   							},
   							"examples": {
   								"Example 1": {
   									"value": {
   										"id": -1,
   										"email": "[email protected]",
   										"name": "Jimmy",
   										"phoneNumbers": [
   											"778-234-5678"
   										]
   
 }

Current Behavior

Instead, the attribute with a negative number is not included in the openapi spec. The example code above produces:

"responses": {
					"200": {
						"description": "Ok",
						"content": {
							"application/json": {
								"schema": {
									"$ref": "#/components/schemas/User"
								},
								"examples": {
									"Example 1": {
										"value": {
											"email": "[email protected]",
											"name": "Jimmy",
											"phoneNumbers": [
												"778-234-5678"
											]

Context (Environment)

Version of the library: 4.1.0
Version of NodeJS: 16.15.1

@github-actions
Copy link

Hello there thecampbells384 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

@github-actions github-actions bot added the Stale label Aug 26, 2022
Repository owner deleted a comment from github-actions bot Aug 31, 2022
jackey8616 added a commit to jackey8616/tsoa that referenced this issue Oct 6, 2022
Add both plus(+) and minus(-) operator @ ExampleDecorator.
Apply to both spec2 & 3 test cases.
jackey8616 added a commit to jackey8616/tsoa that referenced this issue Oct 6, 2022
Add both plus(+) and minus(-) operator @ ExampleDecorator.
Apply to both spec2 & 3 test cases.
jackey8616 added a commit to jackey8616/tsoa that referenced this issue Oct 6, 2022
Add minus(-) and plus(+) operator detection @ getInitializerValue when
metadataGenerating.
jackey8616 added a commit to jackey8616/tsoa that referenced this issue Oct 6, 2022
Add both plus(+) and minus(-) operator @ ExampleDecorator.
Apply to both spec2 & 3 test cases.
jackey8616 added a commit to jackey8616/tsoa that referenced this issue Oct 6, 2022
Add minus(-) and plus(+) operator detection @ getInitializerValue when
metadataGenerating.
@WoH WoH closed this as completed in #1319 Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants