thiagobustamante / typescript-rest-swagger

Swagger tools for typescript-rest
156 stars 57 forks source link

Using @Secuirty Decorator for controller class with more than one method fails to generate swagger docs #141

Open r0610205 opened 3 years ago

r0610205 commented 3 years ago

When using controller.secuirty vs method.security the value should cloned rather than copied. If @Secuirty decorator defined as @Security('*', 'basic') then produced value will be ['*'] - Array, which in case of multiple methods will reference the same internal object.

Without cloning the value, underlying swagger2openapi library fails with S2OError: YAML anchor or merge key.

https://github.com/thiagobustamante/typescript-rest-swagger/blob/a0dd006e003a3f1ae256db87f33c6d2dadc3cb63/src/swagger/generator.ts#L139

Proposed fix:

 method.security = method.security || (controller.security ? JSON.parse(JSON.stringify(controller.security)) : controller.security);