static Schema schemaWithName(final Schema schema, final String schemaName) {
    if (schemaName == null || schema.type() != Schema.Type.STRUCT) {
      return schema;
    }

    final SchemaBuilder builder = SchemaBuilder.struct();

    for (final Field f : schema.fields()) {
      builder.field(f.name(), f.schema());
    }

    if (schema.parameters() != null) {
      builder.parameters(schema.parameters());
    }

    if (schema.isOptional()) {
      builder.optional();
    }

    if (schema.defaultValue() != null) {
      builder.defaultValue(schema.defaultValue());
    }

    builder.doc(schema.doc());
    builder.version(schema.version());

    return builder.name(schemaName).build();
  }
@Test
  public void shouldNameSchemaWithoutName() {
    // Given
    final Schema unnamedSchema = SchemaBuilder.struct()
        .field("field1", Schema.INT32_SCHEMA)
        .field("field2",
            SchemaBuilder.struct()
                .field("product_id", Schema.INT32_SCHEMA)
                .build())
        .build();

    // When
    final Schema schemaWithName = ProtobufSchemas.schemaWithName(unnamedSchema, CUSTOM_FULL_SCHEMA_NAME);

    // Then
    assertThat(schemaWithName, is(SchemaBuilder.struct()
        .field("field1", Schema.INT32_SCHEMA)
        .field("field2",
            SchemaBuilder.struct()
                .field("product_id", Schema.INT32_SCHEMA)
                .build())
        .name(CUSTOM_FULL_SCHEMA_NAME)
        .build()));
  }