23

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?

0

1 Answer 1

21

You must set type: string and format: byte

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.