private emitStruct()

in src/type-generator.ts [383:409]


  private emitStruct(typeName: string, structDef: JSONSchema4, structFqn: string): EmittedType {
    const toJson = new ToJsonFunction(typeName);
    const emitted: EmittedType = {
      type: typeName,
      toJson: x => `${toJson.functionName}(${x})`,
    };

    this.emitCustomType(typeName, code => {

      this.emitDescription(code, structFqn, structDef.description);
      code.openBlock(`export interface ${typeName}`);

      for (const [propName, propSpec] of Object.entries(structDef.properties || {})) {
        this.emitProperty(code, propName, propSpec, structFqn, structDef, toJson);
      }

      code.closeBlock();

      if (this.toJson) {
        toJson.emit(code);
      }

      return emitted;
    });

    return emitted;
  }