swaggercodegen/

directory
v0.29.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2020 License: Apache-2.0

README

Swagger codegen OpenAPI Example

This example was created using swagger-codegen tool. Using the generator we have created a service provider that exposes a resource for managing 'CDNs' allowing the consumer to create and read CDNs.

Overview

This server was generated by the swagger-codegen project.
By using the OpenAPI-Spec from a remote server, you can easily generate a server stub.

To see how to make this your own, look here:

README

  • API version: 0.0.1
  • Build date: 2017-10-28T10:56:37.853-07:00

Running the example swaggercodegen API

This service is fully OpenAPI Terraform compliant and the swagger document can be found here.

Using make target 'faster approach'

A make target is provided to bring up the API service running in a docker container:

$ cd $GOPATH/github.com/dikhan/terraform-provider-openapi
$ DC_SERVICE=swaggercodegen-service-provider-api make local-env

Similarly, a local-env-down is provided to shutdown the service:

$ make local-env-down
Manual approach

A dockerfile is provided to run the example in a container:

  • To build the container:
$ cd $GOPATH/github.com/dikhan/terraform-provider-openapi/examples/swaggercodegen/api
$ docker build -t swaggercodegen-service-provider-api .
  • To run the container:
$ docker run -p 8080:80 -p 8443:443 swaggercodegen-service-provider-api
Create swagger-ui

This example also includes a docker container that contains a a simple web app that exposes the swagger UI for the swaggercodegen example.

$ cd $GOPATH/github.com/dikhan/terraform-provider-openapi/examples/swaggercodegen/api
$ docker run -p 8082:8080 -e SWAGGER_JSON=/app/resources/swagger.yaml -v $(pwd):/app  swaggerapi/swagger-ui

Installing 'swaggercodegen' OpenAPI Terraform provider

The following command will build the OpenAPI Terraform provider and install the terraform-provider-swaggercodegen terraform provider plugin in Terraform's plugin installation directory:

$ cd $GOPATH/github.com/dikhan/terraform-provider-openapi/
$ PROVIDER_NAME="swaggercodegen" make install

Running Terraform

Now that the terraform-provider-swaggercodegen plugin is installed, we can go ahead and execute terraform passing the following env variables or if using the plugin configuration file the env variables won't be needed:

$ cd $GOPATH/github.com/dikhan/terraform-provider-openapi/examples/swaggercodegen/api
$ terraform init && OTF_VAR_swaggercodegen_SWAGGER_URL="https://localhost:8443/swagger.yaml" PROVIDER_NAME="swaggercodegen" OTF_INSECURE_SKIP_VERIFY=true terraform plan

Below is an output of the terraform execution:


$ cd $GOPATH/github.com/dikhan/terraform-provider-openapi/examples/swaggercodegen
$ terraform init && OTF_VAR_swaggercodegen_SWAGGER_URL="https://localhost:8443/swagger.yaml" OTF_INSECURE_SKIP_VERIFY=true terraform plan

Initializing provider plugins...

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  + swaggercodegen_cdns_v1.my_cdn
      id:              <computed>
      example_boolean: "true"
      example_int:     "12"
      example_number:  "1.12"
      hostnames.#:     "1"
      hostnames.0:     "origin.com"
      ips.#:           "1"
      ips.0:           "127.0.0.1"
      label:           "label"


Plan: 1 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

Running Terraform using make

Alternatively, a make target is also provided to achieve the same output by executing the following command:

$ cd $GOPATH/github.com/dikhan/terraform-provider-openapi/
$ TF_CMD=plan make run-terraform-example-swaggercodegen

The above command will:

  • Compile, build and install the terraform-provider-swaggercodegen terraform provider
  • Bring up the API service running in the docker container
  • Execute the Terraform command specified with the TF_CMD variable against the main.tf containing a resource provided by the goa service.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL