Skip to content

Commit

Permalink
fix(codecs) csv documentation defaults as ascii_char (#20498)
Browse files Browse the repository at this point in the history
* set type_override for ascii_char

* specially handle "docs::type_override" with "ascii_char" in generate-component-docs.rb

* add missing filds in csv.rs and coresponsing cue docs as well as short comment in generate-component-docs.rb

* fix spelling
  • Loading branch information
scMarkus authored Jul 17, 2024
1 parent 7916ad5 commit 5a10aa2
Show file tree
Hide file tree
Showing 30 changed files with 99 additions and 82 deletions.
4 changes: 4 additions & 0 deletions changelog.d/18669_csv_documentation_u8_display.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fixing the representation of the ascii character configuration in the csv encoder documentation so
that they are shown as human readable characters contrary to integers.

author scMarkus
3 changes: 3 additions & 0 deletions lib/codecs/src/encoding/format/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl CsvSerializerConfig {
#[derive(Debug, Clone)]
pub struct CsvSerializerOptions {
/// The field delimiter to use when writing CSV.
#[configurable(metadata(docs::type_override = "ascii_char"))]
#[serde(
default = "default_delimiter",
with = "vector_core::serde::ascii_char",
Expand All @@ -98,6 +99,7 @@ pub struct CsvSerializerOptions {
/// like \ (instead of escaping quotes by doubling them).
///
/// To use this, `double_quotes` needs to be disabled as well otherwise it is ignored.
#[configurable(metadata(docs::type_override = "ascii_char"))]
#[serde(
default = "default_escape",
with = "vector_core::serde::ascii_char",
Expand All @@ -106,6 +108,7 @@ pub struct CsvSerializerOptions {
pub escape: u8,

/// The quote character to use when writing CSV.
#[configurable(metadata(docs::type_override = "ascii_char"))]
#[serde(
default = "default_escape",
with = "vector_core::serde::ascii_char",
Expand Down
12 changes: 11 additions & 1 deletion scripts/generate-component-docs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,19 @@ def resolve_schema(root_schema, schema)
#
# We intentially set no actual definition for these types, relying on the documentation generation
# process to provide the actual details. We only need to specify the custom type name.
#
# To handle u8 types as ascii characters and not there uint representation between 0 and 255 we
# added a special handling of these exact values. This means
# `#[configurable(metadata(docs::type_override = "ascii_char"))]` should only be used consciously
# for rust u8 type. See lib/codecs/src/encoding/format/csv.rs for an example and
# https://github.com/vectordotdev/vector/pull/20498
type_override = get_schema_metadata(schema, 'docs::type_override')
if !type_override.nil?
resolved = { 'type' => { type_override.to_s => {} } }
if type_override == 'ascii_char'
resolved = { 'type' => { type_override.to_s => { 'default' => schema['default'].chr } } }
else
resolved = { 'type' => { type_override.to_s => {} } }
end
description = get_rendered_description_from_schema(schema)
resolved['description'] = description unless description.empty?
return resolved
Expand Down
6 changes: 3 additions & 3 deletions website/cue/reference/components/sinks/base/amqp.cue
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ base: components: sinks: amqp: configuration: {
delimiter: {
description: "The field delimiter to use when writing CSV."
required: false
type: uint: default: 44
type: ascii_char: default: ","
}
double_quote: {
description: """
Expand All @@ -179,7 +179,7 @@ base: components: sinks: amqp: configuration: {
To use this, `double_quotes` needs to be disabled as well otherwise it is ignored.
"""
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
fields: {
description: """
Expand All @@ -197,7 +197,7 @@ base: components: sinks: amqp: configuration: {
quote: {
description: "The quote character to use when writing CSV."
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
quote_style: {
description: "The quoting style to use when writing CSV data."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ base: components: sinks: aws_cloudwatch_logs: configuration: {
delimiter: {
description: "The field delimiter to use when writing CSV."
required: false
type: uint: default: 44
type: ascii_char: default: ","
}
double_quote: {
description: """
Expand All @@ -355,7 +355,7 @@ base: components: sinks: aws_cloudwatch_logs: configuration: {
To use this, `double_quotes` needs to be disabled as well otherwise it is ignored.
"""
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
fields: {
description: """
Expand All @@ -373,7 +373,7 @@ base: components: sinks: aws_cloudwatch_logs: configuration: {
quote: {
description: "The quote character to use when writing CSV."
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
quote_style: {
description: "The quoting style to use when writing CSV data."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ base: components: sinks: aws_kinesis_firehose: configuration: {
delimiter: {
description: "The field delimiter to use when writing CSV."
required: false
type: uint: default: 44
type: ascii_char: default: ","
}
double_quote: {
description: """
Expand All @@ -334,7 +334,7 @@ base: components: sinks: aws_kinesis_firehose: configuration: {
To use this, `double_quotes` needs to be disabled as well otherwise it is ignored.
"""
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
fields: {
description: """
Expand All @@ -352,7 +352,7 @@ base: components: sinks: aws_kinesis_firehose: configuration: {
quote: {
description: "The quote character to use when writing CSV."
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
quote_style: {
description: "The quoting style to use when writing CSV data."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ base: components: sinks: aws_kinesis_streams: configuration: {
delimiter: {
description: "The field delimiter to use when writing CSV."
required: false
type: uint: default: 44
type: ascii_char: default: ","
}
double_quote: {
description: """
Expand All @@ -334,7 +334,7 @@ base: components: sinks: aws_kinesis_streams: configuration: {
To use this, `double_quotes` needs to be disabled as well otherwise it is ignored.
"""
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
fields: {
description: """
Expand All @@ -352,7 +352,7 @@ base: components: sinks: aws_kinesis_streams: configuration: {
quote: {
description: "The quote character to use when writing CSV."
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
quote_style: {
description: "The quoting style to use when writing CSV data."
Expand Down
6 changes: 3 additions & 3 deletions website/cue/reference/components/sinks/base/aws_s3.cue
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ base: components: sinks: aws_s3: configuration: {
delimiter: {
description: "The field delimiter to use when writing CSV."
required: false
type: uint: default: 44
type: ascii_char: default: ","
}
double_quote: {
description: """
Expand All @@ -443,7 +443,7 @@ base: components: sinks: aws_s3: configuration: {
To use this, `double_quotes` needs to be disabled as well otherwise it is ignored.
"""
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
fields: {
description: """
Expand All @@ -461,7 +461,7 @@ base: components: sinks: aws_s3: configuration: {
quote: {
description: "The quote character to use when writing CSV."
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
quote_style: {
description: "The quoting style to use when writing CSV data."
Expand Down
6 changes: 3 additions & 3 deletions website/cue/reference/components/sinks/base/aws_sns.cue
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ base: components: sinks: aws_sns: configuration: {
delimiter: {
description: "The field delimiter to use when writing CSV."
required: false
type: uint: default: 44
type: ascii_char: default: ","
}
double_quote: {
description: """
Expand All @@ -265,7 +265,7 @@ base: components: sinks: aws_sns: configuration: {
To use this, `double_quotes` needs to be disabled as well otherwise it is ignored.
"""
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
fields: {
description: """
Expand All @@ -283,7 +283,7 @@ base: components: sinks: aws_sns: configuration: {
quote: {
description: "The quote character to use when writing CSV."
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
quote_style: {
description: "The quoting style to use when writing CSV data."
Expand Down
6 changes: 3 additions & 3 deletions website/cue/reference/components/sinks/base/aws_sqs.cue
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ base: components: sinks: aws_sqs: configuration: {
delimiter: {
description: "The field delimiter to use when writing CSV."
required: false
type: uint: default: 44
type: ascii_char: default: ","
}
double_quote: {
description: """
Expand All @@ -265,7 +265,7 @@ base: components: sinks: aws_sqs: configuration: {
To use this, `double_quotes` needs to be disabled as well otherwise it is ignored.
"""
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
fields: {
description: """
Expand All @@ -283,7 +283,7 @@ base: components: sinks: aws_sqs: configuration: {
quote: {
description: "The quote character to use when writing CSV."
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
quote_style: {
description: "The quoting style to use when writing CSV data."
Expand Down
6 changes: 3 additions & 3 deletions website/cue/reference/components/sinks/base/azure_blob.cue
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ base: components: sinks: azure_blob: configuration: {
delimiter: {
description: "The field delimiter to use when writing CSV."
required: false
type: uint: default: 44
type: ascii_char: default: ","
}
double_quote: {
description: """
Expand All @@ -297,7 +297,7 @@ base: components: sinks: azure_blob: configuration: {
To use this, `double_quotes` needs to be disabled as well otherwise it is ignored.
"""
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
fields: {
description: """
Expand All @@ -315,7 +315,7 @@ base: components: sinks: azure_blob: configuration: {
quote: {
description: "The quote character to use when writing CSV."
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
quote_style: {
description: "The quoting style to use when writing CSV data."
Expand Down
6 changes: 3 additions & 3 deletions website/cue/reference/components/sinks/base/console.cue
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ base: components: sinks: console: configuration: {
delimiter: {
description: "The field delimiter to use when writing CSV."
required: false
type: uint: default: 44
type: ascii_char: default: ","
}
double_quote: {
description: """
Expand All @@ -163,7 +163,7 @@ base: components: sinks: console: configuration: {
To use this, `double_quotes` needs to be disabled as well otherwise it is ignored.
"""
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
fields: {
description: """
Expand All @@ -181,7 +181,7 @@ base: components: sinks: console: configuration: {
quote: {
description: "The quote character to use when writing CSV."
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
quote_style: {
description: "The quoting style to use when writing CSV data."
Expand Down
6 changes: 3 additions & 3 deletions website/cue/reference/components/sinks/base/databend.cue
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ base: components: sinks: databend: configuration: {
delimiter: {
description: "The field delimiter to use when writing CSV."
required: false
type: uint: default: 44
type: ascii_char: default: ","
}
double_quote: {
description: """
Expand All @@ -182,7 +182,7 @@ base: components: sinks: databend: configuration: {
To use this, `double_quotes` needs to be disabled as well otherwise it is ignored.
"""
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
fields: {
description: """
Expand All @@ -200,7 +200,7 @@ base: components: sinks: databend: configuration: {
quote: {
description: "The quote character to use when writing CSV."
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
quote_style: {
description: "The quoting style to use when writing CSV data."
Expand Down
6 changes: 3 additions & 3 deletions website/cue/reference/components/sinks/base/file.cue
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ base: components: sinks: file: configuration: {
delimiter: {
description: "The field delimiter to use when writing CSV."
required: false
type: uint: default: 44
type: ascii_char: default: ","
}
double_quote: {
description: """
Expand All @@ -183,7 +183,7 @@ base: components: sinks: file: configuration: {
To use this, `double_quotes` needs to be disabled as well otherwise it is ignored.
"""
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
fields: {
description: """
Expand All @@ -201,7 +201,7 @@ base: components: sinks: file: configuration: {
quote: {
description: "The quote character to use when writing CSV."
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
quote_style: {
description: "The quoting style to use when writing CSV data."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ base: components: sinks: gcp_chronicle_unstructured: configuration: {
delimiter: {
description: "The field delimiter to use when writing CSV."
required: false
type: uint: default: 44
type: ascii_char: default: ","
}
double_quote: {
description: """
Expand All @@ -232,7 +232,7 @@ base: components: sinks: gcp_chronicle_unstructured: configuration: {
To use this, `double_quotes` needs to be disabled as well otherwise it is ignored.
"""
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
fields: {
description: """
Expand All @@ -250,7 +250,7 @@ base: components: sinks: gcp_chronicle_unstructured: configuration: {
quote: {
description: "The quote character to use when writing CSV."
required: false
type: uint: default: 34
type: ascii_char: default: "\""
}
quote_style: {
description: "The quoting style to use when writing CSV data."
Expand Down
Loading

0 comments on commit 5a10aa2

Please sign in to comment.