Skip to content

Allow multiple RequestEditorFns in Client and Request Methods#228

Merged
deepmap-marcinr merged 4 commits intooapi-codegen:masterfrom
curvegrid:multiple-editors
Jan 30, 2021
Merged

Allow multiple RequestEditorFns in Client and Request Methods#228
deepmap-marcinr merged 4 commits intooapi-codegen:masterfrom
curvegrid:multiple-editors

Conversation

@natsukagami
Copy link
Copy Markdown
Contributor

@natsukagami natsukagami commented Sep 9, 2020

I usually find myself having to combine multiple editors into one, or change the client in order to customize a request with e.g. special headers.

This changes that with

  • Allowing multiple RequestEditorFns in the Client, with each WithRequestEditorFn call appending one to the list.
  • Allowing RequestEditorFns as a (spread) parameter in every Client method. They are run after the default ones.

This change is Reviewable

@mitar
Copy link
Copy Markdown
Contributor

mitar commented Jan 28, 2021

This would be super useful. I just now have to complicate my code because I want to use different access tokens for some requests. With this PR I could just pass RequestEditorFn to the call itself. Super useful.

@dahu33
Copy link
Copy Markdown
Contributor

dahu33 commented Jan 29, 2021

@deepmap-marcinr any chance we could get this in? It's a non-breaking change and it's been proven useful.

// A list of callbacks for modifying requests which are generated before sending over
// the network.
RequestEditor RequestEditorFn
RequestEditors []RequestEditorFn
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change. Anyone accessing the previous RequestEditor will get a compile error now.

We don't need a list of RequestEditors on the client, could you leave it as a single RequestEditor?

Your per-handler request editors supercede this global per-client editor.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a list of RequestEditors on the client, could you leave it as a single RequestEditor?

But how would then one register multiple RequestEditors with a client?

I mean, modifying RequestEditors directly should be a bad pattern anyway, no? You have to modify it through constructor options.

But if this is really the problem, we could have RequestEditor and RequestEditors, where first the RequestEditor is run an then new RequestEditors in order.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the breakage from this will be minimal, I will merge as-is.

The reason that I originally had a single request editor is that you yourself can call a bunch from within it, so it seemed redundant.

Your code never uses that editor array on the client, as you use the list specified on the handler, and only of present, do you append. So, the change from 1 to many doesn't really gain much.

@deepmap-marcinr
Copy link
Copy Markdown
Contributor

deepmap-marcinr commented Jan 29, 2021 via email

@deepmap-marcinr deepmap-marcinr merged commit 0ac4dee into oapi-codegen:master Jan 30, 2021
@falzm falzm mentioned this pull request Feb 18, 2021
adrianpk pushed a commit to foorester/oapi-codegen that referenced this pull request Jan 16, 2024
…odegen#228)

* Allow multiple RequestEditorFns and custom ones

* Re-generate templates

* Fix tests

* Update README
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.

4 participants