client_java icon indicating copy to clipboard operation
client_java copied to clipboard

Escaping API inconsistencies

Open jonatan-ivanov opened this issue 5 months ago • 1 comments

If I understand correctly, this is approximately how I should produce an output:

expositionFormats.findWriter(accept)
    .write(System.out, registry.scrape(), EscapingScheme.fromAcceptHeader(accept));

The problem with this is that the API forces me to pass the accept header twice, so theoretically I can do this:

expositionFormats.findWriter(acceptHeaderOne)
    .write(System.out, registry.scrape(), EscapingScheme.fromAcceptHeader(acceptHeaderTwo));

Which can lead to inconsistencies, it is easy to misuse the API. I'm wondering if something like this would make sense:

expositionFormats.findWriter(accept).write(System.out, registry.scrape());

and the writer would have the EscapingScheme. The writer still can be cached but it would be a little more than today.

jonatan-ivanov avatar Sep 19 '25 03:09 jonatan-ivanov

So we'd need to add the escaping scheme to the writer - creating ExpositionFormatWriterWithEscaping.

If more users fall into this trap, then I'll consider adding this new API.

zeitlinger avatar Sep 19 '25 07:09 zeitlinger