typesense / typesense-java

Java client for Typesense
https://typesense.org/docs/latest/api/
Apache License 2.0
60 stars 29 forks source link

fix(keys): fix delete schema response #77

Open tharropoulos opened 3 weeks ago

tharropoulos commented 3 weeks ago

Change Summary

Add a new interface for response schemas after deletion, as the API only returns the id of the API key instead of the whole object.

❯ curl -k "http://localhost:8108/keys/15" \
      -X DELETE \
      -H "Content-Type: application/json" \
      -H "X-TYPESENSE-API-KEY: ${TYPESENSE-API-KEY}" \
{"id":15} // Nothing other than the id of the key

This is part of a larger problem regarding the OpenAPI spec, as according to it, the 200 response schema of a API Key DELETE request is defined as:

  /keys/{keyId}:
    delete:
      tags:
        - keys
      summary: Delete an API key given its ID.
      operationId: deleteKey
      parameters:
        - name: keyId
          in: path
          description: The ID of the key to delete
          required: true
          schema:
            type: integer
            format: int64
      responses:
        200:
          description: The key referenced by the ID
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiKey"

Where the ApiKey schema is defined as:

    ApiKeySchema:
      type: object
      required:
        - actions
        - collections
        - description
      properties:
        value:
          type: string
        description:
          type: string
        actions:
          type: array
          items:
            type: string
        collections:
          type: array
          items:
            type: string
        expires_at:
          type: integer
          format: int64
    ApiKey:
      allOf:
        - $ref: "#/components/schemas/ApiKeySchema"
        - type: object
          properties:
            id:
              type: integer
              format: int64
              readOnly: true
            value_prefix:
              type: string
              readOnly: true

PR Checklist