swaggercodegen/

directory
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2018 License: Apache-2.0

README

Swagger codegen service provider 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

Building and running container '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
Curl commands
  • Create new CDN
$ curl -X POST http://localhost:8080/v1/cdns -d '{"label":"label", "ips":["127.0.0.1"], "hostnames":["www.origin.com"]}'
  • Get info about previously created CDN
$ curl http://localhost:8080/v1/cdns/<CDN_ID>'
  • Update CDN
$ curl -X PUT http://localhost:8080/v1/cdns/<CDN_ID> -d '{"label":"label updated", "ips":["127.0.0.1"], "hostnames":["www.origin.com"]}'
  • Delete exiting CDN
$ curl -X DELETE http://localhost:8080/v1/cdns/<CDN_ID>'
Create swagger-ui
$ 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
Building and running container via make target 'faster approach'

Alternatively, a make target is provided to do the above in one command:

$ cd $GOPATH/github.com/dikhan/terraform-provider-openapi
$ make local-env

This command will bring up the example APIs provided for development purposes.

Running terraform-provider-api against this API

  • Install terraform-provider-api and the symlink for 'swaggercodegen' provider:
$ cd $GOPATH/github.com/dikhan/terraform-provider-openapi/
$ PROVIDER_NAME="swaggercodegen" make install
  • Execute terraform passing the following env variables:
$ cd $GOPATH/github.com/dikhan/terraform-provider-openapi/examples/swaggercodegen/api
$ export OTF_VAR_swaggercodegen_SWAGGER_URL="https://localhost:8443/swagger.yaml" PROVIDER_NAME="swaggercodegen" OTF_INSECURE_SKIP_VERIFY=true && terraform init && terraform plan

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

$ cd $GOPATH/github.com/dikhan/terraform-provider-openapi/
$ make local-env
$ make run-terraform-example-swaggercodegen

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" 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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