Skip to content

SwaggerProvider and byte array  #46

@ghost

Description

Description

The provider does not generate the correct types for format : byte

Repro steps

The following JSON can be used to show the problem, note the testBytes property on the TestDirect type.

{
  "swagger": "2.0",
  "info": {
    "version": "v1",
    "title": "My API"
  },
  "host": "localhost:48213",
  "schemes": [ "http" ],
  "paths": {
    "/api/add": {
      "post": {
        "tags": [ "Tx" ],
        "operationId": "Control_AddApp",
        "consumes": [ "application/json", "text/json", "application/x-www-form-urlencoded", "application/bson" ],
        "produces": [ "application/json", "text/json", "application/xml", "text/xml", "application/bson" ],
        "parameters": [
          {
            "name": "input",
            "in": "body",
            "required": true,
            "schema": { "$ref": "#/definitions/TestDirect" }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "schema": { "type": "boolean" }
          }
        },
        "deprecated": false
      }
    }
  },
  "definitions": {
    "TestDirect": {
      "type": "object",
      "properties": {
        "testBytes": {
          "format": "byte",
          "type": "string"
        }
      }
    }
  }
}

Saving the above JSON to a file, and referencing it like so:

type test = SwaggerProvider< @"C:\Users\user\Desktop\test.json" >
let f e = 
    let a = test.TestDirect()
    a.TestBytes <- e

Hovering over the parameter e shows that the type is string. Additionally, if we view the binary after compilation using ILSpy, we get the following:

...
    // Properties
    .property instance string TestBytes()
    {
        .custom instance void [Newtonsoft.Json]Newtonsoft.Json.JsonPropertyAttribute::.ctor(string) = (
            01 00 09 74 65 73 74 42 79 74 65 73 00 00
        )
        .get instance string test.Client/test/TestDirect::get_TestBytes()
        .set instance void test.Client/test/TestDirect::set_TestBytes(string)
    }

Expected behavior

It is expected that the 'TestBytes' property should allow for byte[].

Known workarounds

Unfortunately there is no workaround apart from not using SwaggerProvider for the API calls that require byte arrays.

Related information

paket.lock:

    SwaggerProvider (0.5.3)
      Newtonsoft.Json (>= 9.0.1)
      YamlDotNet (>= 3.9)
    Swashbuckle.Core (5.4)
      Microsoft.AspNet.WebApi.Core (>= 4.0.20710)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions