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(dynamite)!: add experimental standalone JsonSchema generation #1964

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Leptopoda
Copy link
Member

implements: #933

@Leptopoda Leptopoda requested a review from provokateurin April 24, 2024 09:49
@Leptopoda Leptopoda linked an issue Apr 24, 2024 that may be closed by this pull request
Copy link
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First commit message has a typo and should be feat(dynamite): do not rely on the openapi spec for type resolving

packages/dynamite/dynamite/build.yaml Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a bit of this code is just copied from the existing builder and should be factored out into common methods.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure how much we can deduplicate this without making a mess of the code.
I'll take another look on what makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a schema definition: https://json-schema.org/learn/getting-started-step-by-step#create
We should really implement the whole thing and not just the schema part itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand? what is still missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The metadata that can be inside a schema definition is not considered in the generated code. For OpenAPI specs we add title, description, license etc. to the top of the file while this doesn't seem to happen for JSON schema definitions afaict.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry my initial message was a bit confusing, I'd simply like to have proper support for JSON schema definitions.

Copy link
Member Author

@Leptopoda Leptopoda Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please say what JsonSchema keywords you'd like to support?

It appears that the only user facing information is the title and I don't think that it should be set as a library level doc comment. I'd rather add it to the generated class itself similar to how the dart doc style expects the documentation:

/// {title}.
///
/// {description}.
class MyObject {}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the comment should be on the generated class. IMO the $id can also be relevant for users, so I'd like to have that linked as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is $defs it is possible to have multiple object inside a single schema. I don't know if the title and description should be interpreted as the title and description for the main object or the whole schema.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory we already support $defs. our reference resolving is independent from the dart schema object and directly searches in the json data (see: #1953).

Therefore only the schemas referenced in the main schema will be generated. Or do you mean to generate all schemas defined in the definitions just in case 🤷‍♀️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this was about the other fields, not specifically $defs. I was just saying that title and description might not be for the main schema but for the whole schema which would make them library level.

@Leptopoda Leptopoda force-pushed the feat/dynamite/json_schema_builder branch from 44e594b to a1705e0 Compare April 26, 2024 19:30
Copy link

codecov bot commented Apr 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 29.31%. Comparing base (729e5ae) to head (44e594b).
Report is 5 commits behind head on main.

❗ Current head 44e594b differs from pull request most recent head a1705e0. Consider uploading reports for the commit a1705e0 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1964      +/-   ##
==========================================
+ Coverage   28.43%   29.31%   +0.87%     
==========================================
  Files         245      245              
  Lines       81449    76519    -4930     
==========================================
- Hits        23161    22430     -731     
+ Misses      58288    54089    -4199     
Flag Coverage Δ *Carryforward flag
dynamite 22.46% <ø> (-0.26%) ⬇️
dynamite_end_to_end_test 62.98% <ø> (+0.35%) ⬆️
dynamite_runtime 82.65% <ø> (ø) Carriedforward from a3c55c1
neon_dashboard 92.56% <ø> (ø)
neon_framework ∅ <ø> (∅) Carriedforward from a3c55c1
neon_talk ∅ <ø> (∅) Carriedforward from a3c55c1
nextcloud ∅ <ø> (∅) Carriedforward from a3c55c1
sort_box 90.90% <ø> (ø) Carriedforward from a3c55c1

*This pull request uses carry forward flags. Click here to find out more.

see 160 files with indirect coverage changes

@Leptopoda Leptopoda changed the base branch from main to feat/dynamite/json_schema_meta-data-annotation April 26, 2024 19:30
@Leptopoda Leptopoda marked this pull request as draft April 26, 2024 19:30
@Leptopoda
Copy link
Member Author

Making a draft for now until we have merged all the depending changes.

@Leptopoda Leptopoda changed the title feat(dynamite): do not relly on the openapi spec for type resolving feat(dynamite)!: add experimental standalone JsonSchema generation Apr 26, 2024
@Leptopoda Leptopoda force-pushed the feat/dynamite/json_schema_meta-data-annotation branch 2 times, most recently from 9658bf4 to 0b64d23 Compare April 27, 2024 11:18
Base automatically changed from feat/dynamite/json_schema_meta-data-annotation to main April 27, 2024 11:36
@provokateurin
Copy link
Member

$defs should also be supported as it acts like the components.schemas

@provokateurin
Copy link
Member

@Leptopoda can we move this forward and include it in the next batch of releases or is there something holding it back?

@Leptopoda
Copy link
Member Author

I don't think this is anything we can immediately implement.

$defs should also be supported as it acts like the components.schemas

This requires a complete rework of how our $ref resolving works and this will take quite some time ...

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.

Support generating code for JSON schema files
2 participants