-
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
Support for functions #110
Comments
I found the place in the code that needs to be extended to support methods. I'll open a pullrequest as soon as i'm done writing a |
I met similar problems. Currently, typescript-json-schema just ignore merhod definition by #194. export type HandlerObject = {
prop(props: {}): string
}; This output is {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object"
} But, a property of function not ignored. index.ts: export type Handler = (props: {}) => string
export type HandlerObject = {
prop: Handler
}; Command
This output is: {
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"prop": {
"type": "object"
}
},
"type": "object"
} Reproduce repository: |
Is this still on the radar? |
Not for me since I don’t think functions are supported in JSON Schema. I’d be happy to review a proposal and we’ll tested pull request. I reopened the issue to look into why functions are not filtered out. |
While including functions in the schema of a type itself doesn't really make sense, some way of making all of that type info (and TSdoc comments) available would be amazing. Specifically, I'd like to be able to see the return and param types of functions, types for static class properties, and TSDoc comments attached to functions. I'm using this to generate API docs, and easily being able to grab the type info (and comments) for a function would let me more easily include the description and spec for request and response bodies. I've been able to largely work around this by using a custom ts compiler transformer to add stringified typenames into reflected metadata, and then looking up those types in the generated json schema. But with this setup, I currently have to always use a named type for route params, rather than defining them inline, and I have to avoid static properties if I want type info and comments about them. It's working pretty well, but having more type info available certainly would have made things more flexible. |
I'm also looking into this, I need to translate the typescript type definition into another language (Dart) and I need the functions as well. |
Any update on this? |
Hey! Any updates? I also need this. |
https://github.com/vega/ts-json-schema-generator has support for functions. You can look at the pull request but since there is no standard I can't ping you at how it should be done. |
I have to add one thing and sorry for the confusion. I don't want to get the function, I want to get the method declaration from an interface. Example:
I want to get the checkPemissions and its parameters. |
JSON schema is for JSON. An interface is not JSON. |
https://github.com/vega/ts-json-schema-generator has function support. The parser is at https://github.com/vega/ts-json-schema-generator/blob/next/src/NodeParser/FunctionNodeParser.ts for example. |
We'd like to generate schemas from our interfaces and also include functions and their respective parameters, as well as their corresponding types.
Do you plan to support such a scenario? In case you don't, do you have some advice where to start if we wanted to contribute that feature?
The text was updated successfully, but these errors were encountered: