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

Codegen: Add new useHeadTagForObjectNames flag to permit splitting generated endpoint objects by tag #3594

Merged

Conversation

hughsimpson
Copy link
Contributor

@hughsimpson hughsimpson commented Mar 12, 2024

I've been thinking about this for ages and finally got around to it. If autogenerating files for a very large spec, it's possible to hit the JVM limits on class size since all definitions go into the same object; so from a purely technical perspective, this does enable working with certain specs that would otherwise require some fudging (such as calling the codegen cli on multiple input files); although I confess to also just finding it a bit tidier. This pr adds a new flag useHeadTagForObjectNames (defaulting to false, to preserve existing behaviour). If this flag is true then the generated endpoints are grouped by the first tag, and each group put into a new file+object with the same name as that tag. All types/enums/classes generated from schemas remain in the default object model as before, and if an endpoint has no tags at all, it is placed into the default object (i.e. a spec with no tags would see no change as a result of this pr, regardless of whether the flag were set to true or not)

@kciesielski
Copy link
Member

Thanks! Could you add documentation for this new flag to sbt-openapi-codegen.md?

@hughsimpson
Copy link
Contributor Author

Sure. Will do that in a few mins & push up a test, too

@hughsimpson
Copy link
Contributor Author

Done! (In case you can't tell, this is a feature I really want 😂)

@kciesielski
Copy link
Member

Yes, I can tell 😁 Sorry to push back some more, but could you also explain in the docs what the "first declared tag" mean? This could be added outside of the table with flags.

@hughsimpson
Copy link
Contributor Author

hughsimpson commented Mar 13, 2024

@kciesielski I've updated the copy a little more, let me know what you think

Edit: Happy to make changes, please do comment on anything you're not happy with. Meantime I've brewed another pr for ya 😄

@kciesielski
Copy link
Member

Thanks! Looks good to me :)

@hughsimpson hughsimpson force-pushed the separate_endpoint_objects_by_tag branch from d1c1f2d to 5a047c3 Compare March 14, 2024 08:19
@hughsimpson
Copy link
Contributor Author

Pushed rebase to fix merge conflicts

.map { case (name, definition) =>
s"""|lazy val $name =
val geMap =
doc.paths.flatMap(generatedEndpoints(components, useHeadTagForObjectNames)).groupBy(_._1).mapValues(_.map(_._2).reduce(_ ++ _))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would've been so much cleaner with groupMapReduce(_._1)(_._2)(_ ++ _) 😂 but, alas, scala 2.12...

@kciesielski kciesielski merged commit e611d21 into softwaremill:master Mar 14, 2024
23 checks passed
@hughsimpson hughsimpson deleted the separate_endpoint_objects_by_tag branch March 14, 2024 10:32
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