-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/methods #121
Feature/methods #121
Conversation
{ | ||
"name": "d", | ||
"type": "union", | ||
"typeArguments": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with this syntax. Can you send me some resources so I can evaluate this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@domoritz: TypeScript - generics
- the
string
inArray<string>
is atypeArgument
- the
implements
inT implements Array<string>
makesArray<string>
aconstraint
(onT
) - for
union
-types andintersection
-types in method-definitions i usedtypeArguments
to represent the types that are part of that union/intersection.
I unfortunately don't really have sources on how a function should be represented in a JSON-Schema, because there barely are sources. I've read somewhere that JSON-Schema isn't really meant to include functions, so i somewhat came up with my own way to represent them.
If there happens to be standards for this, that i just overlooked, i'm more than happy to follow it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know Generics in typescript but this syntax in JSON schema strikes me as an odd use case for JSON schema. A schema is usually intended for data structures and not really for functions or method signatures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, usually you wouldn't use JSON-Schema for that, because a function has functionality. But the use case here is not to verify a whole function (including the implementation), but to verify it's declaration. The goal is to compare "functions" based on their name, parameter, parameter-order, parameter-types, return-type etc.
I think JSON-Schema can be a good tool to verify function-declarations, without comparing the function-implementation.
I personally think this is too non-standard and I would like to keep the library lean. Unless somebody has strong opinions, I vote for not including this. Can we somehow find a way to implement a plugin interface so that you can easily extend the ts to json schema converter instead? |
@domoritz I see your point. I'd be completely happy with a plugin-interface that would allow me to add this functionality! |
@heikomat Thanks! I understand that you put some effort into this PR. Unfortunately, I won't have the cycles to add the plugin interface but maybe someone else can chime in. I'm closing this PR for now. |
@domoritz i'm not toooo familiar with typescript-json-schema (i guess you can can see my level of knowledge about this library in this PR), but if it's ok, i could give adding a plugin interface a try in another branch |
@domoritz I understand your reason to not merge the PR now. The JSON schema standard doesn't specify methods or generics by default. But the standard allows (and encourages) expanding it. The basic type schema for functions and promises could therefore easily be supplied in additional JSON schemas, that we can later reference in our generated JSON schemas. But I also agree that it shouldn't be considered the default behavior of this library as this is beyond the core JSON schema standard. I hope that we can revisit this as a plugin as soon as that feature progresses. |
@5ebastianMeier Thanks for the understanding. I agree with the points you are making. |
Hi, |
@bergundy Not that I know of. Thanks for offering to help! You can look into how we could create a plugin interface. |
@domoritz I'll try and see if I can come up with. Any ideas as of what we'd like to support? |
Not at the moment, no. |
@bergundy I haven't got the time right now, to write down the use cases we would need in the plugin API to implement this feature. But if you want to look into it, we've continued some further development on our fork after the initial PR (see https://github.com/essential-projects/typescript-json-schema). Maybe the commits there can help you to isolate an API out of our changes. Just out of curiosity: do you specifically want to implement the feature described in this PR or do you have other use cases or PRs in mind that I don't know of? I'll gladly review any plugin concept and provide feedback from our point of view if you want. Heads up: we're not planning to implement any further features except the one described in this PR |
@5ebastianMeier I mainly need the feature in this PR, I'm planning on creating some sort of "reverse swagger" tool, and I'd like to avoid forking TJS. |
Please:
.js
,.js.map
, or.d.ts
in your pull request as it makes it harder to merge your changes.Readme.md
This implements #110.
This is probably not optimal, as i've not studied the JSON-Schema-specs in depth, but i've talked to @5ebastianMeier, and this would work for him.
If anything needs to be changed, please let me know, i'm happy to adjust it if necessary, especially because i think i haven't reused as much of the existing code as i could have.