Skip to content

feat: allow preserving specific schemas during prune (preserve-schemas + x-oapi-codegen-keep-unused)#2233

Open
aureleoules wants to merge 1 commit intooapi-codegen:mainfrom
aureleoules:aurele.oules/preserve-schemas
Open

feat: allow preserving specific schemas during prune (preserve-schemas + x-oapi-codegen-keep-unused)#2233
aureleoules wants to merge 1 commit intooapi-codegen:mainfrom
aureleoules:aurele.oules/preserve-schemas

Conversation

@aureleoules
Copy link

Add two ways to keep unreferenced component schemas from being pruned:

  • output-options.preserve-schemas: list of schema names to always keep, even when not referenced anywhere in the spec.
  • x-oapi-codegen-keep-unused: set to true on a schema in the OpenAPI spec so that schema is never pruned when unreferenced.

pruneUnusedComponents() now takes an optional preserveSchemas []string (from config); schemas in that list or with the extension are not removed. Existing call sites use nil. Tests and configuration-schema/README updated.

…s + x-oapi-codegen-keep-unused)

Add two ways to keep unreferenced component schemas from being pruned:

- output-options.preserve-schemas: list of schema names to always keep,
  even when not referenced anywhere in the spec.

- x-oapi-codegen-keep-unused: set to true on a schema in the OpenAPI spec
  so that schema is never pruned when unreferenced.

pruneUnusedComponents() now takes an optional preserveSchemas []string
(from config); schemas in that list or with the extension are not removed.
Existing call sites use nil. Tests and configuration-schema/README updated.
@aureleoules aureleoules requested a review from a team as a code owner February 23, 2026 13:08
@oapi-codegen oapi-codegen deleted a comment from greptile-apps bot Feb 24, 2026
@mromaszewicz
Copy link
Member

@aureleoules , we already have this behavior:
https://github.com/oapi-codegen/oapi-codegen/blob/main/pkg/codegen/configuration.go#L248

Is this not sufficient for what you are trying to accomplish?

Go does dead code pruning when it compiles, so having some unused schemas in the generated go code when setting skip-prune: true is ok. i don't think we need to pick, per-schema, which one to include.

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.

2 participants