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

Feat: support custom annotations #38

Merged
merged 3 commits into from
Aug 31, 2024

Conversation

chivalryq
Copy link
Contributor

Overview

Support custom annotations. See https://json-schema.org/blog/posts/custom-annotations-will-continue

After generation: custom annotation starts with "x-" will be added to field.

Source

# @schema
# type: string
# x-foo-type: modelWeight
# @schema
modelWeight: ""

result

{
    "modelWeight": {
      "default": "",
      "title": "modelWeight",
      "type": "string",
      "x-foo-field-type": "modelWeight"
    }
}

@dadav
Copy link
Owner

dadav commented Aug 8, 2024

Hi @chivalryq,

thanks for your PR. Looks interesting, do you have any specific usecase in mind? I'd like to understand better what is used for :)

@chivalryq
Copy link
Contributor Author

Hi @dadav

We are using helm-based ArgoCD application, and we build a platform helping us to dispatch those apps. When filling values of applications, there're fields like:

modelWeight: <series>/<version>/<weight>

where series, version, weight are metadata that stored in system. So we can make it a "Custom" field in frontend form instead of a simple string field.

image

Here's the trick, we can use a custom annotation to mark what this field type should be at frontend. And generate schema from it.

# @schema
# x-<company-name>/field-type: model-weight
# @schema
modelWeight: ""

@dadav dadav force-pushed the feat/support-custom-annotations branch from d72ca49 to e5c1345 Compare August 31, 2024 17:45
@dadav
Copy link
Owner

dadav commented Aug 31, 2024

Why not :)

@dadav dadav merged commit f205574 into dadav:main Aug 31, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants