Does JSONSchema support assigning a function to a property? #65
-
I want to be able to define functions with parameters and return type for my JavaScript object specification. I am hoping to be able to do this using JSONSchema. But, I can't seem to figure out how to do it. I am trying to do something like the following:
Is it possible to do something liek this? Triple thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
As (JavaScript) functions are not part of the JSON specification, it would be out of scope for JSONSchema. You can of course define your own schema or your own vocabulary along the lines of what you example code shows. |
Beta Was this translation helpful? Give feedback.
-
Question was already answered on StackOverflow. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the update. I am accustomed to using OpenAPI to specify a REST API, so "functions" are sorta built in to the specification format. I was hoping to take a similar route under JSON Schema. Of course TypeScript supports interfaces, which is an implicit specification for an object. We're trying to implement a single source of truth system in which both developers and documentation creators work from the same source in order to create code and also to create documentation. |
Beta Was this translation helpful? Give feedback.
-
https://json-schema.org/implementations.html#code-generation |
Beta Was this translation helpful? Give feedback.
As (JavaScript) functions are not part of the JSON specification, it would be out of scope for JSONSchema.
You can of course define your own schema or your own vocabulary along the lines of what you example code shows.