Comments (11)
@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.
Is there any progress on this issue?
from njsonschema.
Is there any progress on this issue?
I am wondering the same.
from njsonschema.
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.
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.
How should multiple generic parameters be handled with that schema definition?
from njsonschema.
You would have multiple entries in the "x-generics" object.
from njsonschema.
I've updated the sample
from njsonschema.
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.
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.
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)
- Using the generic type 'JsonInheritanceConverter<TBase>' requires 1 type argument HOT 2
- NJsonSchema generated code throwing The JSON value could not be converted HOT 1
- Improve base package readme
- AllowAdditionalProperties - not working
- Format "guid" vs "uuid"
- Validation Failures On All JSON Schema Draft Versions
- Private expression-bodied read-only properties should be ignored HOT 1
- Unable to generate document when XmlElement[] is a property of the class
- JsonProperty not working on version 11.0.0 (working on 10.9.0) HOT 1
- Referenced schema could not be loaded when defined in external schema file
- Fixed the bug. "System.InvalidOperationException: Could not resolve the path '#/paths/~1audienceCategories~1%7Ba "
- Annotations on separate lines?
- Polymorphic Schema Generation
- .Net6 to .Net8 upgrade - System.InvalidOperationException: This operation is only valid on generic types. HOT 1
- C# TimeSpan not resolved and generated as a DayJs duration HOT 1
- Property named '-1' generates wrong C# Property name
- Duplicated members
- IEquatable<T> interface
- Method Resolution Conflict in `SystemTextJsonReflectionService`
- INPC: Skip change check (to support partial patch) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from njsonschema.