Documentation
¶
Overview ¶
Package codegen generates the SDK's *_types.gen.go files from the OpenAPI specs in codegen/openapi.
The upstream specs contain known bugs (wrong types, malformed schemas, machine-generated operation ids). Rather than hand-maintaining corrected copies of the generated types, this package applies a fixed set of transforms to each spec in memory — the committed spec files are never modified — and feeds the corrected spec to oapi-codegen.
The behavior of every transform is pinned by the characterization tests in codegen_test.go; the committed *_types.gen.go files must be reproducible byte-for-byte from the committed specs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchSpecs ¶
func FetchSpecs(opts FetchOptions) error
FetchSpecs downloads every configured spec from the Dev Portal and rewrites the local copies. Each fetched document is validated (it must be an OpenAPI document and must survive the transform pipeline, so broken overrides surface immediately) and re-indented with json.Indent, which changes whitespace only — key order and values stay byte-exact as served.
Specs without a configured source are reported and skipped. All configured specs are attempted; errors are aggregated so one failure does not hide the rest.
func Generate ¶
Generate runs the full type-generation pipeline: it validates spec file names, applies the transform chain to each spec in memory (the spec files on disk are never modified), invokes the pinned oapi-codegen on the corrected spec, rewrites form tags to url tags, and writes the result into the output directory.
func SeedLock ¶
func SeedLock(opts FetchOptions) error
SeedLock builds the lock file from the spec copies already on disk. It is the bootstrap (and repair) path for specs that predate the fetch tooling: provenance fields that cannot be known locally (fetchedAt) are left empty.
Types ¶
type FetchOptions ¶
type FetchOptions struct {
// SpecsDir is the directory the fetched specs are written to.
SpecsDir string
// MappingFile is the operation-id mapping file, used to dry-run the
// transform pipeline against each fetched spec.
MappingFile string
// LockFile records the provenance of each committed spec; see specLock.
LockFile string
// Token is the Dev Portal API token.
Token string
// Client is the HTTP client to use; defaults to a client with a 30s
// timeout.
Client *http.Client
// Now stamps fetchedAt in the lock file; defaults to time.Now.
Now func() time.Time
}
FetchOptions configures a spec refresh.
type Options ¶
type Options struct {
// SpecsDir is the directory containing the *-openapi.json spec files.
SpecsDir string
// MappingFile is the JSON file mapping upstream operation ids to friendly
// names.
MappingFile string
// OutputDir is the sdk-clients directory that receives
// <package>/<spec>_types.gen.go files.
OutputDir string
}
Options configures a generation run.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
fetch-specs
command
Command fetch-specs refreshes the local OpenAPI spec copies from the 1inch Dev Portal and records their provenance in codegen/specs.lock.json.
|
Command fetch-specs refreshes the local OpenAPI spec copies from the 1inch Dev Portal and records their provenance in codegen/specs.lock.json. |
|
generate-types
command
Command generate-types regenerates all *_types.gen.go files from the OpenAPI specs in codegen/openapi.
|
Command generate-types regenerates all *_types.gen.go files from the OpenAPI specs in codegen/openapi. |