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

Possible to not prefix names? #297

Open
stevekuznetsov opened this issue Oct 22, 2024 · 5 comments · May be fixed by #324
Open

Possible to not prefix names? #297

stevekuznetsov opened this issue Oct 22, 2024 · 5 comments · May be fixed by #324

Comments

@stevekuznetsov
Copy link
Contributor

In dense, nested schemas without explicit call-outs in $defs, this tool today will string-concatenate the type names to form extremely long prefixes for deeply-nested types. It would be awesome to opt into not doing this and risking the collision of type names. If this is acceptable, I am happy to implement such an option behind some flag.

@stevekuznetsov
Copy link
Contributor Author

@omissis any thoughts on this? Happy to start work ASAP if you are OK with the idea.

@omissis
Copy link
Owner

omissis commented Nov 7, 2024

hey, I am not really sure I want to add an extra flag for cosmetic reasons if that can cause invalid code to be generated. so if we have to go down this path, I'd do it with a collision remediation strategy. would you be open to that and how would you implement it if so?

@stevekuznetsov
Copy link
Contributor Author

@omissis well this is already an issue today, actually. Any set of schemas that reference the same type within themselves will cause duplicates to be generated if you run the go-jsonschema tool against them individually right now. I think we could then add a feature to generate all de-duplicated Go types for N schemas - at the point that go-jsonschema has all N schemas loaded at once, it should be able to not only de-duplicate but also find shortest possible name prefix necessary to be unique.

@bbrcan
Copy link

bbrcan commented Nov 19, 2024

I'd love to see a flag like this. At the moment I'm getting types like RouteLocationsElemAddressesElemAddressType, RouteLocationsElemAddressesElemContactsElem, which are way too long.

@stevekuznetsov stevekuznetsov linked a pull request Nov 19, 2024 that will close this issue
@stevekuznetsov
Copy link
Contributor Author

stevekuznetsov commented Nov 19, 2024

I've pushed #324 as one step of many for this feature. For a real-world use-case for us, some examples of names that change with the new flag:

RolloutSpecificationOrchestratedStepsElem -> OrchestratedStep
RolloutSpecificationOrchestratedStepsElemApplicationsApplyAcrossServiceResources -> ApplyAcrossServiceResources

If this approach looks OK, I will work on loading more than one file at a time and deduplicating across schemas next. That will be a bit more work as the data structures today are per-schema.

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 a pull request may close this issue.

3 participants