Skip to content
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

Open
5ebastianMeier opened this issue May 16, 2017 · 7 comments
Open

Support for functions #110

5ebastianMeier opened this issue May 16, 2017 · 7 comments

Comments

@5ebastianMeier
Copy link

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?

@heikomat
Copy link

heikomat commented Jun 4, 2017

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 getMethodDefinition-method

@azu
Copy link

azu commented Apr 10, 2020

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

typescript-json-schema index.ts HandlerObject

This output is:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "properties": {
        "prop": {
            "type": "object"
        }
    },
    "type": "object"
}

Reproduce repository:
https://github.com/azu/typescript-json-schema-function-object-issue

@mattoni
Copy link

mattoni commented May 13, 2020

Is this still on the radar?

@domoritz
Copy link
Collaborator

domoritz commented May 13, 2020

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.

@theoephraim
Copy link

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.

@Hexer10
Copy link

Hexer10 commented Jul 31, 2020

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.
If this is against the schema it would be enough to add a switch that to enable to feature only when needed

@havsar
Copy link

havsar commented Aug 18, 2023

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants