patchspec

command
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Command patchspec preprocesses the downloaded OpenAPI document before oapi-codegen runs, flattening scalar `oneOf` unions in *parameter* schemas into a plain `type: string`.

Why this exists: Freelo's spec describes polymorphic path parameters with a oneOf, e.g. note_id accepts either the numeric id or the note uuid:

NoteIdParam:
  name: note_id
  in: path
  schema:
    oneOf:
      - type: integer
      - type: string
        format: uuid

oapi-codegen v2 turns that into a union struct whose accessors reference generated-but-never-emitted member types (`N0`, `N1`) — which additionally collide with the unprefixed `N0`/`N1` enum constants it emits elsewhere, so the package does not compile ("N0 (constant) is not a type"). Even if it did compile, a union struct cannot be serialized into a URL path segment by runtime.StyleParamWithOptions.

Path, query, header and cookie parameters are strings on the wire, so collapsing an all-scalar union to `type: string` is lossless: callers can pass "12345" or a uuid in the same argument.

This is a spec preprocessor (rather than a post-generation patch) because the fix belongs to the input document: one schema edit replaces having to rewrite a union struct plus six accessor methods in the generated Go.

Only parameter schemas are touched — request/response body unions keep their generated union types. Run via `make gen`. Idempotent, and a no-op once the upstream spec stops emitting scalar parameter unions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL