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.listContactsComplete()" to handle Swagger defined GET route #4

Closed
nfloersch opened this issue Jan 12, 2021 · 0 comments · Fixed by #17
Assignees
Labels
good first issue Good for newcomers

Comments

@nfloersch
Copy link
Contributor

nfloersch commented Jan 12, 2021

The contacts/complete route in the YAML is defined here:

/contacts/complete/:
   x-swagger-router-controller: contacts
    get:
      summary: Get all contacts with full details
      description: Returns a list of contacts with full details and filtering support
      operationId: listContactsComplete

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

For the contacts controller, we need to mock up a listContactsComplete() 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: query
          type: string
          name: query
          description: A query to filter list by (up to provider to determine what to search)
        - in: query
          type: string
          name: queries
          description: A comma separate list of queries with specific fields.
        - in: query
          type: number
          name: page
          default: 0
          description: The particular page of results.
        - in: query
          type: number
          name: per_page
          default: 25
          description: Number of records to return per page, up to 100.
        - in: query
          type: string
          name: sort_by
          default: name
          description: Which field to sort by.
        - in: query
          type: string
          name: order
          default: asc
          description: Which order to sort by (asc,desc).

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

function listContactsComplete(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 12, 2021
@nfloersch nfloersch added this to the Core API Functions Mocked milestone Jan 12, 2021
@nfloersch nfloersch changed the title Mock API controller function "contacts.listContactsComplete()" to handle Swagger defined route Mock API controller function "contacts.listContactsComplete()" to handle Swagger defined GET route Jan 14, 2021
@kad1001 kad1001 self-assigned this Mar 23, 2021
@kad1001 kad1001 mentioned this issue Apr 14, 2021
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

Successfully merging a pull request may close this issue.

2 participants