Class: ThreeScaleToolbox::Commands::ImportCommand::OpenAPI::CreateActiveDocsStep

Inherits:
Object
  • Object
show all
Includes:
Step
Defined in:
lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb

Instance Attribute Summary

Attributes included from Step

#context

Instance Method Summary collapse

Methods included from Step

#api_spec, #backend_api_host_header, #backend_api_secret_token, #base_path, #build_3scale_operations, #default_credentials_userkey, #initialize, #oidc_issuer_endpoint, #operations, #override_private_base_url, #override_private_basepath, #override_public_basepath, #prefix_matching, #private_base_path, #production_public_base_url, #public_base_path, #resource, #service, #service=, #staging_public_base_url, #target_system_name, #threescale_client

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/3scale_toolbox/commands/import_command/openapi/create_activedocs_step.rb', line 8

def call
  active_doc = {
    name: api_spec.title,
    system_name: activedocs_system_name,
    service_id: service.id,
    body: JSON.pretty_generate(rewritten_openapi),
    description: api_spec.description,
    published: context[:activedocs_published],
    skip_swagger_validations: context[:skip_openapi_validation]
  }

  res = threescale_client.create_activedocs(active_doc)
  # Make operation indempotent
  if (errors = res['errors'])
    raise ThreeScaleToolbox::Error, "ActiveDocs has not been created. #{errors}" \
      unless ThreeScaleToolbox::Helper.system_name_already_taken_error? errors

    # if activedocs system_name exists, ignore error, update activedocs
    puts 'Activedocs exists, update!'
    update_res = threescale_client.update_activedocs(find_activedocs_id, active_doc)
    raise ThreeScaleToolbox::Error, "ActiveDocs has not been updated. #{update_res['errors']}" unless update_res['errors'].nil?
  end
end