@@ -18,7 +18,10 @@ class Service(DriverService):
1818 * **file:** The name of you swagger yaml file. The default value is `swagger.yaml`
1919 * **url:** The url where swagger run in your server. The default value is `/ui/`.
2020 * **project_dir:** Relative path of the project folder to automatic routing,
21- see [this link for more info](https://github.com/zalando/connexion#automatic-routing). The default value is `project`
21+ see [this link for more info](https://github.com/zalando/connexion#automatic-routing).
22+ The default value is `project`
23+
24+ All default values keys are created as class attributes in `DriverService`
2225 """
2326 service = "swagger"
2427 default_values = {
@@ -29,16 +32,48 @@ class Service(DriverService):
2932 }
3033
3134 def init_app (self , config , path ):
35+ """
36+ Initialize Connexion App. See more info in [Connexion Github](https://github.com/zalando/connexion)
37+ :param config: The Flask configuration defined in the config.yaml:
38+ ```yaml
39+ pyms:
40+ services:
41+ requests: true
42+ swagger:
43+ path: ""
44+ file: "swagger.yaml"
45+ config: <!--
46+ DEBUG: true
47+ TESTING: false
48+ APP_NAME: "Python Microservice"
49+ APPLICATION_ROOT: ""
50+ ```
51+ :param path: The current path where is instantiated Microservice class:
52+ ```
53+ Microservice(path=__file__)
54+ ^^^^--- This param
55+ ```
56+ :return: Flask
57+ """
3258 check_package_exists ("connexion" )
59+ specification_dir = self .path
60+ if not os .path .isabs (self .path ):
61+ specification_dir = os .path .join (path , self .path )
62+
3363 app = connexion .App (__name__ ,
34- specification_dir = os . path . join ( path , self . path ) ,
64+ specification_dir = specification_dir ,
3565 resolver = RestyResolver (self .project_dir ))
36- app .add_api (
37- self .file ,
38- arguments = {'title' : config .APP_NAME },
39- base_path = config .APPLICATION_ROOT ,
40- options = {"swagger_url" : self .url }
41- )
66+
67+ params = {
68+ "specification" : self .file ,
69+ "arguments" : {'title' : config .APP_NAME },
70+ "options" : {"swagger_url" : self .url },
71+ }
72+ # Fix Connexion issue https://github.com/zalando/connexion/issues/1135
73+ if config .APPLICATION_ROOT and config .APPLICATION_ROOT != "/" :
74+ params ["base_path" ] = config .APPLICATION_ROOT
75+
76+ app .add_api (** params )
4277 # Invert the objects, instead connexion with a Flask object, a Flask object with
4378 application = app .app
4479 application .connexion_app = app
0 commit comments