anz-bank / sysl-go

Communication library used by SYSL-generated code written in Go.
Apache License 2.0
10 stars 14 forks source link

Add support for arrays in query param #218

Closed cuminandpaprika closed 4 years ago

cuminandpaprika commented 4 years ago

Please do not post any internal, closed source snippets on this public issue tracker!

Purpose

One of our users have asked for us to support arrays in their query params, as it is needed to support queries passed to one of their downstream systems.

This means they require both support for both server and client code which handles array query parameters

e.g A call is made tobff/customers?1,2,3,4 which must be passed on to downstream/customers?1,2,3,4

Example OpenAPI3 spec file

openapi: "3.0.0"
info:
  title: Simple
paths:
  /test/:
    get:
      responses:
        200:
          description: 200 OK
      parameters:
        - name: key
          description: something
          schema:
            example:
              - "a,b,c"
            type: array
            items: 
              type: string
          style: form
          explode: false
          required: true
          in: query

Currently, this produces the following sysl from the importer

##########################################
##                                      ##
##  AUTOGENERATED CODE -- DO NOT EDIT!  ##
##                                      ##
##########################################

testArray "Simple":
    @description =:
        | No description.

    /test:
        GET ?key={key}:
            | No description.
            return ok

    #---------------------------------------------------------------------------
    # definitions

    !alias key:
        sequence of string

Suggested approaches

What have you tried, and how might this problem be solved?

This means that Sysl needs to represent information regarding how the parameter should be serialised/ deserialised, as well as whether the parameter should be exploded.

A full implementation would include full support of the various ways of serialising parameters listed in the link below

The use of a URL template library would be a recommended approach https://github.com/jtacoma/uritemplates

style | explode | URI template | Primitive value id = 5 | Array id = [3, 4, 5] | Object id = {"role": "admin", "firstName": "Alex"}
-- | -- | -- | -- | -- | --
simple * | false * | /users/{id} | /users/5 | /users/3,4,5 | /users/role,admin,firstName,Alex
simple | true | /users/{id*} | /users/5 | /users/3,4,5 | /users/role=admin,firstName=Alex
label | false | /users/{.id} | /users/.5 | /users/.3,4,5 | /users/.role,admin,firstName,Alex
label | true | /users/{.id*} | /users/.5 | /users/.3.4.5 | /users/.role=admin.firstName=Alex
matrix | false | /users/{;id} | /users/;id=5 | /users/;id=3,4,5 | /users/;id=role,admin,firstName,Alex
matrix | true | /users/{;id*} | /users/;id=5 | /users/;id=3;id=4;id=5 | /users/;role=admin;firstName=Alex

Taken from https://swagger.io/docs/specification/serialization/#uri-templates

Basic support would just involve parsing the parameter when an array type is specified, assuming the string separator is used This is the default assumption made for OpenAPI3 specs and should apply generally to Sysl and be documented

Basic Support

Full Support