question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

override-with-generic-response shouldn't shallow copy

See original GitHub issue

Is your feature request related to a problem? Please describe :

Hi

I’m using v1.6.6 of docapi.

I’ve noticed that org.springdoc.core.GenericResponseService#getGenericMapResponse is making a shallow copy of the generic responses.

It’s bugging me while I’m trying to write a customizer :

Its purpose is to add extra examples entries to the contents of already existing 4xx and 5xx generic entries.

Those generic entries are 500 and 400 ones, automatically build by Springdoc, out of my centralized @ControllerAdvice.

Those default entries are fine to report exceptions that could occur either from :

  • 500 : the lower layers, such as database connexion troubles
  • 400 : the client side, whenever Spring received a problematic request and throw an exception before the controllers been called

But I also have domaine related exceptions, that are reported in the throw part of my controller’s signature.

Because each of those domain exceptions are coming along with a @ResponseStatus, the point of my customizer is to use their associated informations to add extra examples to those 400 and 500 entries, whenever the status code match, of course 😉

But because of the shallow copy, when my customizer add an extra example to one controller endpoint’s Content part, it’s also adding it to all other ones … 😛

Do you have a clue how to workaround this trouble ?

Describe the solution you’d like

Either :

  • have org.springdoc.core.GenericResponseService#getGenericMapResponse performing a deep copy instead of a shallow one
  • or if it’s not possible, have an access to a clone function, in order to manage this replication myself in my customizer

Describe alternatives you’ve considered

None

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
Mumeiicommented, Nov 28, 2022

Ha ! Ok, didn’t understood what HelloController was all about 😝

I’ll try to do it tonight so.

0reactions
Mumeiicommented, Dec 6, 2022

yup, the test is running fine when trying it on my side, and as long as they are no huge performance constraints associated to the GenericResponseService#getGenericMapResponse method, the objectMapper.readValue(objectMapper.writeValueAsString()) trick is nice.

Thanks for this evol !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deep copy, shallow copy, clone - java - Stack Overflow
Shallow copying generally means copying only one level of an object, ... are just some generic type, code shouldn't blindly deep-clone everything that...
Read more >
copy — Shallow and deep copy operations — Python 3.11.1 ...
A shallow copy constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in...
Read more >
#18032 (Broken copy, plot in sandpile) – Sage
I added a override for copy. I don't like the GenericGraph.__copy__ implementation, for starters its not making a copy. If you want to...
Read more >
How to differentiate between deep and shallow copies in ...
A deep copy means that all of the values of the new variable are copied and disconnected from the original variable.
Read more >
MyMediaLite: LeastSquareSLIM Class Reference
create a shallow copy of the object More. ... override float, Predict (int user_id, int item_id) ... exclude_item_id, Current item ID which shouldn't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found