title: ServiceStack: OpenApi import in Azure Api Management Gateway
body: <p>We are running a Dotnet Core 2.2 service using ServiceStack 5.7, and need to throttle it. So we want to put it behind a Azure Api Management Gateway (apim) - it runs in a Azure App Service.</p>
  
  <p>We have enabled OpenApi feature using</p>
  
  <blockquote>
    <p>self.Plugins.Add(new OpenApiFeature());</p>
  </blockquote>
  
  <p>When we export our OpenApi definition we get the following: </p>
  
  <pre><code>"paths": {
   ...
          "/api/search": {
              "post": {
                  "tags": [
                      "api"
                  ],
                  "operationId": "SearchRequestsearch_Post",
                  "consumes": [
                      "application/x-www-form-urlencoded"
                  ],
                  "produces": [
                      "application/json"
                  ],
                  "parameters": [
                      {
                          "name": "Filters",
                          "in": "formData",
                          "type": "array",
                          "items": {
                              "$ref": "#/definitions/FilterDto"
                          },
                          "collectionFormat": "multi",
                          "required": false
                      }
                  ],
                  "responses": {
                      "200": {
                          "description": "Success",
                          "schema": {
                              "$ref": "#/definitions/SearchResponse"
                          }
                      }
                  },
                  "deprecated": false,
                  "security": [
                      {
                          "Bearer": []
                      }
                  ]
              },
  
              "parameters": [
                  {
                      "$ref": "#/parameters/Accept"
                  }
              ]
          }
      }
   ...
  "definitions": {
    "FilterDto": {
              "title": "FilterDto",
              "properties": {
                  "Field": {
                      "description": "The field to filter on",
                      "type": "string",
                      "enum": [
                          "None",
                          "DestinationName",
                          "DocumentId"
                      ]
                  },
                  "Values": {
                      type": "array",
                      "items": {
                          "type": "string"
                      }
                  },
                  "Type": {
                      "type": "string",
                      "enum": [
                          "Equals",
                          "NotEquals",
                          "RangeNumeric",
                          "RangeDate"
                      ]
                  }
              },
              "description": "FilterDto",
              "type": "object"
          }
          ...
  }
  </code></pre>
  
  <p>The problem is that it is not supported to have a parameter with an array of a type (defined in #/definitions/FilterDto). And it fails with:
   Parsing error(s): JSON is valid against no schemas from 'oneOf'. Path 'paths['/api/search'].post.parameters[1]', line 1, position 666.
  Parsing error(s): The input OpenAPI file is not valid for the OpenAPI specificate <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md" rel="nofollow noreferrer">https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md</a> (schema <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json" rel="nofollow noreferrer">https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json</a>).</p>
  
  <p>In the Azure portal.</p>
  
  <p>In c# (ServiceStack) we have defined the following:</p>
  
  <pre><code>public class SearchRequest : SearchRequestBase, IReturn&lt;SearchResponse&gt;
      {
          public SearchRequest()
          {
              Filters = new List&lt;FilterDto&gt;();
          }
  
          [ApiMember(Name = "Filters"]
          public List&lt;FilterDto&gt; Filters { get; set; }
      }
  
  public class FilterDto
      {
          [ApiMember(Name = "Field"]
          [ApiAllowableValues("Field", typeof(FilterAndFacetField))] 
          public FilterAndFacetField Field { get; set; }
  
          [ApiMember(Name = "Values")]
          public List&lt;string&gt; Values { get; set; }
  
          [ApiMember(Name = "Type")]
          [ApiAllowableValues("Type", typeof(FilterType))]
          public FilterType Type { get; set; }
  
          public FilterDto()
          {
              Values = new List&lt;string&gt;();
          }
      }
  </code></pre>
  
  <p>Have anyone successfully managed to import a OpenApi using array of $ref in the parameters from ServiceStack into a Api Management? </p>