Skip to content
This repository was archived by the owner on Feb 15, 2019. It is now read-only.

add support an optional parameter in a query #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Damon-V79
Copy link

Hello!

We want to use optional parameters in an HTTP request, as it described here for pagination. "offset" and "limit" must be optional parameters.

This pull-request adds processing support for not required query parameter (i.e. /items?id=###).

Swagger:

paths:
  # dogs
  /dogs:
    get:
      operationId: getDogs
      produces:
        - application/json
      parameters:
        - name: limit
          in: query
          required: false
          type: integer
          format: int32
        - name: offset
          in: query
          required: false
          type: integer
          format: int32
      responses:
        200:
          schema:
            $ref: "#/definitions/Dogs"

  /just_test:
    get:
      operationId: justTest
      produces:
        - application/json
      parameters:
        - name: default
          in: query
          type: integer
          format: int32
        - name: required
          in: query
          required: true
          type: integer
          format: int32
        - name: optional
          in: query
          required: false
          type: integer
          format: int32
      responses:
        200:
          schema:
            $ref: "#/definitions/Dogs"

Old Scala code:

trait DogsApi extends Service {

    def getDogs(limit: Int, offset: Int): ServiceCall[akka.NotUsed, Dogs]
    def justTest(default: Int, required: Int, optional: Int): ServiceCall[akka.NotUsed, Dogs]

    final override def descriptor: Descriptor = {
        named("dogs").withCalls(
                restCall(Method.GET, "/api/v1.0/dogs?limit&offset", getDogs _),
                restCall(Method.GET, "/api/v1.0/just_test?default&optional&required", justTest _)
        ).withAutoAcl(true)
    }
}

New Scala code:

trait DogsApi extends Service {

    def getDogs(limit: Option[Int], offset: Option[Int]): ServiceCall[akka.NotUsed, Dogs]
    def justTest(default: Option[Int], required: Int, optional: Option[Int]): ServiceCall[akka.NotUsed, Dogs]

    final override def descriptor: Descriptor = {
        named("dogs").withCalls(
                restCall(Method.GET, "/api/v1.0/dogs?limit&offset", getDogs _),
                restCall(Method.GET, "/api/v1.0/just_test?default&optional&required", justTest _)
        ).withAutoAcl(true)
    }
}

Test project.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant