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

Remove unused schemas #31

Closed
sudorandom opened this issue Sep 5, 2024 · 3 comments
Closed

Remove unused schemas #31

sudorandom opened this issue Sep 5, 2024 · 3 comments

Comments

@sudorandom
Copy link
Owner

Right now it's possible for schemas to be unused but still exist in the openapi spec. I think we can do some tree-shaking to ensure that unreferenced schemas get removed before we render it to the user. We can use the index/rolodex feature of libopenapi to help with this:

	{
		b, err := spec.Render()
		if err != nil {
			return nil, err
		}
		doc, err := libopenapi.NewDocument(b)
		if err != nil {
			return nil, err
		}
		model, errs := doc.BuildV3Model()
		if errs != nil {
			return nil, errors.Join(errs...)
		}
		model.Index.BuildIndex()
		slog.Info("rolo", "errs", model.Model.Rolodex.GetCaughtErrors())
		for name, ref := range model.Model.Rolodex.GetRootIndex().GetAllCombinedReferences() {
			slog.Info(name, "ref", ref)
		}
	}
@sudorandom
Copy link
Owner Author

Another strategy is to only add schemas when they are referenced (and don't already exist). That would give us this same effect, and may be easier to support other features later on

@sudorandom
Copy link
Owner Author

Should this be an option? It may be useful to see all of the types even if they aren't directly used.

@sudorandom
Copy link
Owner Author

This option is added with v0.12.0 as trim-unused-types

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

No branches or pull requests

1 participant