Skip to content

Missing responses interfaces #63

@kirkas

Description

@kirkas

I have an openapi spec for authentification with few responses types:

"/authentication": {
  "post": {
    "tags": [
      "authenticate_user"
    ],
    "operationId": "authenticate",
    "requestBody": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/Auth"
          }
        }
      },
      "required": true
    },
    "responses": {
      "200": {
        "description": "Returns current authentication state.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AuthResponse"
            }
          }
        }
      },
      "4XX": {
        "description": "",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponseObject"
            }
          }
        }
      },
      "5XX": {
        "description": "",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponseObject"
            }
          }
        }
      }
    }
  }
}

The AuthResponse & ErrorResponseObject are correctly created, but ErrorResponseObject is not used in case of 4XX or 5XX errors.

This is the generated file:

import * as runtime from '../runtime';
import type {
  Auth,
  AuthResponse,
  ErrorResponseObject,
} from '../models';
import {
    AuthFromJSON,
    AuthToJSON,
    AuthResponseFromJSON,
    AuthResponseToJSON,
    ErrorResponseObjectFromJSON,
    ErrorResponseObjectToJSON,
} from '../models';

export interface AuthenticateRequest {
    auth: Auth;
}

/**
 * 
 */
export class AuthenticateUserApi extends runtime.BaseAPI {

    /**
     */
    async authenticateRaw(requestParameters: AuthenticateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<AuthResponseErrorResponseObject>> {
        if (requestParameters.auth === null || requestParameters.auth === undefined) {
            throw new runtime.RequiredError('auth','Required parameter requestParameters.auth was null or undefined when calling authenticate.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        headerParameters['Content-Type'] = 'application/json';

        const response = await this.request({
            path: `/authentication`,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: AuthToJSON(requestParameters.auth),
        }, initOverrides);

        return new runtime.JSONApiResponse(response, (jsonValue) => AuthResponseFromJSON(jsonValue));
    }

    /**
     */
    async authenticate(requestParameters: AuthenticateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<AuthResponse> {
        const response = await this.authenticateRaw(requestParameters, initOverrides);
        return await response.value();
    }

}

As you can see ErrorResponseObject is imported but never used.

This creates multiple issues down the line. The main one is that I cannot use the ErrorResponseObject attributes to let the user know what the error actually is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions