8000 [jsonschemagen] Add lifecycle methods to jsonschemagen by sneakers-the-rat · Pull Request #2369 · linkml/linkml · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[jsonschemagen] Add lifecycle methods to jsonschemagen #2369

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

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

sneakers-the-rat
Copy link
Collaborator

Related to: #2339

Lifecycle methods in generators are a great way to allow people to modify the generation process in ways that might not have a place in the main in-library generators while not having to override methods that would cause subclasses to get out of date with changes in in-library generators.

In this case the request was to add special terms for a json schema dialect for UI elements. Adding lifecycle hooks allows them to experiment with making that work - and if it is something that we might want to integrate upstream then we have a clear, packaged way of doing that that cleanly divides the additional parts into separate methods rather than intercalating them in the other parts of the generator.

As usual, i could only implement some of the lifecycle hooks (eg. the after methods for the collective classes methods can't be done because the results aren't returned, but directly added to a shared dict), but i added which to the docstring.

Added before/after_generate_class_slot because those seem different enough from generating a slot by itself to be worth a separate method that also passes the class that the slot is being built in the context of. will save swapping pydanticgen over to those for another PR.

Build results classes here are trivial since jsonschemagen doesn't use the builder pattern, used model_construct since there's no actual validation to be done and i wasn't sure if the pydantic validator would take extra time with a custom dict subclass.

Copy link
codecov bot commented Oct 14, 2024

Codecov Report

Attention: Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.

Project coverage is 80.97%. Comparing base (198a2de) to head (f3494be).
Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
linkml/generators/common/lifecycle.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2369      +/-   ##
==========================================
+ Coverage   80.91%   80.97%   +0.06%     
==========================================
  Files         118      118              
  Lines       13129    13156      +27     
  Branches     3711     3710       -1     
==========================================
+ Hits        10623    10653      +30     
+ Misses       1898     1895       -3     
  Partials      608      608              

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

@sierra-moxon
Copy link
Member

@sneakers-the-rat - just an update: we ran out of time in the dev call (you are always more than welcome to join) today to discuss this. It is next on my list; please let us know if this is a blocker for you?

@sneakers-the-rat
Copy link
Collaborator Author

Not a blocker for me, just helping out with #2339 :)

@sierra-moxon sierra-moxon merged commit 4acf912 into linkml:main Nov 1, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0