<commit_before>import { Inject, Injectable } from '@ts-stack/di';
import { edk } from '@ditsmod/core';
import { ReferenceObject, XParameterObject } from '@ts-stack/openapi-spec';

import { OasModuleWithParams } from '../types/oas-modul-with-params';
import { isReferenceObject } from '../utils/type-guards';
import { getLastParameterObjects, getLastReferenceObjects } from '../utils/get-last-params';

@Injectable()
export class OpenapiPatchMetadataExtension implements edk.Extension<void> {
  protected inited: boolean;

  constructor(@Inject(edk.APP_METADATA_MAP) protected appMetadataMap: edk.AppMetadataMap) {}

  async init() {
    if (this.inited) {
      return;
    }

    this.appMetadataMap.forEach((metadataPerMod) => {
      const { moduleMetadata } = metadataPerMod;
      this.setPrefixParams(moduleMetadata);
    });

    this.inited = true;
  }

  protected setPrefixParams(moduleMetadata: edk.NormalizedModuleMetadata) {
    if (edk.isModuleWithParams(moduleMetadata.module)) {
      const { prefixParams } = moduleMetadata.module as OasModuleWithParams;
      if (prefixParams?.length) {
        let imp: OasModuleWithParams;
        for (imp of moduleMetadata.importsWithParams) {
          imp.prefixParams = this.getUniqParams([...prefixParams, ...(imp.prefixParams || [])]);
        }
      }
    }
  }

  protected getUniqParams(prefixParams: (XParameterObject<any> | ReferenceObject)[]) {
    const referenceObjects: ReferenceObject[] = [];
    const parametersObjets: XParameterObject[] = [];
    for (const param of prefixParams) {
      if (isReferenceObject(param)) {<commit_msg>refactor(openapi): added recursive call for setPrefixParams()<commit_after>import { Inject, Injectable } from '@ts-stack/di';
import { edk } from '@ditsmod/core';
import { ReferenceObject, XParameterObject } from '@ts-stack/openapi-spec';

import { OasModuleWithParams } from '../types/oas-modul-with-params';
import { isReferenceObject } from '../utils/type-guards';
import { getLastParameterObjects, getLastReferenceObjects } from '../utils/get-last-params';

@Injectable()
export class OpenapiPatchMetadataExtension implements edk.Extension<void> {
  protected inited: boolean;

  constructor(
    protected moduleManager: edk.ModuleManager,
    @Inject(edk.APP_METADATA_MAP) protected appMetadataMap: edk.AppMetadataMap
  ) {}

  async init() {
    if (this.inited) {
      return;
    }

    this.appMetadataMap.forEach((metadataPerMod) => {
      const { moduleMetadata } = metadataPerMod;
      this.setPrefixParams(moduleMetadata);
    });

    this.inited = true;
  }

  protected setPrefixParams(moduleMetadata: edk.NormalizedModuleMetadata) {
    if (edk.isModuleWithParams(moduleMetadata.module)) {
      const { prefixParams } = moduleMetadata.module as OasModuleWithParams;
      if (prefixParams?.length) {
        let imp: OasModuleWithParams;
        for (imp of moduleMetadata.importsWithParams) {
          imp.prefixParams = this.getUniqParams([...prefixParams, ...(imp.prefixParams || [])]);
          const meta = this.moduleManager.getMetadata(imp);
          this.setPrefixParams(meta);
        }
      }
    }
  }

  protected getUniqParams(prefixParams: (XParameterObject<any> | ReferenceObject)[]) {
    const referenceObjects: ReferenceObject[] = [];
    const parametersObjets: XParameterObject[] = [];
    for (const param of prefixParams) {
      if (isReferenceObject(param)) {
{'fraction_non_alphanumeric': 0.12295081967213115, 'fraction_numerical': 0.0, 'mean_word_length': 3.9236311239193085, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5452083', 'n_tokens_mistral': 997, 'n_tokens_neox': 983, 'n_words': 195}