Skip to content

Commit

Permalink
Support examples for binary and byte formats
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-tarjanyi authored and frantuma committed Apr 19, 2024
1 parent 502affe commit 8e20f11
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
public class Item {
private String name;
private String value;
@Schema(example = "Ynl0ZQ==")
private byte[] bytes;
@Schema(format = "binary")
@Schema(format = "binary", example = "YmluYXJ5")
private byte[] binary;

public Item() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ components:
bytes:
type: string
format: byte
example: Ynl0ZQ==
binary:
type: string
format: binary
example: YmluYXJ5

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.swagger.v3.oas.models.media;

import java.util.Base64;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -39,6 +40,9 @@ protected byte[] cast(Object value) {
} else {
return value.toString().getBytes();
}
if (value instanceof String) {
return Base64.getDecoder().decode((String) value);
}
} catch (Exception e) {
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.swagger.v3.oas.models.media;

import java.util.Base64;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -39,6 +40,9 @@ protected byte[] cast(Object value) {
} else {
return value.toString().getBytes();
}
if (value instanceof String) {
return Base64.getDecoder().decode((String) value);
}
} catch (Exception e) {
}
}
Expand Down

0 comments on commit 8e20f11

Please sign in to comment.