kubb-labs / kubb

The ultimate toolkit for working with APIs.
https://kubb.dev
MIT License
679 stars 57 forks source link

ESLint `no-unused-vars` for mocks of 204 (No content) responses #917

Closed antipopp closed 6 months ago

antipopp commented 6 months ago

What version of kubb is running?

2.12.3

What platform is your computer?

Linux

What version of external packages are you using(@tanstack-query, MSW, React, Vue, ...)

No response

What steps can reproduce the bug?

Generate a schema that has a 204 response.

The mocks will fail ESLint validation as these snippets

/**
 * @description No content
 */
export function createAddPet204(
  override?: NonNullable<Partial<AddPet204>>,
): NonNullable<AddPet204> {
  return undefined;
}

will trigger a 'override' is defined but never used.eslint[@typescript-eslint/no-unused-vars](https://typescript-eslint.io/rules/no-unused-vars) error

How often does this bug happen?

None

What is the expected behavior?

Such functions should omit the override prop

Swagger/OpenAPI file?

openapi: 3.0.3
info:
  title: Swagger Petstore - OpenAPI 3.0
  description: |-
    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
    Swagger at [https://swagger.io](https://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
    You can now help us improve the API whether it's by making changes to the definition itself or to the code.
    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.

    Some useful links:
    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)

  termsOfService: http://swagger.io/terms/
  contact:
    email: apiteam@swagger.io
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.0.11
externalDocs:
  description: Find out more about Swagger
  url: http://swagger.io
servers:
  - url: https://petstore3.swagger.io/api/v3
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: http://swagger.io
  - name: store
    description: Access to Petstore orders
    externalDocs:
      description: Find out more about our store
      url: http://swagger.io
  - name: user
    description: Operations about user
paths:
  /pet:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: Add a new pet to the store
      operationId: addPet
      requestBody:
        description: Create a new pet in the store
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
        required: true
      responses:
        '204':
          description: No content
components:
  schemas:
    Pet:
      required:
        - name
        - photoUrls
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
        photoUrls:
          type: array
          xml:
            wrapped: true
          items:
            type: string
            xml:
              name: photoUrl
        status:
          type: string
          description: pet status in the store
          enum:
            - available
            - pending
            - sold

Additional information

No response

stijnvanhulle commented 6 months ago

Fixed with version 2.12.4