Coder Social home page Coder Social logo

Comments (11)

mirata avatar mirata commented on August 14, 2024 14

@RicoSuter I think this would be a really good thing to add actually. Happy to help out if I can commit some time.
I had a very complicated object I needed to deal with on the typescript side with multiple generics, and it really doesn't work well. I don't think it matters that this concept would only work within the NSwag toolchain - people would definitely make use of it.

from njsonschema.

john-larson avatar john-larson commented on August 14, 2024 8

Is there any progress on this issue?

from njsonschema.

marinasundstrom avatar marinasundstrom commented on August 14, 2024 4

Is there any progress on this issue?

I am wondering the same.

from njsonschema.

binginsin avatar binginsin commented on August 14, 2024 3

Was looking into generics and JSON schema recently and found this:
https://gist.github.com/kevinswiber/4ee078f7bee175852587aca738377168#file-page-schema-json-L32

Apparently generics can be supported using $dynamicRef, $dynamicAnchor and multiple schemas.

I'm not entirely sure how difficult this would be to implement, but I believe it may be possible to add generic support without going against the specification of OpenAPI, even if other generators don't have this implemented.

Interested to hear others' thoughts.

from njsonschema.

antonGritsenko avatar antonGritsenko commented on August 14, 2024 3

because other tools will not understand it.

IMHO this is bad argument, since each and very OpenAPI tool works in a very different way, and none of them fully support all aspects of the OpenAPI on different platform. NJsonSchema and NSwag are from .net world, so they should support generics, because its native of the platform.

from njsonschema.

grovesNL avatar grovesNL commented on August 14, 2024

How should multiple generic parameters be handled with that schema definition?

from njsonschema.

RicoSuter avatar RicoSuter commented on August 14, 2024

You would have multiple entries in the "x-generics" object.

from njsonschema.

RicoSuter avatar RicoSuter commented on August 14, 2024

I've updated the sample

from njsonschema.

RicoSuter avatar RicoSuter commented on August 14, 2024

Is there any progress on this issue?

The answer is no there is no progress :-)... not planned as it is very custom to the NJsonSchema/NSwag toolchain - main recommendation is to avoid generics because other tools will not understand it.

from njsonschema.

JohnGalt1717 avatar JohnGalt1717 commented on August 14, 2024

How is this still an issue in 2023 9 years after the first request for generics in the OpenAPI spec that basically all languages support or could just use object?

You should be able to define Page as a schema type, and to be valid, everywhere it's referenced should have to provide the ref/concrete type to TResult.

And that should be it. NSwag shouldn't have to be doing this, this should just be part of the OpenApi spec. But like Enums that it still has a mess of, this still isn't supported.

This is literally why people create new competing standards: Basics broken.

from njsonschema.

mcDevnagh avatar mcDevnagh commented on August 14, 2024

If generating Generic DTOs is too complicated, the could be an option to just use the generic types if generateDtoTypes is false. It would then fall upon the developer to "generate" the DTOs

Thus, it would generate

public virtual async System.Threading.Tasks.Task<ListResponse<Order>> GetOrdersAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
public virtual async System.Threading.Tasks.Task<ListResponseOfOrder> GetOrdersAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))

Maybe an option to just using the schema IDs directly, since our schema ID for ListResponseOfOrder is ListResponse<Order>

from njsonschema.

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.