Base
Base class for exports.
Subclass this to create custom export formats. Declare output type and override #generate to produce output.
Example: Hash export (supports json/yaml)
class OpenAPI < Apiwork::Export::Base
export_name :openapi
output :hash
def generate
{ openapi: '3.1.0', ... } # Returns Hash
end
endExample: String export (fixed format)
class ProtobufExport < Apiwork::Export::Base
export_name :protobuf
output :string
file_extension '.proto'
def generate
"syntax = \"proto3\";\n..." # Returns String
end
end
# Register the export
Apiwork::Export.register(ProtobufExport)Class Methods
.export_name
.export_name(name = nil)
The name for this export.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol, nil | nil | The export name. |
Returns
Symbol, nil
.file_extension
.file_extension(value = nil)
The file extension for this export.
Only applies to string exports. Hash exports derive extension from format.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value | String, nil | nil | The file extension (e.g., '.ts'). |
Returns
String, nil
.option
.option(name, type:, default: nil, enum: nil, &block)
Defines a configuration option.
For nested options, use type: :hash with a block. Inside the block, call option to define child options.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | Symbol | The option name. | |
type | Symbol<:boolean, :hash, :integer, :string, :symbol> | The option type. | |
default | Object, nil | nil | The default value. |
enum | Array, nil | nil | The allowed values. |
Returns
void
See also
Example: Symbol option
option :locale, type: :symbol, default: :enExample: String option with enum
option :version, type: :string, default: '5', enum: %w[4 5]Example: Nested options
option :pagination, type: :hash do
option :strategy, type: :symbol, default: :offset, enum: %i[offset cursor]
option :default_size, type: :integer, default: 20
option :max_size, type: :integer, default: 100
end.output
.output(type = nil)
The output for this export.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
type | Symbol<:hash, :string>, nil | nil | The output type. :hash for Hash output (json/yaml), :string for String output. |
Returns
Symbol, nil
Instance Methods
#api
#api
The API introspection for this export.
Primary interface for accessing introspection data in export generators.
Returns
See also
#generate
#generate
Generates the export output.
Override this method in subclasses to produce the export format. Access API data via the #api method which provides typed access to types, enums, resources, actions, and other introspection data.
Returns
Hash, String
See also
#key_format
#key_format
The key format for this export.
Returns
Symbol
#transform_key
#transform_key(key)
Transforms a key according to the configured key format.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | String, Symbol | The key to transform. |
Returns
String
See also