Skip to content

Commit

Permalink
Clean-up - Unnecessary trailing underscores in Python Flask, AIOHttp,…
Browse files Browse the repository at this point in the history
… BluePlanet (#16249)

* Remove trailing underscore in security_controller_.py and base_model_.py

* Regenerating sample files

* Clean-up files with trailing underscore in samples

* Update security extension to use the new security_controller

* Regenerate unmaintained samples
  • Loading branch information
yilmi authored Aug 14, 2023
1 parent 47020f1 commit 931197a
Show file tree
Hide file tree
Showing 91 changed files with 463 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,48 @@

package org.openapitools.codegen.languages;

import static org.openapitools.codegen.utils.StringUtils.camelize;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.CliOption;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenParameter;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.meta.features.DocumentationFeature;
import org.openapitools.codegen.model.ApiInfoMap;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.model.OperationMap;
import org.openapitools.codegen.model.OperationsMap;
import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
Expand All @@ -35,23 +68,6 @@
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.parameters.RequestBody;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.meta.features.DocumentationFeature;
import org.openapitools.codegen.model.ApiInfoMap;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.model.OperationMap;
import org.openapitools.codegen.model.OperationsMap;
import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.*;

import static org.openapitools.codegen.utils.StringUtils.camelize;

public abstract class AbstractPythonConnexionServerCodegen extends AbstractPythonCodegen implements CodegenConfig {
private static class PythonBooleanSerializer extends JsonSerializer<Boolean> {
Expand Down Expand Up @@ -230,9 +246,9 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("util.mustache", packagePath(), "util.py"));
supportingFiles.add(new SupportingFile("typing_utils.mustache", packagePath(), "typing_utils.py"));
supportingFiles.add(new SupportingFile("__init__.mustache", packagePath() + File.separatorChar + packageToPath(controllerPackage), "__init__.py"));
supportingFiles.add(new SupportingFile("security_controller_.mustache", packagePath() + File.separatorChar + packageToPath(controllerPackage), "security_controller_.py"));
supportingFiles.add(new SupportingFile("security_controller.mustache", packagePath() + File.separatorChar + packageToPath(controllerPackage), "security_controller.py"));
supportingFiles.add(new SupportingFile("__init__model.mustache", packagePath() + File.separatorChar + packageToPath(modelPackage), "__init__.py"));
supportingFiles.add(new SupportingFile("base_model_.mustache", packagePath() + File.separatorChar + packageToPath(modelPackage), "base_model_.py"));
supportingFiles.add(new SupportingFile("base_model.mustache", packagePath() + File.separatorChar + packageToPath(modelPackage), "base_model.py"));
supportingFiles.add(new SupportingFile("openapi.mustache", packagePath() + File.separatorChar + "openapi", "openapi.yaml"));
addSupportingFiles();

Expand Down Expand Up @@ -455,7 +471,7 @@ private void addSecurityExtensions(OpenAPI openAPI) {
for (Map.Entry<String, SecurityScheme> securitySchemesEntry : securitySchemes.entrySet()) {
String securityName = securitySchemesEntry.getKey();
SecurityScheme securityScheme = securitySchemesEntry.getValue();
String baseFunctionName = controllerPackage + ".security_controller_.";
String baseFunctionName = controllerPackage + ".security_controller.";
switch (securityScheme.getType()) {
case APIKEY:
addSecurityExtension(securityScheme, "x-apikeyInfoFunc", baseFunctionName + "info_from_" + securityName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
*/
package org.openapitools.codegen.languages;

import java.io.File;
import java.util.EnumSet;

import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.meta.features.*;
import org.openapitools.codegen.meta.features.DocumentationFeature;
import org.openapitools.codegen.meta.features.GlobalFeature;
import org.openapitools.codegen.meta.features.ParameterFeature;
import org.openapitools.codegen.meta.features.SchemaSupportFeature;
import org.openapitools.codegen.meta.features.SecurityFeature;
import org.openapitools.codegen.meta.features.WireFormatFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.EnumSet;

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

Expand Down Expand Up @@ -145,7 +150,7 @@ public void processOpts() {
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}}/models/base_model.mustache", MODEL_PATH, "base_model.py"));

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

Expand Down Expand Up @@ -220,7 +225,7 @@ protected void addSupportingFiles() {
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}}/models/base_model.mustache", MODEL_PATH, "base_model.py"));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from datetime import date, datetime

from typing import List, Dict, Type

from {{modelPackage}}.base_model_ import Model
from {{modelPackage}}.base_model import Model
{{#models}}
{{#model}}
{{#pyImports}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from connexion.apps.flask_app import FlaskJSONEncoder
import six

from {{modelPackage}}.base_model_ import Model
from {{modelPackage}}.base_model import Model


class JSONEncoder(FlaskJSONEncoder):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from datetime import date, datetime # noqa: F401

from typing import List, Dict # noqa: F401

from {{modelPackage}}.base_model_ import Model
from {{modelPackage}}.base_model import Model
{{#imports}}{{import}} # noqa: F401,E501
{{/imports}}
from {{packageName}} import util
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from connexion.apps.flask_app import FlaskJSONEncoder
import six

from {{modelPackage}}.base_model_ import Model
from {{modelPackage}}.base_model import Model


class JSONEncoder(FlaskJSONEncoder):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from datetime import date, datetime # noqa: F401

from typing import List, Dict # noqa: F401

from {{modelPackage}}.base_model_ import Model
from {{modelPackage}}.base_model import Model
{{#models}}
{{#model}}
{{#pyImports}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.dockerignore
.gitignore
.travis.yml
Dockerfile
README.md
git_push.sh
openapi_server/__init__.py
openapi_server/__main__.py
openapi_server/controllers/__init__.py
openapi_server/controllers/pet_controller.py
openapi_server/controllers/security_controller.py
openapi_server/controllers/store_controller.py
openapi_server/controllers/user_controller.py
openapi_server/encoder.py
openapi_server/models/__init__.py
openapi_server/models/api_response.py
openapi_server/models/base_model.py
openapi_server/models/category.py
openapi_server/models/order.py
openapi_server/models/pet.py
openapi_server/models/status_enum.py
openapi_server/models/tag.py
openapi_server/models/user.py
openapi_server/openapi/openapi.yaml
openapi_server/test/__init__.py
openapi_server/typing_utils.py
openapi_server/util.py
requirements.txt
setup.py
test-requirements.txt
tox.ini
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.0-SNAPSHOT
7.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# ref: https://docs.travis-ci.com/user/languages/python
language: python
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM python:2-alpine
FROM python:3-alpine

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY requirements.txt /usr/src/app/

RUN pip install --no-cache-dir -r requirements.txt
RUN pip3 install --no-cache-dir -r requirements.txt

COPY . /usr/src/app

EXPOSE 8080

ENTRYPOINT ["python"]
ENTRYPOINT ["python3"]

CMD ["-m", "openapi_server"]
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ is an example of building a OpenAPI-enabled Flask server.
This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask.

## Requirements
Python 2.7+
Python 3.5.2+

## Usage
To run the server, please execute the following from the root directory:

```
pip install -r requirements.txt
python -m openapi_server
pip3 install -r requirements.txt
python3 -m openapi_server
```

and open your browser to here:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ git add .
git commit -m "$release_note"

# Sets the new remote
git_remote=`git remote`
git_remote=$(git remote)
if [ "$git_remote" = "" ]; then # git remote not defined

if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git
git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
fi

fi
Expand All @@ -55,4 +55,3 @@ git pull origin master
# Pushes (Forces) the changes in the local repository up to the remote repository
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
git push origin master 2>&1 | grep -v 'To https'

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import connexion

Expand All @@ -11,6 +11,7 @@ def main():
app.add_api('openapi.yaml',
arguments={'title': 'OpenAPI Petstore'},
pythonic_params=True)

app.run(port=8080)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import connexion
import six
from typing import Dict
from typing import Tuple
from typing import Union

from openapi_server.models.api_response import ApiResponse # noqa: E501
from openapi_server.models.pet import Pet # noqa: E501
Expand All @@ -17,7 +20,7 @@ def add_pet(pet): # noqa: E501
:param pet: Pet object that needs to be added to the store
:type pet: dict | bytes
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
pet = Pet.from_dict(connexion.request.get_json()) # noqa: E501
Expand All @@ -34,7 +37,7 @@ def delete_pet(pet_id, api_key=None): # noqa: E501
:param api_key:
:type api_key: str
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
return 'do some magic!'

Expand All @@ -47,7 +50,7 @@ def find_pets_by_status(status): # noqa: E501
:param status: Status values that need to be considered for filter
:type status: List[str]
:rtype: List[Pet]
:rtype: Union[List[Pet], Tuple[List[Pet], int], Tuple[List[Pet], int, Dict[str, str]]
"""
return 'do some magic!'

Expand All @@ -60,7 +63,7 @@ def find_pets_by_tags(tags): # noqa: E501
:param tags: Tags to filter by
:type tags: List[str]
:rtype: List[Pet]
:rtype: Union[List[Pet], Tuple[List[Pet], int], Tuple[List[Pet], int, Dict[str, str]]
"""
return 'do some magic!'

Expand All @@ -73,7 +76,7 @@ def get_pet_by_id(pet_id): # noqa: E501
:param pet_id: ID of pet to return
:type pet_id: int
:rtype: Pet
:rtype: Union[Pet, Tuple[Pet, int], Tuple[Pet, int, Dict[str, str]]
"""
return 'do some magic!'

Expand All @@ -86,7 +89,7 @@ def update_pet(pet): # noqa: E501
:param pet: Pet object that needs to be added to the store
:type pet: dict | bytes
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
pet = Pet.from_dict(connexion.request.get_json()) # noqa: E501
Expand All @@ -103,7 +106,7 @@ def update_pet_status_with_enum(pet_id, status): # noqa: E501
:param status: The required status
:type status: dict | bytes
:rtype: Pet
:rtype: Union[Pet, Tuple[Pet, int], Tuple[Pet, int, Dict[str, str]]
"""
if connexion.request.is_json:
status = StatusEnum.from_dict(connexion.request.get_json()) # noqa: E501
Expand All @@ -120,7 +123,7 @@ def update_pet_with_form(pet_id, pet_form=None): # noqa: E501
:param pet_form:
:type pet_form: dict | bytes
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
pet_form = PetForm.from_dict(connexion.request.get_json()) # noqa: E501
Expand All @@ -137,7 +140,7 @@ def upload_file(pet_id, upload_form=None): # noqa: E501
:param upload_form:
:type upload_form: dict | bytes
:rtype: ApiResponse
:rtype: Union[ApiResponse, Tuple[ApiResponse, int], Tuple[ApiResponse, int, Dict[str, str]]
"""
if connexion.request.is_json:
upload_form = UploadForm.from_dict(connexion.request.get_json()) # noqa: E501
Expand Down
Loading

0 comments on commit 931197a

Please sign in to comment.