0

Seem to almost have it...

Trying to have swagger send an anonymous hash of parameters in the request body.

I have an anonymous hash containing one key named list that contains an array.

Trying to send this parameter (text/json):

{
    list : [ 'string1', 'string2' ]
}

Swagger is building the right curl statement but is not sending the parameters via the UI.

Swagger builds this (works from command line):

/usr/bin/curl -H 'Content-Type: text/json' -X GET -d '{ "list" : [ "text:/export/home/ihome/perl5/our_modules/check_parse_lib_rest/t/data/hosts:/export/home/ihome/perl5/our_modules/check_parse_lib_rest/t/data/hosts", "text:/export/home/ihome/perl5/our_modules/check_parse_lib_rest/t/data/hosts:/export/home/ihome/perl5/our_modules/check_parse_lib_rest/t/data/hosts.1" ] }' 'https://localhost.localdomain:9086/library/check_diff_batch'

But Swagger-ui shows no model example and sends no parameters in the request body.

In the editor I see it the list shows as undefined.

Schema
 ⇄  
Comparison {
list:
ComparisonList undefined *
} 

Definition -

paths:
  /check_diff_batch:
    get:
      summary: Compare a list of file comparrison objects using diff.
      description: |
        FIXME: Takes an array of colon delimited comparrison objects.
        Required parameter Comparrison object format = type:file1:file2
        **RC** will return false if there are differences or a failure.
        **FAULT_MSG** will return No Faults or a failure message.
      parameters:
         - $ref: "#/parameters/ComparrisonList"
      responses:
        200:
          description: Successful response
          examples:
            text/json:
                ...

parameters:
    ComparrisonList:
      name: list
      in: body
      description: List of comparrison objects
      schema:
        $ref: "#/definitions/Comparisons"

definitions:
  Comparisons:
    required:
      - list
    properties:
      list:
        $ref: "#/definitions/ComparisonList"

  ComparisonList:
    additionalProperties:
      type: string

1 Answers1

0

additionalProperties is used to define associative arrays / hashmaps, not regular arrays. A regular string array is defined as:

definitions:
  ComparisonList:
    type: array
    items:
      type: string

You should also use a post operation and not get, since request body in GET does not have defined semantics as per RFC 7231 section 4.3.1.

Community
  • 1
  • 1
Helen
  • 87,344
  • 17
  • 243
  • 314
  • Thanks Helen. Seems, I looked at a simplified definition of what methods should be used for what types of REST requests. Should have used POST all along like I usually do. Funny how I always find the reasons why I normally do things one way, when I try to do them another way. – Scott Wares Mar 21 '17 at 16:25