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

Enhancement of JSON Schema generation #2549

Closed
guersam opened this issue Dec 8, 2023 · 8 comments · Fixed by #2661
Closed

Enhancement of JSON Schema generation #2549

guersam opened this issue Dec 8, 2023 · 8 comments · Fixed by #2661
Labels

Comments

@guersam
Copy link
Contributor

guersam commented Dec 8, 2023

I'm currently adapting the same command model for ChatGPT, utilizing it in two ways: one through an HTTP endpoint called by the ChatGPT plugin, and the other for direct use via the ChatGPT API.

Thanks to #2470, I've successfully generated a JSON schema. However, while experimenting with RC4, I identified two specific use cases that could be improved:

Eliminating the Need for an Intermediate HttpCodec

To generate a JSON Schema of a case class A, I currently need to wrap my schema with HttpCodec.content. A more straightforward method to directly convert Schema[A] to JsonSchema would be beneficial.

    OpenAPIGen
      .contentAsJsonSchema(
        HttpCodec.content[A](MediaType.application.json)(using inputSchema),
      )

EDIT: JsonSchema.fromZSchema does the job.

Enhanced Customization During Serialization

In RC4, the generated JsonSchema invariably includes the additionalProperties field in the serialized JSON. However, I'm looking to remove this field to minimize ChatGPT token usage. I currently do not have a clear interface design or idea for how to achieve this level of customization.

@guersam guersam added the enhancement New feature or request label Dec 8, 2023
@987Nabil
Copy link
Contributor

987Nabil commented Dec 8, 2023

For directly creating JsonSchema without the need of an HttpCodec, you should be able to just call JsonSchema#fromZSchema

@guersam
Copy link
Contributor Author

guersam commented Dec 15, 2023

@987Nabil Thanks for fromZSchema!

Another use case is to transform a JsonSchema into a Java data type generated by protobuf. Currently I need to pollute zio.http.endpoint.openapi namespace to access SerializableJsonSchema or concrete JsonSchema variants.

I considered zio-schema-protobuf, but there's no guarantee that the inferred codec matches the desired protobuf spec. (e.g. the order of enum values)

@987Nabil
Copy link
Contributor

@guersam I am working currently on openapi to endpoint code gen and want to work on protobuf next. I will try to solve this in this workflow

@guersam
Copy link
Contributor Author

guersam commented Dec 29, 2023

Another finding: Having OpenAPI.paths as a Map[OpenAPI.Path, OpenAPI.PathItem] results in the erasure of the order of path items. This leads to the rendered output being less coherent.

@jdegoes
Copy link
Member

jdegoes commented Jan 6, 2024

/bounty $200

For all issues raised herein.

Copy link

algora-pbc bot commented Jan 6, 2024

💎 $200 bounty created by ZIO
🙋 If you start working on this, comment /attempt #2549 along with your implementation plan
👉 To claim this bounty, submit a pull request that includes the text /claim #2549 somewhere in its body
📝 Before proceeding, please make sure you can receive payouts in your country
💵 Payment arrives in your account 2-5 days after the bounty is rewarded
💯 You keep 100% of the bounty award
🙏 Thank you for contributing to zio/zio-http!

👉 Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟢 @987Nabil #2661

987Nabil added a commit to 987Nabil/zio-http that referenced this issue Feb 3, 2024
Sorted maps for OpenAPI for stable json generation (zio#2549)
Copy link

algora-pbc bot commented Feb 3, 2024

💡 @987Nabil submitted a pull request that claims the bounty. You can visit your bounty board to reward.

jdegoes pushed a commit that referenced this issue Feb 7, 2024
Sorted maps for OpenAPI for stable json generation (#2549)
Copy link

algora-pbc bot commented Feb 7, 2024

🎉🎈 @987Nabil has been awarded $200! 🎈🎊

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

Successfully merging a pull request may close this issue.

3 participants