FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(codegen): migrate embedded spec compression to `compress/lzw` by jamietanna · Pull Request #2537 · oapi-codegen/oapi-codegen · GitHub

feat(codegen): migrate embedded spec compression to compress/lzw - #2537

Open
jamietanna wants to merge 2 commits into
mainfrom
fix/flate
Open

feat(codegen): migrate embedded spec compression to compress/lzw#2537
jamietanna wants to merge 2 commits into
mainfrom
fix/flate

Conversation

Copy link
Copy Markdown
Member
  • refactor(codegen): extract compressSpec helper from GenerateInlinedSpec

    When we embed the OpenAPI spec as an "embedded spec" in the generated
    code, we compress its JSON form (with compress/flate) and then
    Base64-encode the output.

    While upgrading to Go 1.27, Go 1.27 produces different answer for the embedded spec #2536 noticed that there is now a diff in
    the generated code, due to a slight compression improvement in
    compress/flate, which means that any Go 1.27 users will now see a
    diff.

    To provide a more stable output across Go versions, we can change our
    compression algorithm.

    Before we do this, we can extract a compressSpec helper function and
    add a test to cover the existing compression, which will fail on Go
    1.27.

  • feat(codegen): migrate embedded spec compression to compress/lzw

    When we embed the OpenAPI spec as an "embedded spec" in the generated
    code, we compress its JSON form (with compress/flate) and then
    Base64-encode the output.

    While upgrading to Go 1.27, Go 1.27 produces different answer for the embedded spec #2536 noticed that there is now a diff in
    the generated code, due to a slight compression improvement in
    compress/flate, which means that any Go 1.27 users will now see a
    diff.

    To provide a more stable output across Go versions, we can change our
    compression algorithm.

    Through testing, compress/lzw appears to be stable across Go 1.26 and
    Go 1.27, so we can switch this over.

    Closes Go 1.27 produces different answer for the embedded spec #2536.

jamietanna requested a review from a team as a code owner August 20, 2026 07:11

jamietanna commented Aug 20, 2026
edited
Loading

Copy link
Copy Markdown
Member Author

I could see this as a feat or a fix depending on how we want to do it - I don't think too many folks are directly depending on the internals of how it's compressed, and should instead use the generated helper functions to decompress it

greptile-apps Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR changes embedded OpenAPI specifications from DEFLATE to LZW compression to make generated output more stable across Go releases.

  • Extracts compression into compressSpec and adds deterministic-output and round-trip tests.
  • Updates shared imports and inline decoding templates to use compress/lzw.
  • Regenerates embedded-spec fixtures across examples and internal tests.

Confidence Score: 4/5

The PR should not merge until existing partial user-template overrides have a compatible migration or fallback for the new embedded-spec format.

The bundled compressor and decoder agree, but the generator changes the payload contract unconditionally while allowing users to replace the decoder template independently, leaving existing DEFLATE overrides unable to read regenerated specifications.

Files Needing Attention: pkg/codegen/inline.go, pkg/codegen/templates/inline.tmpl

Important Files Changed

Filename Overview
pkg/codegen/inline.go Changes generator-side embedded-spec compression to LZW; existing independently overridden decoders can become format-incompatible.
pkg/codegen/templates/inline.tmpl Updates the bundled runtime decoder and diagnostics to match the LZW payload.
pkg/codegen/templates/imports.tmpl Replaces the generated DEFLATE import with the matching standard-library LZW import.
pkg/codegen/inline_test.go Adds deterministic-output and LZW round-trip coverage using a fixed trusted fixture.
Prompt To Fix All With AI
### Issue 1
pkg/codegen/inline.go:74
**Custom decoders receive incompatible payloads**

When a user overrides only `inline.tmpl` with the previous DEFLATE decoder, `compressSpec` now supplies LZW bytes to that decoder, causing the generated `GetSpec` and `GetSwagger` APIs to fail to load the embedded OpenAPI document. This payload-format change needs a compatibility path for independently overridden templates.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "feat(codegen): migrate embedded spec com..." | Re-trigger Greptile

Comment thread pkg/codegen/inline.go
// embedded spec.
func compressSpec(data []byte) (string, error) {
var buf bytes.Buffer
zw := lzw.NewWriter(&buf, lzw.LSB, 8)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Custom decoders receive incompatible payloads

When a user overrides only inline.tmpl with the previous DEFLATE decoder, compressSpec now supplies LZW bytes to that decoder, causing the generated GetSpec and GetSwagger APIs to fail to load the embedded OpenAPI document. This payload-format change needs a compatibility path for independently overridden templates.

Knowledge Base Used:

Prompt To Fix With AI
This is a comment left during a code review.
Path: pkg/codegen/inline.go
Line: 74

Comment:
**Custom decoders receive incompatible payloads**

When a user overrides only `inline.tmpl` with the previous DEFLATE decoder, `compressSpec` now supplies LZW bytes to that decoder, causing the generated `GetSpec` and `GetSwagger` APIs to fail to load the embedded OpenAPI document. This payload-format change needs a compatibility path for independently overridden templates.

**Knowledge Base Used:**
- [Codegen Pipeline](https://app.greptile.com/oapi-codegen/-/custom-context/knowledge-base/oapi-codegen/oapi-codegen/-/docs/codegen-pipeline.md)
- [Server & Client Templates (pkg/codegen/templates)](https://app.greptile.com/oapi-codegen/-/custom-context/knowledge-base/oapi-codegen/oapi-codegen/-/docs/templates-codegen.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

jamietanna and others added 2 commits August 20, 2026 08:17
…dSpec`

When we embed the OpenAPI spec as an "embedded spec" in the generated
code, we compress its JSON form (with `compress/flate`) and then
Base64-encode the output.

While upgrading to Go 1.27, #2536 noticed that there is now a diff in
the generated code, due to a slight compression improvement in
`compress/flate`, which means that any Go 1.27 users will now see a
diff.

To provide a more stable output across Go versions, we can change our
compression algorithm.

Before we do this, we can extract a `compressSpec` helper function and
add a test to cover the existing compression, which will fail on Go
1.27.

Co-Authored-By: Claude Sonnet 5 <claude-code@jamietanna.co.uk>
When we embed the OpenAPI spec as an "embedded spec" in the generated
code, we compress its JSON form (with `compress/flate`) and then
Base64-encode the output.

While upgrading to Go 1.27, #2536 noticed that there is now a diff in
the generated code, due to a slight compression improvement in
`compress/flate`, which means that any Go 1.27 users will now see a
diff.

To provide a more stable output across Go versions, we can change our
compression algorithm.

Through testing, `compress/lzw` appears to be stable across Go 1.26 and
Go 1.27, so we can switch this over.

Closes #2536.

Co-Authored-By: Claude Sonnet 5 <claude-code@jamietanna.co.uk>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

Go 1.27 produces different answer for the embedded spec

1 participant


Back | FazBrowse Home | New Git URL