Gaurav Shukla Gaurav Shukla - 1 month ago 12
Node.js Question

Microservice communication which are created using Swagger

I am working on creating a micro-service environment in which micro-services created using node ,python,dot net etc. needs to communicate with each other. All the services will be of RESTFUL web-services and it will expose a URL with supporting http / https methods (GET, POST, PUT, DELETE).
for achieving the above explained scenario I


  • created couple of micro-services using node and communicate between them.

  • then I copy pasted YAML file into swagger editor (Please see below for YAML file content) and generated python equivalent code of that webservice.
    but i could not make it work as it started giving the following error:

    Failed to add operation for X-SWAGGER-PIPE //swagger
    Traceback (most recent call last):
    File "C:\Program Files (x86)\Python35-32\connexion\api.py", line 131, in add_paths
    self.add_operation(method, path, endpoint)
    File "C:\Program Files (x86)\Python35-32\connexion\api.py", line 112, in add_operation
    parameter_definitions=self.parameter_definitions)
    File "C:\Program Files (x86)\Python35-32\connexion\operation.py", line 74, in __init__
    self.operation_id = operation['operationId']
    TypeError: string indices must be integers
    Failed to add operation for X-SWAGGER-ROUTER-CONTROLLER //hellopoolmanager
    Traceback (most recent call last):
    File "C:\Program Files (x86)\Python35-32\connexion\api.py", line 131, in add_paths
    self.add_operation(method, path, endpoint)
    File "C:\Program Files (x86)\Python35-32\connexion\api.py", line 112, in add_operation
    parameter_definitions=self.parameter_definitions)
    File "C:\Program Files (x86)\Python35-32\connexion\operation.py", line 74, in __init__
    self.operation_id = operation['operationId']
    TypeError: string indices must be integers
    Traceback (most recent call last):
    File "app.py", line 8, in <module>
    app.run(port=8080)
    TypeError: run() got an unexpected keyword argument 'port'



Also when I tried with already given sample named as 'default.yaml' it started giving error as

c:\Users\20073010\Downloads\python-flask-server-generated (1)\python-flask-server>python app.py
Traceback (most recent call last):
File "app.py", line 8, in <module>
app.run(port=8080)
TypeError: run() got an unexpected keyword argument 'port'


How should I trace the origin of the error and what should be the better way to debug micro-services written in SWAGGER?

YAML file content :

swagger: "2.0"
info:
version: "0.0.1"
title: Hello World App
# during dev, should point to your local machine
host: localhost:10010
# basePath prefixes all resource paths
basePath: /
#
schemes:
# tip: remove http to make production-grade
- http
- https
# format of bodies a client can send (Content-Type)
consumes:
- application/json
# format of the responses to the client (Accepts)
produces:
- application/json
paths:
/hellopoolmanager:
# binds a127 app logic to a route
x-swagger-router-controller: hellopoolmanager
get:
description: Returns 'Hello' to the caller
# used as the method name of the controller
operationId: hellopoolmanager
parameters:
- name: message
in: query
description: The name of the person to whom to say hello
required: false
type: string
responses:
"200":
description: Success
schema:
# a pointer to a definition
$ref: "#/definitions/HelloWorldResponse"
# responses may fall through to errors
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
/swagger:
x-swagger-pipe: swagger_raw
# complex objects have schema definitions
definitions:
HelloWorldResponse:
required:
- message
properties:
message:
type: string
ErrorResponse:
required:
- message
properties:
message:
type: string

Answer

Ok I figured out what was wrong with most of the errors. Basically, if you go to editor.swagger.io and create a new yaml file and generate python flask code from there then all the errors gets resolved except one which is:

 Traceback (most recent call last):                                                                                    
  File "app.py", line 8, in <module>                                                                                  
    app.run(port=8080)                                                                                                
TypeError: run() got an unexpected keyword argument 'port' 

this error is because the generated code is putting port number in 'app.run()'. if I remove port details from 'app.run()' then its working fine on default port 5000 . Now, my question is, can anybody help me out in putting the port number into app.run() ?

Comments