Skip to content

Support custom swagger components in PaginatedSwaggerDocs #1101

@dariozachow

Description

@dariozachow

I was trying to return a oneOf schema as a paginated Entity, but unfortunately it's is not possible to pass a custom schema or model by string into @PaginatedSwaggerDocs. So I had to create a CustomType manually for that and reference it by string with an type-ignore.

Example:

CustomType defined in the swagger:

    CustomType:
      oneOf:
        - $ref: '#/components/schemas/Case1'
        - $ref: '#/components/schemas/Case2'
        - $ref: '#/components/schemas/Case3'
      discriminator:
        propertyName: type
        mapping:
          a: '#/components/schemas/Case1'
          b: '#/components/schemas/Case2'
          c: '#/components/schemas/Case3'
          d: '#/components/schemas/Case3'

Trying to use this @PaginatedSwaggerDocs('CustomType', paginationConfig) shows a type error because string is not assignable to DTO.
But when ignoring the typecheck the build of the swagger is successful anyway, because getSchemaPath accepts a string, for referencing a schema.

So either allowing string as a parameter in the @PaginatedSwaggerDocs or allowing CustomSchemas by passing something like:

@PaginatedSwaggerDocs({ schema: {
        CustomType: {
          oneOf: [
            {
              $ref: getSchemaPath(Case1)
            },
            {
              $ref: getSchemaPath(Case2)
            },
            {
              $ref: getSchemaPath(Case3)
            }
          ],
          discriminator: {
            propertyName: 'type',
            mapping: {
              a: getSchemaPath(Case1),
              b getSchemaPath(Case2),
              c: getSchemaPath(Case3),
              d: getSchemaPath(Case3)
            }
          }
        }
      }
}, paginationConfig)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions