Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define byte array in OpenAPI 3.0

I'm migrating my API from Swagger 2.0 to OpenAPI 3.0. In a DTO I have a field specified as a byte array. Swagger definition of the DTO:

Job:
   type: object
   properties:
       body:
         type: string
         format: binary

Using the definition above the swagger code generator generates an object that accepts byte[] array as the body field new Job().setBody(new byte[1]).

After converting the API definition to OpenAPI the definition for that object stayed the same but the openapi code generator now requires org.springframework.core.io.Resource instead of byte[] (new Job().setBody(org.springframework.core.io.Resource)). There are some places in my code where I have to serialize the Job object but it's no longer possible because Resource doesn't implement serializable.

As a workaround I changed the type to object:

Job:
   type: object
   properties:
       body:
         type: object

Now I have to cast the body to String and then convert to byte[] everywhere and I'd rather have the type as byte[] as it was before.

How can I specify the type as byte[] using OpenAPI 3.0?

like image 621
Michael Dz Avatar asked Jul 08 '20 12:07

Michael Dz


1 Answers

You must set type: string and format: byte

Original answer: when using swagger codegen getting 'List<byte[]>' instead of simply 'byte[]'

like image 71
user8496353 Avatar answered Sep 17 '22 15:09

user8496353