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

add enum tag to jsonschema #962

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

jtarchie
Copy link

@jtarchie jtarchie commented Apr 3, 2025

A similar PR may already be submitted!
Please search among the Pull request before creating one.

There is another issue, #912. It seems to have been abandoned.

Describe the change

When creating a JSON schema from a struct, a new tag enum can be used to see the Enum field.

For example,

type Car struct {
  Color string `json:"color" enum:"red,green,blue"`
}

This will see the Enum on the field definition would be Enum = []string{"red","green","blue"}.

This is implementation is being used.

Provide OpenAI documentation link
Provide a relevant API doc from https://platform.openai.com/docs/api-reference

Describe your solution

See change above.

Tests

  1. A heads up, the tests on Github Actions are not running these tests. I've added support to this PR to ensure it runs correctly.
  2. I've added tests for the enum field in the json_test.go. This also required adding some other tests for struct to schema definition.
  3. Because of omitempty, I've updated the tests to reflect this.

Additional context
n/a

Copy link

codecov bot commented Apr 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.25%. Comparing base (774fc9d) to head (db50e2b).
Report is 88 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #962       +/-   ##
===========================================
- Coverage   98.46%   85.25%   -13.21%     
===========================================
  Files          24       43       +19     
  Lines        1364     2259      +895     
===========================================
+ Hits         1343     1926      +583     
- Misses         15      312      +297     
- Partials        6       21       +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jtarchie
Copy link
Author

jtarchie commented Apr 3, 2025

I'm not sure why code coverage went down. Maybe adding more tests from Github Action?

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.

1 participant