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

How to document optional attributes with buildTemplatedApiExceptionDecorator? #17

Closed
lzkill opened this issue Apr 20, 2021 · 10 comments · Fixed by #18
Closed

How to document optional attributes with buildTemplatedApiExceptionDecorator? #17

lzkill opened this issue Apr 20, 2021 · 10 comments · Fixed by #18
Assignees
Labels
enhancement New feature or request

Comments

@lzkill
Copy link

lzkill commented Apr 20, 2021

I have this template decorator:

import { buildTemplatedApiExceptionDecorator } from '@nanogiants/nestjs-swagger-api-exception-decorator';

export const TemplatedApiException = buildTemplatedApiExceptionDecorator({
  statusCode: '$status',
  clientCode: 'number',
  message: '$description',
  errors: [
    {
      string: 'string',
    },
  ],
  path: 'string',
  timestamp: '1970-01-01T15:30:11',
});

It matches my exception filter custom json. But some attributes are optional. Hoe can I document this on Swagger?

@jsproede
Copy link
Contributor

Hi @lzkill, with the @TemplatedApiException decorator currently it is not possible to mark attributes as optional.

What do you think about an optional array which can contain the required attributes? For example:

export const TemplatedApiException = buildTemplatedApiExceptionDecorator({
  statusCode: '$status',
  clientCode: 'number',
  message: '$description',
  errors: [
    {
      string: 'string',
    },
  ],
  path: 'string',
  timestamp: '1970-01-01T15:30:11',
}, ['statusCode', 'message', 'timestamp']);

@jsproede jsproede self-assigned this Apr 21, 2021
@jsproede jsproede added the enhancement New feature or request label Apr 21, 2021
@lzkill
Copy link
Author

lzkill commented Apr 21, 2021

Hi my friend. I guess this array would pretty much fit my needs. Without this the api consumer is not aware until the first errors start to return.

@jsproede
Copy link
Contributor

Hi @lzkill,

we've extended the Options interface with requiredProperties. For example:

export const TemplatedApiException = buildTemplatedApiExceptionDecorator(
  {
    statusCode: '$status',
    clientCode: 'number',
    message: '$description',
    errors: [
      {
        string: 'string',
      },
    ],
    path: 'string',
    timestamp: '1970-01-01T15:30:11',
  },
  { requiredProperties: ['statusCode', 'message', 'timestamp'] },
);

We'll release a new version (v1.3.0) soon :)

@lzkill
Copy link
Author

lzkill commented Apr 21, 2021

Thank you again, my friend!

@jsproede jsproede linked a pull request Apr 21, 2021 that will close this issue
@lzkill
Copy link
Author

lzkill commented Apr 21, 2021

@jsproede What do you think about having a similar array for custom placeholders?

@jsproede
Copy link
Contributor

@lzkill Do you have an example? :)

@jsproede jsproede reopened this Apr 21, 2021
@lzkill
Copy link
Author

lzkill commented Apr 21, 2021

Something like this:

export const TemplatedApiException = buildTemplatedApiExceptionDecorator(
  {
    statusCode: '$status',
    clientCode: '$clientCode',
    message: '$description',
    errors: [
      {
        string: 'string',
      },
    ],
    path: 'string',
    timestamp: '1970-01-01T15:30:11',
  },
  {
    requiredProperties: ['statusCode', 'message', 'timestamp'],
    placeholders: {
       'clientCode': (e) => { (e as BaseException).getClientCode(); }
    }
  },
);

(I'm sorry for my poor typescript)

@jsproede
Copy link
Contributor

@lzkill Great idea! I've moved your suggestion regarding custom placeholders into a new issue :)

@jsproede
Copy link
Contributor

Hi @lzkill, I just wanted to notify you, that a new version including the requiredProperties property has been released :) The new release also includes custom placeholders. We described the new properties in our documentation.

@lzkill
Copy link
Author

lzkill commented Apr 30, 2021

Hi my friend. I was already using your first commit. :)

Thank you very much for your superb work!

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

Successfully merging a pull request may close this issue.

2 participants