Skip to content

feat: more capable csv consumer and producer#280

Merged
fredbi merged 1 commit intogo-openapi:masterfrom
fredbi:fix/csv
Dec 22, 2023
Merged

feat: more capable csv consumer and producer#280
fredbi merged 1 commit intogo-openapi:masterfrom
fredbi:fix/csv

Conversation

@fredbi
Copy link
Copy Markdown
Member

@fredbi fredbi commented Dec 13, 2023

This PR allows to use the CSV consumer and producer in a more versatile way. There is no breaking change to the interface.

  • fixes CSVProducer returns error 'data type must be byte array' #263 (types built with an io.Reader should be able to produce CSV)

  • csv/consumer can now consume CSV into *csv.Writer, io.Writer, io.ReaderFrom, encoding.BinaryUnmarshaler

  • also supports the new CSVWriter interface, i.e. anything that can Write([]string) error like *csv.Writer

  • also supports pointers with underlying type *[][]string, *[]byte and *string, not just *[]byte

  • csv/producer can now produce CSV from *csv.Reader, io.Reader, io.WriterTo, encoding.BinaryMarshaler

  • also supports the new CSVReader interface, i.e. anything that can Read() ([]string, error) like *csv.Reader

  • also supports underlying types [][]string, []byte and string, not just []byte

  • CSVConsumer and CSVProducer now stream CSV records whenever possible,

  • like ByteStreamConsumer and Producer, added the CSVCloseStream() option

  • added support to (optionally) configure the CSV format with CSVOpts, using the options made available by the standard library

  • doc: documented the above in the exported func signatures

  • test: added full unit test of the CSVConsumer and Producer

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (442694d) 82.27% compared to head (2825ebb) 83.75%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #280      +/-   ##
==========================================
+ Coverage   82.27%   83.75%   +1.47%     
==========================================
  Files          45       46       +1     
  Lines        3447     3687     +240     
==========================================
+ Hits         2836     3088     +252     
+ Misses        499      491       -8     
+ Partials      112      108       -4     
Flag Coverage Δ
oldstable 83.75% <100.00%> (+1.47%) ⬆️
stable 83.75% <100.00%> (+1.47%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This PR allows to use the CSV consumer and producer in a more versatile way.
There is no breaking change to the interface.

* fixes go-openapi#263 (types built with an io.Reader should be able to produce
  CSV)

* csv/consumer can now consume CSV into *csv.Writer, io.Writer, io.ReaderFrom,
  encoding.BinaryUnmarshaler
* also supports the new CSVWriter interface, i.e. anything that can
  Write([]string) error like *csv.Writer
* also supports pointers with underlying type *[][]string, *[]byte and *string, not just
  *[]byte

* csv/producer can now produce CSV from *csv.Reader, io.Reader,
  io.WriterTo, encoding.BinaryMarshaler
* also supports the new CSVReader interface, i.e. anything that can
  Read() ([]string, error) like *csv.Reader
* also supports underlying types [][]string, []byte and string, not just
  []byte

* CSVConsumer and CSVProducer now stream CSV records whenever possible,
* like ByteStreamConsumer and Producer, added the CSVCloseStream()
  option

* added support to (optionally) configure the CSV format with CSVOpts,
  using the options made available by the standard library

* doc: documented the above in the exported func signatures
* test: added full unit test of the CSVConsumer and Producer

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@fredbi
Copy link
Copy Markdown
Member Author

fredbi commented Dec 22, 2023

Thanks @youyuanwu i know this one was demanding for review…

@fredbi fredbi merged commit cc8632e into go-openapi:master Dec 22, 2023
@youyuanwu
Copy link
Copy Markdown
Member

@fredbi No problem. Thanks for making these improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSVProducer returns error 'data type must be byte array'

2 participants