Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock API controller function "contacts.addContact()" to handle Swagger defined POST route #2

Open
nfloersch opened this issue Jan 11, 2021 · 2 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@nfloersch
Copy link
Contributor

nfloersch commented Jan 11, 2021

The contacts route in the YAML is defined here:

/contacts/:
    x-swagger-router-controller: contacts
    .
    .
    .
    post:
      summary: Add contact
      description: Creates a new named contact entry for services or organizations
      operationId: addContact

The YAML file defines the route (/contacts), controller (x-swagger-router-controller: contacts), and function name (operationId: listContacts) that will be called for the POST verb.

For the contacts controller, we need to mock up a listContacts() function that takes in the parameters of the function as defined in the YAML, and responds with a JSON object that reflects those values back to the caller.

In the YAML the params are listed as:

      parameters:
        - in: body
          name: body
          schema:
            $ref: '#/definitions/contact'

This can be done fixing the body of this placeholder function located in file:

function addContact(req, res) {
  // variables defined in the Swagger document can be referenced using req.swagger.params.{parameter_name}
  var name = req.swagger.params.name.value || 'stranger';
  var hello = util.format('Hello, %s!', name);

  // this sends back a JSON response which is a single string
  res.json(hello);
}

To see an example solution to a similar problem to get you started, view issue #1

@nfloersch nfloersch added the good first issue Good for newcomers label Jan 11, 2021
@nfloersch nfloersch added this to the Core API Functions Mocked milestone Jan 11, 2021
@iritush iritush self-assigned this Jan 12, 2021
@nfloersch nfloersch changed the title Mock up API controller function "contacts.addContact()" to handle Swagger defined route Mock API controller function "contacts.addContact()" to handle Swagger defined route Jan 12, 2021
@nfloersch nfloersch changed the title Mock API controller function "contacts.addContact()" to handle Swagger defined route Mock API controller function "contacts.addContact()" to handle Swagger defined POST route Jan 14, 2021
@iritush
Copy link
Collaborator

iritush commented Jan 28, 2021

Pushed the following to the development branch: ac5b2f6

@iritush
Copy link
Collaborator

iritush commented Jan 28, 2021

@nfloersch can you review when you get a chance? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants