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

ValidateError does not produce valid swagger.json #1500

Closed
2 of 4 tasks
leherv opened this issue Oct 25, 2023 · 3 comments
Closed
2 of 4 tasks

ValidateError does not produce valid swagger.json #1500

leherv opened this issue Oct 25, 2023 · 3 comments
Labels

Comments

@leherv
Copy link

leherv commented Oct 25, 2023

Like you describe in your docs (https://tsoa-community.github.io/docs/error-handling.html) one can return the FieldErrors type directly if a ValidateError occurs. In my API I use those FieldErrors to create an ErrorResponse type which looks like this:

export type ErrorResponse = {
  code: ErrorCode;
  message: string;
  details?: ErrorDetails;
};

export type ErrorDetails = {
  [name: string]: {
    message: string;
    value?: any;
  };
};

export const enum ErrorCode {
  generalError = "general.error",
  validationError = "validation.error",
}

As you can see ErrorDetails matches the FieldErrors. I then annotate a controller method with this response type in the case an error occurred

@response(400, "Request validation failed.")

If I then look at the generated swagger.json output it looks like this for the ErrorResponse type:

ErrorCode:
      enum:
        - general.error
        - validation.error
      type: string
    ErrorDetails:
      properties: {}
      additionalProperties:
        properties:
          value: {}
          message:
            type: string
        required:
          - message
        type: object
      type: object
    ErrorResponse:
      properties:
        details:
          $ref: '#/components/schemas/ErrorDetails'
        message:
          type: string
        code:
          $ref: '#/components/schemas/ErrorCode'
      required:
        - message
        - code
      type: object

A generated client (swagger editor) typescript-axios generates this ErrorDetails type for the ErrorResponse:

export interface ErrorDetails extends null<String, any> {
}

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

I would expect that I can use ErrorFields as a valid response, as it is also included in the docs.

Current Behavior

Currently as already mentioned this does not generate a valid client.

Possible Solution

As a workaround I tried mapping the ErrorFields to a Map<string, X> but quickly found out that there is an open issue with Maps.

@github-actions
Copy link

Hello there leherv 👋

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

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

@leherv
Copy link
Author

leherv commented Oct 30, 2023

Hello again,

it seems the problem could be related to this: swagger-api/swagger-codegen#11901.
Maybe you still have a hint or advice on how I can get this to work.

Best regards

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant