[RAILS] What to do if you get Swagger-codegen in python and Import Error: No module named

background

swagger-codegen, when you define an API in a particular format, It spits out a library for hitting it in various languages.

It goes well with Rails' Grape, and if I try to hit an API server made with Rails from python, it's the main subject.

problem

As you can see by reading the swagger-codegen code, When creating a file, the file name should be ʻapi_v1_name, but it is generated as ʻapi :: v1:: name, and the file name and the path specified by import mesh well. Is not ... Therefore, I get an Import Error. It's a small mistake, so I think it will be fixed soon, but I want to be able to communicate right away.

approach

So let's override the function and solve it. Regarding override, "So easy! Customize Swagger Codegen" was very helpful.

custom-script.groovy


@Grab('io.swagger:swagger-codegen-cli:2.1.4')
import io.swagger.codegen.*;
import io.swagger.codegen.languages.*;

class MyPythonClientGen extends PythonClientCodegen {

  @Override
  public String toModelFilename(String name){
    return toVarName(name)
  }

  //Kick to CLI
  public static main(String[] args) {
    SwaggerCodegen.main(args)
  }

}
groovy custom-script.groovy generate -i http://example.com/api/v1/swagger_doc -l MyPythonClientGen -o ./api/ 

with this, Files are now generated with ʻapi_v1_name instead of ʻapi :: v1 :: name. If you find it bothersome, you may want to manually rename the file.

Recommended Posts

What to do if you get Swagger-codegen in python and Import Error: No module named
No module named What to do if you get'libs.resources'
What to do if you get a "No versions found" error in pipenv
What to do if you get `No kernel for language python found` in Hydrogen
What to do if you run python in IntelliJ and end with an error
What to do if you get a minus zero in Python
What to do if "amazon-linux-extras" → "No module named amazon_linux_extras"
ModuleNotFoundError: No module What to do if you get'tensorflow.contrib'
What to do if you get an error when installing python with pyenv
What to do if you get "Python not configured." Using PyDev in Eclipse
What to do if you get angry with "Value Error: unknown local: UTF-8" in python manage.py syncdb
What to do if you get the error Target WSGI script'/var/www/xxx/xxx.wsgi' cannot be loaded as python module
What to do if you get "coverage unknown" in Coveralls
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if you get "(35,'SSL connect error')" in pycurl (one of them)
What to do if you get an Import Error when importing matplotlib with Jupyter
Import Error in Python3: No module named'xxxxx'
What to do when ModuleNotFoundError: No module named'XXX' occurs in Python
What to do if you get a Cannot retrieve metalink for repository error in yum
What to do if you get an error when running "certbot renew" in CakePHP environment
What to do if you get the error "Error: opencv3: Does not support building both Python 2 and 3 wrappers" when installing openCV 3
What to do to get google spreadsheet in python
What to do if you can't use scikit grid search in Python
What to do if you get lost in file reference with FileNotFoundError
What to do if you get angry in TensorFlow v2 without attribute'app'
What to do if No Python documentation found for ... appears in pydoc
What to do if you get an error when trying to load mnist
What happens if you do "import A, B as C" in Python?
What to do if you get an error when installing Dlib (Ubuntu)
What to do if you get an error saying c compiler cannot create executables in configure
What to do if you get a must override `get_config` error when trying to model.save in Keras
What to do if you install openCV3 and make a symbolic link, but when you do "import cv2", "No module named'cv2'" appears
[Python] What to do if an error occurs in pip (pyinstaller, pyautogui, etc.)
What to do if you get an error like'Qstring' has already been set to version 1 using mne python
[Python] What to check when you get a Unicode Decode Error in Django
[Python] What to do if you get a ModuleNotFoundError when importing pandas using Jupyter Notebook in Anaconda
What to do if a symbolic link error occurs in import cv while trying to install OpenCV in Python
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup
What to do if you get an "unknown service" error from your gRPC server
What to do if you get a memory error when converting from PySparkDataFrame to PandasDataFrame
What to do if the print command itself causes an error in Maya python
What to do if Sort imports get stuck in VS Code's Python Extension (around 2020/09)
How to install and use pyenv, what to do if you can't switch python versions
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux
What to do if you can't hit the arrow keys in the Python interactive console
What to do if a 0xC0000005 error occurs in tf.train.start_queue_runners ()
What to do if you can't log in as root
ImportError: No module What to do when you are told
What to do if you get a Call with too many input arguments error at DoAndReturn in a golang test
Solution if the module is installed in Python but you get an error in Jupyter notebook
What to do if you get an Undefined error:'Module_six_moves_urllib_parse' object has no attribute'urlencode' on MacOS
If you can't use Beautiful Soup 4 after updating to Python 3.5. ImportError: No module named bs4
What to do if you get an Undefined error when trying to use pip with pyenv
I get "sanity check" and "No module" errors in import numpy
What to do if you can't install pyaudio with pip #Python
What to do if you get a UnicodeDecodeError with pip install
What to do if you can't use the trash in Lubuntu 18.04.
Today's python error: ModuleNotFoundError: No module named
Today's python error: ModuleNotFoundError: No module named
ModuleNotFoundError in Python: No module named story
Module import and exception handling in python