Module: Apiwork::Export

Defined in:
lib/apiwork/export.rb,
lib/apiwork/export/zod.rb,
lib/apiwork/export/base.rb,
lib/apiwork/export/sorbus.rb,
lib/apiwork/export/apiwork.rb,
lib/apiwork/export/open_api.rb,
lib/apiwork/export/pipeline.rb,
lib/apiwork/export/registry.rb,
lib/apiwork/export/zod_mapper.rb,
lib/apiwork/export/type_script.rb,
lib/apiwork/export/sorbus_mapper.rb,
lib/apiwork/export/type_analysis.rb,
lib/apiwork/export/apiwork_mapper.rb,
lib/apiwork/export/pipeline/writer.rb,
lib/apiwork/export/surface_resolver.rb,
lib/apiwork/export/type_script_mapper.rb

Defined Under Namespace

Classes: Apiwork, ApiworkMapper, Base, OpenAPI, Pipeline, Registry, Sorbus, SorbusMapper, SurfaceResolver, TypeAnalysis, TypeScript, TypeScriptMapper, Zod, ZodMapper

Class Method Summary collapse

Class Method Details

.find(name) ⇒ Class<Export::Base>?

Finds an export by name.

Examples:

Apiwork::Export.find(:openapi)

Parameters:

  • name (Symbol)

    The export name.

Returns:

See Also:



36
37
38
39
40
41
42
43
# File 'lib/apiwork/export.rb', line 36

delegate :clear!,
:exists?,
:find,
:find!,
:keys,
:register,
:values,
to: Registry

.find!(name) ⇒ Class<Export::Base>

Finds an export by name.

Examples:

Apiwork::Export.find!(:openapi)

Parameters:

  • name (Symbol)

    The export name.

Returns:

Raises:

  • (KeyError)

    if the export is not found

See Also:



36
37
38
39
40
41
42
43
# File 'lib/apiwork/export.rb', line 36

delegate :clear!,
:exists?,
:find,
:find!,
:keys,
:register,
:values,
to: Registry

.generate(export_name, api_base_path, format: nil, key_format: nil, locale: nil, **options) ⇒ String

Generates an export for an API.

Examples:

Apiwork::Export.generate(:openapi, '/api/v1')
Apiwork::Export.generate(:openapi, '/api/v1', format: :yaml)
Apiwork::Export.generate(:typescript, '/api/v1', key_format: :camel)

Parameters:

  • export_name (Symbol)

    The registered export name. Built-in: ‘:openapi`, `:typescript`, `:zod`.

  • api_base_path (String)

    The API base path.

  • format (Symbol, nil) (defaults to: nil)

    (nil) [:json, :yaml] The output format. Hash exports only.

  • key_format (Symbol, nil) (defaults to: nil)

    (nil) [:camel, :kebab, :keep, :pascal, :underscore] The key format.

  • locale (Symbol, nil) (defaults to: nil)

    (nil) The locale for translations.

  • options

    Export-specific keyword arguments.

Returns:

  • (String)

Raises:

See Also:



68
69
70
71
# File 'lib/apiwork/export.rb', line 68

def generate(export_name, api_base_path, format: nil, key_format: nil, locale: nil, **options)
  export_class = find!(export_name)
  export_class.generate(api_base_path, format:, key_format:, locale:, **options)
end

.register(klass) ⇒ Object

Registers an export.

Examples:

Apiwork::Export.register(JSONSchemaExport)

Parameters:

  • klass (Class<Export::Base>)

    The export class with export_name set.

See Also:



36
37
38
39
40
41
42
43
# File 'lib/apiwork/export.rb', line 36

delegate :clear!,
:exists?,
:find,
:find!,
:keys,
:register,
:values,
to: Registry

.register_defaults!Object



73
74
75
76
77
78
79
# File 'lib/apiwork/export.rb', line 73

def register_defaults!
  register(Apiwork)
  register(OpenAPI)
  register(TypeScript)
  register(Zod)
  register(Sorbus)
end