Skip to content

'openapi-request-validator' componentSchemas should be an object#914

Open
jckr wants to merge 1 commit intokogosoftwarellc:mainfrom
jckr:openapi-request-validator-component-schemas-should-be-an-object
Open

'openapi-request-validator' componentSchemas should be an object#914
jckr wants to merge 1 commit intokogosoftwarellc:mainfrom
jckr:openapi-request-validator-component-schemas-should-be-an-object

Conversation

@jckr
Copy link

@jckr jckr commented Nov 14, 2024

the problem

currently, the interface of the OpenAPIRequestValidator has componentSchemas as an array of IJsonSchema.

export interface OpenAPIRequestValidatorArgs {
  customFormats?: {
    [formatName: string]: Format | FormatDefinition<string | number>;
  };
  customKeywords?: {
    [keywordName: string]: KeywordDefinition;
  };
  externalSchemas?: {
    [index: string]: IJsonSchema;
  };
  loggingKey?: string;
  logger?: Logger;
  parameters?: OpenAPI.Parameters;
  requestBody?: OpenAPIV3.RequestBodyObject;
  schemas?: IJsonSchema[];
  componentSchemas?: IJsonSchema[];
  errorTransformer?(
    openAPIResponseValidatorValidationError: OpenAPIRequestValidatorError,
    ajvError: ErrorObject
  ): any;
  ajvOptions?: Options;
  enableHeadersLowercase?: boolean;
  additionalQueryProperties?: boolean;
}

but this is incorrect, in the code we rely on the fact that componentsSchema is an object:

 Object.keys(args.componentSchemas).forEach((id) => {

with the current implementation, we will have typecheck errors whenever we try to use openapi-request-validator in TS with componentSchemas.

the solution

just a one line change to update that interface.
tests still pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant