Coder Social home page Coder Social logo

Comments (7)

miraclx avatar miraclx commented on June 11, 2024

Was just about to submit a ticket for this. This is really relevant. We can probably come up with a different key discriminant than the type name here:

if !self.definitions.contains_key(&name) {
self.insert_new_subschema_for::<T>(name);
}

Perhaps a Hash of std::any::TypeId?

from schemars.

ewoolsey avatar ewoolsey commented on June 11, 2024

Commenting here to mention that I have also run into this problem. Would love to see a fix for this, Should be fairly straightforward I imagine.

from schemars.

miraclx avatar miraclx commented on June 11, 2024

Hi @ewoolsey, #178 is a potential fix. Although, as highlighted in there, I believe a different approach should be considered. An approach that, in-turn, won't be a simple fix.

from schemars.

ewoolsey avatar ewoolsey commented on June 11, 2024

Hi @ewoolsey, #178 is a potential fix. Although, as highlighted in there, I believe a different approach should be considered. An approach that, in-turn, won't be a simple fix.

Haha things are never as straightforward as they first seem. @miraclx any Idea when we can expect either of these solutions to be implemented? I'm working on an interactive parser built on top of schemers and serde to generate complex types from user input. Using it to build some cool development tools. Should I proceed with a workaround or wait it out?

from schemars.

miraclx avatar miraclx commented on June 11, 2024

@ewoolsey, depending on your use case, #178 should suffice for schema generation.

For schema consumption, however, clients have to read the title field for type names. Which, unless you're writing your own jsonschema consumer, probably won't use.

But if you are, it should work perfectly.

One last thing to note is that PR aids exhaustive schema generation.

But you should be careful about espousing reductionism when consuming it.

Effectively, you need to be careful not to remap it to {TypeName: TypeSchema}.

Avoiding these classes of errors both when generating and consuming the schema will require a different approach for encoding information in the jsonschema that helps clients further disambiguate types. Module paths might be an option. But that's tricky to extract from macros.

from schemars.

ewoolsey avatar ewoolsey commented on June 11, 2024

Unfortunately because I'm dealing with a large library that implements JsonSchema on all its types, I'll have to wait for a new release on crates.io :/ Really appreciate the info though! And good luck finding a more robust solution!

from schemars.

karelispanagiotis avatar karelispanagiotis commented on June 11, 2024

I encountered the same issue with structs having the same name in different mods.

from schemars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.