SmartBear / readyapi-swagger-plugin

Ready! API Plugin for importing Swagger definitions as REST Services
36 stars 27 forks source link

Read default value of a swagger "parameter" object and populate the relevant request parameter value. #66

Open wxdave opened 5 years ago

wxdave commented 5 years ago

Example swagger given below. The goal is to read the value foovalue specified for the default parameter of foo, assuming default is in a logical location.

paths:
  /foo-path:
    parameters:
      - $ref: '#/parameters/foo'
    get:
      description: Get a foo    
...
definitions:
...

parameters:
  foo:
    name: foo
    in: query
    required: true
    type: string
    default: foovalue

This would require some magic in AbstractSwagger1XImporter.groovy, assuming complex types (object) would need to be handled in some way. (see line 119 in the below image).

image

The result is that the query parameter's value is populated for all requests (swagger paths) that reference the parameter, as shown below.

image

wxdave commented 5 years ago
    <con:resource name="/resource-path" path="/" id="...">
      <con:settings/>
      <con:parameters>
        <con:parameter required="true">
          <con:name>foo</con:name>
          <con:style>QUERY</con:style>
          <con:description>the foo query parameter</con:description>
          <con:value>foovalue</con:value>
        </con:parameter>
      </con:parameters>
...

as defined by schema

    <xsd:complexType name="RestResource">
        <xsd:complexContent>
            <xsd:extension base="tns:ModelItem">
                <xsd:sequence>
                    <xsd:element name="parameters" type="tns:RestParameters">
                    </xsd:element>
                    <xsd:element name="request" type="tns:OldRestRequest"
                                 maxOccurs="unbounded" minOccurs="0">
                    </xsd:element>

                    <xsd:element name="resource" type="tns:RestResource"
                                 maxOccurs="unbounded" minOccurs="0">
                    </xsd:element>

                    <xsd:element name="method" type="tns:RestMethod"
                                 maxOccurs="unbounded" minOccurs="0"></xsd:element>
                </xsd:sequence>
                <xsd:attribute name="path" type="xsd:string"></xsd:attribute>
                <xsd:attribute name="wadlId" type="xsd:string"></xsd:attribute>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>