Documentation
¶
Overview ¶
Package codegen provides the public API for oapi-codegen's experimental code generator.
This package re-exports the core types and functions from the internal implementation, providing a stable public interface for external consumers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
func Generate(doc libopenapi.Document, specData []byte, cfg Configuration) (string, error)
Generate produces Go code from the parsed OpenAPI document. specData is the raw spec bytes used to embed the spec in the generated code.
Types ¶
type Configuration ¶
type Configuration = impl.Configuration
Configuration is the top-level configuration for code generation.
type GenerationOptions ¶
type GenerationOptions = impl.GenerationOptions
GenerationOptions controls which parts of the code are generated.
type ModelsPackage ¶
type ModelsPackage = impl.ModelsPackage
ModelsPackage specifies an external package containing the model types.
type NameMangling ¶
type NameMangling = impl.NameMangling
NameMangling configures how OpenAPI names are converted to Go identifiers.
type NameSubstitutions ¶
type NameSubstitutions = impl.NameSubstitutions
NameSubstitutions allows direct overrides of generated names.
type OutputOptions ¶
type OutputOptions = impl.OutputOptions
OutputOptions controls filtering of operations and schemas.
type RuntimeOutput ¶
type RuntimeOutput = impl.RuntimeOutput
RuntimeOutput holds the generated code for each runtime sub-package.
func GenerateRuntime ¶
func GenerateRuntime(baseImportPath string) (*RuntimeOutput, error)
GenerateRuntime produces standalone Go source files for each of the three runtime sub-packages (types, params, helpers). baseImportPath is the base import path for the runtime module (e.g., "github.com/org/project/runtime").
type RuntimePackageConfig ¶
type RuntimePackageConfig = impl.RuntimePackageConfig
RuntimePackageConfig specifies an external package containing runtime helpers.
type StructTagsConfig ¶
type StructTagsConfig = impl.StructTagsConfig
StructTagsConfig configures how struct tags are generated for fields.
type TypeMapping ¶
type TypeMapping = impl.TypeMapping
TypeMapping allows customizing OpenAPI type/format to Go type mappings.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package codegen generates Go code from parsed OpenAPI specs.
|
Package codegen generates Go code from parsed OpenAPI specs. |
|
dce
Package dce implements dead code elimination for generated Go source files.
|
Package dce implements dead code elimination for generated Go source files. |
|
runtime
Package runtime contains the source-of-truth Go source files for the oapi-codegen runtime helpers.
|
Package runtime contains the source-of-truth Go source files for the oapi-codegen runtime helpers. |
|
runtimeextract
Package runtimeextract reads Go source files from the embedded runtime FS and extracts code bodies for inlining into generated output or assembling into standalone runtime packages.
|
Package runtimeextract reads Go source files from the embedded runtime FS and extracts code bodies for inlining into generated output or assembling into standalone runtime packages. |
|
test/callbacks
Package callbacks tests callback initiator and receiver code generation.
|
Package callbacks tests callback initiator and receiver code generation. |
|
test/components/all_of
Package all_of tests allOf schema composition including inheritance chains, required field merging, and nested allOf with additional properties.
|
Package all_of tests allOf schema composition including inheritance chains, required field merging, and nested allOf with additional properties. |
|
test/components/allof_with_properties/additional_properties
Package additional_properties tests allOf composition where members have additionalProperties: true.
|
Package additional_properties tests allOf composition where members have additionalProperties: true. |
|
test/components/allof_with_properties/additional_properties_merge
Package additional_properties_merge tests all combinations of allOf merging with different additionalProperties configurations (true, false, typed, default).
|
Package additional_properties_merge tests all combinations of allOf merging with different additionalProperties configurations (true, false, typed, default). |
|
test/components/allof_with_properties/format
Package format tests allOf used to apply format constraints (uuid, date) to a base string type.
|
Package format tests allOf used to apply format constraints (uuid, date) to a base string type. |
|
test/components/allof_with_properties/same_level
Package same_level tests that properties defined at the same level as allOf are included in the generated type, not ignored.
|
Package same_level tests that properties defined at the same level as allOf are included in the generated type, not ignored. |
|
test/components/any_of_enums
Package any_of_enums tests that enum types are generated for properties inside anyOf member schemas.
|
Package any_of_enums tests that enum types are generated for properties inside anyOf member schemas. |
|
test/components/any_of_inline
Package any_of_inline tests inline anyOf schema composition with response schemas containing multiple object variants.
|
Package any_of_inline tests inline anyOf schema composition with response schemas containing multiple object variants. |
|
test/components/any_of_single_ref
Package any_of_single_ref tests anyOf with a single $ref — should generate a typed property, not interface{}.
|
Package any_of_single_ref tests anyOf with a single $ref — should generate a typed property, not interface{}. |
|
test/components/composition
Package composition tests complex component schemas including additionalProperties, oneOf/anyOf patterns, enums, readOnly/writeOnly, and x-go-name.
|
Package composition tests complex component schemas including additionalProperties, oneOf/anyOf patterns, enums, readOnly/writeOnly, and x-go-name. |
|
test/components/default_values
Package default_values tests default value handling in generated types.
|
Package default_values tests default value handling in generated types. |
|
test/components/enums/illegal_names
Package illegal_names tests enum constant generation with edge cases.
|
Package illegal_names tests enum constant generation with edge cases. |
|
test/components/nested_aggregate
Package nested_aggregate tests complex nesting of allOf, anyOf, and oneOf: arrays of anyOf, objects with anyOf/oneOf properties, allOf containing oneOf, oneOf with nested allOf and field preservation, and composition with enums.
|
Package nested_aggregate tests complex nesting of allOf, anyOf, and oneOf: arrays of anyOf, objects with anyOf/oneOf properties, allOf containing oneOf, oneOf with nested allOf and field preservation, and composition with enums. |
|
test/components/nullable
Package nullable tests nullable type generation with required/optional combinations.
|
Package nullable tests nullable type generation with required/optional combinations. |
|
test/components/objects
Package objects tests object schemas with additionalProperties configurations.
|
Package objects tests object schemas with additionalProperties configurations. |
|
test/components/one_of_discriminator_multi_mapping
Package one_of_discriminator_multi_mapping tests oneOf with a discriminator having multiple mapping entries pointing to the same schema.
|
Package one_of_discriminator_multi_mapping tests oneOf with a discriminator having multiple mapping entries pointing to the same schema. |
|
test/components/one_of_string_enums
Package one_of_string_enums tests oneOf with single-value string enum variants (undefined, registered, pending, active).
|
Package one_of_string_enums tests oneOf with single-value string enum variants (undefined, registered, pending, active). |
|
test/components/primitives/aliased_date
Package aliased_date tests aliased date-format types.
|
Package aliased_date tests aliased date-format types. |
|
test/components/primitives/untyped_properties
Package untyped_properties tests properties with no type field.
|
Package untyped_properties tests properties with no type field. |
|
test/components/recursive
Package recursive tests that recursive types are handled properly.
|
Package recursive tests that recursive types are handled properly. |
|
test/components/recursive_all_of
Package recursive_all_of tests recursive allOf self-references in schema definitions without causing a stack overflow.
|
Package recursive_all_of tests recursive allOf self-references in schema definitions without causing a stack overflow. |
|
test/components/recursive_one_of
Package recursive_one_of tests recursive/circular oneOf schema references (FilterPredicate pattern).
|
Package recursive_one_of tests recursive/circular oneOf schema references (FilterPredicate pattern). |
|
test/components/schemas
Package schemas tests comprehensive schema generation including generic objects, nullable properties, custom formats, extra-tags, deprecated fields, and x-go-type-name.
|
Package schemas tests comprehensive schema generation including generic objects, nullable properties, custom formats, extra-tags, deprecated fields, and x-go-type-name. |
|
test/extensions/x_go_type/enum_override
Package enum_override tests x-go-type-name on enum types.
|
Package enum_override tests x-go-type-name on enum types. |
|
test/extensions/x_go_type/object_override
Package object_override tests x-go-type-name on nested object types.
|
Package object_override tests x-go-type-name on nested object types. |
|
test/extensions/x_go_type/skip_pointer
Package skip_pointer tests x-go-type with skip-optional-pointer and x-go-type-import.
|
Package skip_pointer tests x-go-type with skip-optional-pointer and x-go-type-import. |
|
test/extensions/x_order
Package x_order tests field ordering via x-order extension.
|
Package x_order tests field ordering via x-order extension. |
|
test/external_ref/imports
Package imports tests external dependencies with import resolution.
|
Package imports tests external dependencies with import resolution. |
|
test/external_ref/multi_package_response
Package multi_package_response tests multi-package response schemas.
|
Package multi_package_response tests multi-package response schemas. |
|
test/external_ref/multi_spec
Package multi_spec tests multi-spec cross-package imports.
|
Package multi_spec tests multi-spec cross-package imports. |
|
test/external_ref/overlays
Package overlays tests spec overlays and external refs.
|
Package overlays tests spec overlays and external refs. |
|
test/external_ref/removed_ref
Package removed_ref tests external reference filtering.
|
Package removed_ref tests external reference filtering. |
|
test/external_ref/response_refs
Package response_refs tests external response refs across specs.
|
Package response_refs tests external response refs across specs. |
|
test/name_conflict_resolution
Package name_conflict_resolution tests comprehensive type name collision resolution.
|
Package name_conflict_resolution tests comprehensive type name collision resolution. |
|
test/name_conflict_resolution/head_digit_op_id
Package head_digit_op_id tests operation IDs starting with digits.
|
Package head_digit_op_id tests operation IDs starting with digits. |
|
test/name_conflict_resolution/inline_identifiers
Package inline_identifiers tests that inline schemas generate valid Go identifiers.
|
Package inline_identifiers tests that inline schemas generate valid Go identifiers. |
|
test/name_conflict_resolution/underscore_mapping
Package underscore_mapping tests underscore field name mapping.
|
Package underscore_mapping tests underscore field name mapping. |
|
test/output_options/name_normalizer
Package name_normalizer tests name normalization behavior.
|
Package name_normalizer tests name normalization behavior. |
|
test/output_options/skip_optional_pointer/arrays
Package arrays tests skip-optional-pointer with arrays and additionalProperties.
|
Package arrays tests skip-optional-pointer with arrays and additionalProperties. |
|
test/output_options/skip_optional_pointer/containers
Package containers tests skip-optional-pointer on container types.
|
Package containers tests skip-optional-pointer on container types. |
|
test/output_options/skip_prune
Package skip_prune tests skip-prune configuration for unreferenced schemas.
|
Package skip_prune tests skip-prune configuration for unreferenced schemas. |
|
test/parameters/all_styles
Package all_styles tests parameter type generation across all locations and styles.
|
Package all_styles tests parameter type generation across all locations and styles. |
|
test/parameters/any_of
Package any_of tests anyOf and oneOf types used in query parameters, including complex object schemas and primitive type unions.
|
Package any_of tests anyOf and oneOf types used in query parameters, including complex object schemas and primitive type unions. |
|
test/parameters/encoding
Package encoding tests path parameter escaping and special characters.
|
Package encoding tests path parameter escaping and special characters. |
|
test/parameters/precedence
Package precedence tests operation-level parameters overriding path-level parameters.
|
Package precedence tests operation-level parameters overriding path-level parameters. |
|
test/parameters/roundtrip/client
Package client contains the generated client for the parameter roundtrip test.
|
Package client contains the generated client for the parameter roundtrip test. |
|
test/parameters/roundtrip/stdhttp
Package stdhttp contains the std-http server for the parameter roundtrip test.
|
Package stdhttp contains the std-http server for the parameter roundtrip test. |
|
test/request_response/content_types/custom_json
Package custom_json tests custom JSON content types (application/test+json).
|
Package custom_json tests custom JSON content types (application/test+json). |
|
test/request_response/content_types/custom_schema
Package custom_schema tests custom content-type schema handling.
|
Package custom_schema tests custom content-type schema handling. |
|
test/request_response/content_types/multiple
Package multiple tests multiple content types in responses.
|
Package multiple tests multiple content types in responses. |
|
test/webhooks
Package webhooks tests webhook initiator and receiver code generation.
|
Package webhooks tests webhook initiator and receiver code generation. |