Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions bin/python-server-blueplanet-petstore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh

SCRIPT="$0"
echo "# START SCRIPT: $SCRIPT"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"

if [ ! -f "$executable" ]
then
mvn -B clean package
fi

generator=python-blueplanet
input=modules/openapi-generator/src/test/resources/2_0/petstore.yaml
out_folder=samples/server/petstore/$generator
resources=modules/openapi-generator/src/main/resources/$generator

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t $resources -i $input -g $generator -o $out_folder -Dservice $@"

rm -rf $out_folder/.openapi*
rm -rf $out_folder/openapi_server
rm -rf $out_folder/tests*
rm $out_folder/README.md
rm $out_folder/requirements.txt
rm $out_folder/test-requirements.txt

java $JAVA_OPTS -jar $executable $ags
1 change: 1 addition & 0 deletions docs/generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ The following generators are available:
- [php-symfony](generators/php-symfony.md)
- [php-ze-ph](generators/php-ze-ph.md)
- [python-aiohttp](generators/python-aiohttp.md)
- [python-blueplanet](generators/python-blueplanet.md)
- [python-flask](generators/python-flask.md)
- [ruby-on-rails](generators/ruby-on-rails.md)
- [ruby-sinatra](generators/ruby-sinatra.md)
Expand Down
19 changes: 19 additions & 0 deletions docs/generators/python-blueplanet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

---
id: generator-opts-server-python-blueplanet
title: Config Options for python-blueplanet
sidebar_label: python-blueplanet
---

| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|packageName|python package name (convention: snake_case).| |openapi_server|
|packageVersion|python package version.| |1.0.0|
|controllerPackage|controller package| |controllers|
|defaultController|default controller| |default_controller|
|supportPython2|support python2| |false|
|serverPort|TCP port to listen to in app.run| |8080|
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openapitools.codegen.languages;

import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.SupportingFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class PythonBluePlanetServerCodegen extends PythonAbstractConnexionServerCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(PythonBluePlanetServerCodegen.class);

protected String modelDocPath = "";
protected String modelTestPath = "";

public PythonBluePlanetServerCodegen() {
super("python-blueplanet", true);
testPackage = "tests";
embeddedTemplateDir = templateDir = "python-blueplanet";
}


/**
* Configures a friendly name for the generator. This will be used by the generator
* to select the library with the -g flag.
*
* @return the friendly name for the generator
*/
@Override
public String getName() {
return "python-blueplanet";
}

@Override
public void processOpts() {
super.processOpts();
//apiTemplateFiles.clear();

if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
} else {
setPackageName("swagger_microservice");
additionalProperties.put(CodegenConstants.PACKAGE_NAME, this.packageName);
}
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION));
} else {
setPackageVersion("1.0.0");
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, this.packageVersion);
}
if (additionalProperties.containsKey(CONTROLLER_PACKAGE)) {
this.controllerPackage = additionalProperties.get(CONTROLLER_PACKAGE).toString();
} else {
this.controllerPackage = "controllers";
additionalProperties.put(CONTROLLER_PACKAGE, this.controllerPackage);
}
if (additionalProperties.containsKey(DEFAULT_CONTROLLER)) {
this.defaultController = additionalProperties.get(DEFAULT_CONTROLLER).toString();
} else {
this.defaultController = "default_controller";
additionalProperties.put(DEFAULT_CONTROLLER, this.defaultController);
}
if (Boolean.TRUE.equals(additionalProperties.get(SUPPORT_PYTHON2))) {
additionalProperties.put(SUPPORT_PYTHON2, Boolean.TRUE);
typeMapping.put("long", "long");
}

String APP_PATH = "app" + File.separatorChar;
String APP_PACKAGE_PATH = APP_PATH + packageName;
String TEST_PATH = APP_PACKAGE_PATH + File.separatorChar + "test";
String MODEL_PATH = APP_PACKAGE_PATH + File.separatorChar + "models";
String CONTROLLER_PATH = APP_PACKAGE_PATH + File.separatorChar + "controllers";
String SOLUTION_PATH = "solution" + File.separatorChar;
String SWAGGER_PATH = APP_PACKAGE_PATH + File.separatorChar + "swagger";

// make solution and app src path available in mustache template
additionalProperties.put("appSrcPath", APP_PATH);
additionalProperties.put("solutionSrcPath", SOLUTION_PATH);
additionalProperties.put("modelDefinitionsSrcPath", modelDocPath);

/*
* Supporting Files. You can write single files for the generator with the
* entire object tree available. If the input file has a suffix of `.mustache
* it will be processed by the template engine. Otherwise, it will be copied
*/

// Root Directory
supportingFiles.add(new SupportingFile("Makefile.mustache", "", "Makefile"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("requirements.mustache", "", "requirements.txt"));

// App Directory
supportingFiles.add(new SupportingFile("app/Dockerfile.mustache", APP_PATH, "Dockerfile"));
supportingFiles.add(new SupportingFile("app/dockerignore.mustache", APP_PATH, ".dockerignore"));
supportingFiles.add(new SupportingFile("app/gitignore.mustache", APP_PATH, ".gitignore"));
supportingFiles.add(new SupportingFile("app/README.mustache", APP_PATH, "README.md"));
supportingFiles.add(new SupportingFile("app/requirements.mustache", APP_PATH, "requirements.txt"));
supportingFiles.add(new SupportingFile("app/setup.mustache", APP_PATH, "setup.py"));
supportingFiles.add(new SupportingFile("app/tox.mustache", APP_PATH, "tox.ini"));
supportingFiles.add(new SupportingFile("app/test-requirements.mustache", APP_PATH, "test-requirements.txt"));

supportingFiles.add(new SupportingFile("app/{{packageName}}/__init__.mustache", APP_PACKAGE_PATH, "__init__.py"));
supportingFiles.add(new SupportingFile("app/{{packageName}}/__main__.mustache", APP_PACKAGE_PATH, "__main__.py"));
supportingFiles.add(new SupportingFile("app/{{packageName}}/encoder.mustache", APP_PACKAGE_PATH, "encoder.py"));
supportingFiles.add(new SupportingFile("app/{{packageName}}/util.mustache", APP_PACKAGE_PATH, "util.py"));

supportingFiles.add(new SupportingFile("app/{{packageName}}/controllers/__init__.mustache", CONTROLLER_PATH, "__init__.py"));

supportingFiles.add(new SupportingFile("app/{{packageName}}/models/__init__.mustache", MODEL_PATH, "__init__.py"));
supportingFiles.add(new SupportingFile("app/{{packageName}}/models/base_model_.mustache", MODEL_PATH, "base_model_.py"));

supportingFiles.add(new SupportingFile("app/{{packageName}}/test/__init__.mustache", TEST_PATH, "__init__.py"));

supportingFiles.add(new SupportingFile("app/{{packageName}}/swagger/swagger.mustache", SWAGGER_PATH, "swagger.yaml"));

// Solution Directory
supportingFiles.add(new SupportingFile("solution/fig.mustache", SOLUTION_PATH, "fig.yml"));

// Dynamically generated file definitions
modelTemplateFiles.remove("model.mustache", ".py");
modelTemplateFiles.put("app/{{packageName}}/models/model.mustache", ".py");
modelPackage = "app." + packageName + ".models";

apiTemplateFiles.remove("controller.mustache", ".py");
apiTemplateFiles.put("app/{{packageName}}/controllers/controller.mustache", ".py");
controllerPackage = "app." + packageName + ".controllers";

apiTestTemplateFiles().remove("controller_test.mustache", ".py");
apiTestTemplateFiles.put("app/{{packageName}}/test/controller_test.mustache", ".py");
testPackage = "app." + packageName + ".test";

// hack: Use ModelDoc to generate tosca files TODO: implement new Java class
modelDocPath = "model-definitions.types.tosca." + packageName;
modelDocTemplateFiles.put("model-definitions/types/tosca/{{packageName}}/{{model}}.mustache", ".tosca");

// hack: Use ModelTest to generate ui files TODO: implement new Java class
modelTestTemplateFiles.put("model-definitions/types/ddui-views/{{packageName}}.resourceTypes.{{model}}/create.mustache", "create.json");
modelTestTemplateFiles.put("model-definitions/types/ddui-views/{{packageName}}.resourceTypes.{{model}}/high.mustache", "high.json");
modelTestTemplateFiles.put("model-definitions/types/ddui-views/{{packageName}}.resourceTypes.{{model}}/low.mustache", "low.json");
modelTestPath = "model-definitions" + File.separator + "types";
}

@Override
protected void addSupportingFiles() {
String APP_PATH = "app" + File.separatorChar;
String APP_PACKAGE_PATH = APP_PATH + packageName;
String TEST_PATH = APP_PACKAGE_PATH + File.separatorChar + "test";
String MODEL_PATH = APP_PACKAGE_PATH + File.separatorChar + "models";
String CONTROLLER_PATH = APP_PACKAGE_PATH + File.separatorChar + "controllers";
String SOLUTION_PATH = "solution" + File.separatorChar;
String SWAGGER_PATH = APP_PACKAGE_PATH + File.separatorChar + "swagger";

// TODO: PythonAbstract should allow override
supportingFiles.clear();

// make solution and app src path available in mustache template
additionalProperties.put("appSrcPath", APP_PATH);
additionalProperties.put("solutionSrcPath", SOLUTION_PATH);
additionalProperties.put("modelDefinitionsSrcPath", modelDocPath);

// Root Directory
supportingFiles.add(new SupportingFile("Makefile.mustache", "", "Makefile"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("requirements.mustache", "", "requirements.txt"));

// App Directory
supportingFiles.add(new SupportingFile("app/Dockerfile.mustache", APP_PATH, "Dockerfile"));
supportingFiles.add(new SupportingFile("app/dockerignore.mustache", APP_PATH, ".dockerignore"));
supportingFiles.add(new SupportingFile("app/gitignore.mustache", APP_PATH, ".gitignore"));
supportingFiles.add(new SupportingFile("app/README.mustache", APP_PATH, "README.md"));
supportingFiles.add(new SupportingFile("app/requirements.mustache", APP_PATH, "requirements.txt"));
supportingFiles.add(new SupportingFile("app/setup.mustache", APP_PATH, "setup.py"));
supportingFiles.add(new SupportingFile("app/tox.mustache", APP_PATH, "tox.ini"));
supportingFiles.add(new SupportingFile("app/test-requirements.mustache", APP_PATH, "test-requirements.txt"));

supportingFiles.add(new SupportingFile("app/{{packageName}}/__init__.mustache", APP_PACKAGE_PATH, "__init__.py"));
supportingFiles.add(new SupportingFile("app/{{packageName}}/__main__.mustache", APP_PACKAGE_PATH, "__main__.py"));
supportingFiles.add(new SupportingFile("app/{{packageName}}/encoder.mustache", APP_PACKAGE_PATH, "encoder.py"));
supportingFiles.add(new SupportingFile("app/{{packageName}}/util.mustache", APP_PACKAGE_PATH, "util.py"));

supportingFiles.add(new SupportingFile("app/{{packageName}}/controllers/__init__.mustache", CONTROLLER_PATH, "__init__.py"));

supportingFiles.add(new SupportingFile("app/{{packageName}}/models/__init__.mustache", MODEL_PATH, "__init__.py"));
supportingFiles.add(new SupportingFile("app/{{packageName}}/models/base_model_.mustache", MODEL_PATH, "base_model_.py"));

supportingFiles.add(new SupportingFile("app/{{packageName}}/test/__init__.mustache", TEST_PATH, "__init__.py"));

supportingFiles.add(new SupportingFile("app/{{packageName}}/swagger/swagger.mustache", SWAGGER_PATH, "swagger.yaml"));

// Solution Directory
supportingFiles.add(new SupportingFile("solution/fig.mustache", SOLUTION_PATH, "fig.yml"));
}

@Override
public String modelDocFileFolder() {
return (outputFolder + File.separator + modelDocPath).replace('.', File.separatorChar);
}

@Override
public String toModelDocFilename( String name ) {
return toModelName( name ) + "_ResourceType";
}

@Override
public String modelTestFileFolder() {
return outputFolder + File.separator + modelTestPath + File.separator + "ddui-views";
}

@Override
public String toModelTestFilename(String name) {
String resourceTypeFolder = packageName + ".resourceTypes." + toModelName(name) + File.separator;
return resourceTypeFolder;
}

/**
* Location to write api files. You can use the apiPackage() as defined when the class is
* instantiated
*/
@Override
public String apiFileFolder() {
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ org.openapitools.codegen.languages.PowerShellClientCodegen
org.openapitools.codegen.languages.PythonClientCodegen
org.openapitools.codegen.languages.PythonFlaskConnexionServerCodegen
org.openapitools.codegen.languages.PythonAiohttpConnexionServerCodegen
org.openapitools.codegen.languages.PythonBluePlanetServerCodegen
org.openapitools.codegen.languages.RClientCodegen
org.openapitools.codegen.languages.RubyClientCodegen
org.openapitools.codegen.languages.RubyOnRailsServerCodegen
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
HIDE ?= @
PACKAGE := {{packageName}}
RELEASE := {{packageVersion}}
VENV := env
PYPI ?= 'https://pypi.blueplanet.com/simple'

PWD ?= $(shell pwd)

# Solution
VENDOR ?= path_to_your_repo
SOLUTION_RELEASE ?= $(shell solmaker version solution/fig.yml)
SOLUTION_NAME ?= $(shell solmaker name solution/fig.yml)
SOLUTION_IMAGE := $(VENDOR)/solution-$(SOLUTION_NAME)

DOCKER_BUILD := docker build
DOCKER_IMAGE ?= $(VENDOR)/$(PACKAGE)
REGISTRY ?= registry.blueplanet.com
REMOTE_SERVER ?= bpadmin@10.10.10.10

SOLUTION := $(REGISTRY).$(VENDOR).$(SOLUTION_NAME):$(SOLUTION_RELEASE)

.PHONY: app solution update upload-solution

app: check-env
$(DOCKER_BUILD) --build-arg GLTOKEN=${GLTOKEN} -t $(REGISTRY)/$(DOCKER_IMAGE):$(RELEASE) -f app/Dockerfile ./app

remote:
docker save $(REGISTRY)/$(DOCKER_IMAGE):$(RELEASE) | bzip2 | pv | ssh $(REMOTE_SERVER) 'bunzip2 | docker load'
docker save $(REGISTRY)/$(SOLUTION_IMAGE):$(SOLUTION_RELEASE) | bzip2 | pv | ssh $(REMOTE_SERVER) 'bunzip2 | docker load'

push:
docker push $(REGISTRY)/$(DOCKER_IMAGE):$(RELEASE)
docker push $(REGISTRY)/$(SOLUTION_IMAGE):$(SOLUTION_RELEASE)

solution: check-env
$(docker rmi $(REGISTRY)/$(SOLUTION_IMAGE):$(SOLUTION_RELEASE) && true)
solmaker build solution/fig.yml --vendor=$(VENDOR) --tag=$(SOLUTION_RELEASE)

upload-solution:
docker save $(REGISTRY)/$(SOLUTION_IMAGE):$(SOLUTION_RELEASE) | bzip2 | pv | ssh $(REMOTE_SERVER) 'bunzip2 | docker load'

update: app solution
-ssh $(REMOTE_SERVER) 'solman "solution_purge -y $(SOLUTION)"'
docker save $(REGISTRY)/$(DOCKER_IMAGE):$(RELEASE) | bzip2 | pv | ssh $(REMOTE_SERVER) 'bunzip2 | docker load'
docker save $(REGISTRY)/$(SOLUTION_IMAGE):$(SOLUTION_RELEASE) | bzip2 | pv | ssh $(REMOTE_SERVER) 'bunzip2 | docker load'
-ssh $(REMOTE_SERVER) 'solman "solution_deploy $(SOLUTION)"'

check-env:
ifndef GLTOKEN
$(error GLTOKEN is undefined)
endif
Loading