function exampleValueForStruct()

in src/generate.ts [334:361]


function exampleValueForStruct(context: ExampleContext, struct: reflect.InterfaceType, level: number): Code {
  if (struct.allProperties.length === 0) {
    return new Code('{ }');
  }

  const properties = [...struct.allProperties]; // Make a copy that we can sort
  sortBy(properties, (p) => [p.optional ? 1 : 0, p.name]);

  const renderedProperties = properties.map((p) =>
    Code.concatAll(
      `${tab(level + 1)}${p.name}: `,
      exampleValue(context, p.type, p.name, level + 1),
      ',\n',
    ),
  );

  // Add an empty line between required and optional properties
  for (let i = 0; i < properties.length - 1; i++) {
    if (properties[i].optional !== properties[i + 1].optional) {
      renderedProperties.splice(i + 1, 0, new Code(`\n${tab(level+1)}// the properties below are optional\n`));
      break;
    }
  }

  return Code.concatAll(
    '{\n',
    ...renderedProperties,
    `${tab(level)}}`,