private typeForRef()

in src/type-generator.ts [512:532]


  private typeForRef(def: JSONSchema4): EmittedType {
    const prefix = '#/definitions/';
    if (!def.$ref || !def.$ref.startsWith(prefix)) {
      throw new Error(`invalid $ref ${JSON.stringify(def)}`);
    }

    if (this.isExcluded(def.$ref)) {
      return { type: 'any', toJson: x => x };
    }

    const typeName = TypeGenerator.normalizeTypeName(this.renderTypeName(def.$ref.substring(prefix.length)));

    // if we already emitted a type with this type name, just return it
    const emitted = this.emittedTypes[typeName];
    if (emitted) {
      return emitted;
    }

    const schema = this.resolveReference(def);
    return this.emitTypeInternal(typeName, schema, def.$ref);
  }