Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -743,9 +743,10 @@ public static boolean isByteArraySchema(Schema schema) {

public static boolean isBinarySchema(Schema schema) {
return (schema instanceof BinarySchema) ||
// format: binary
// format: binary, or contentMediaType: application/octet-stream (OAS 3.1)
(SchemaTypeUtil.STRING_TYPE.equals(getType(schema))
&& SchemaTypeUtil.BINARY_FORMAT.equals(schema.getFormat()));
&& (SchemaTypeUtil.BINARY_FORMAT.equals(schema.getFormat())
|| "application/octet-stream".equals(schema.getContentMediaType())));
}

public static boolean isFileSchema(Schema schema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,21 @@ public void testModelWithPropertiesOnly() {
assertFalse(ModelUtils.isModelWithPropertiesOnly(testSchema));
}

@Test
public void testIsBinarySchemaOAS30FormatBinary() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/binary-schema.yaml");
Schema fileProp = (Schema) ModelUtils.getSchema(openAPI, "UploadBody").getProperties().get("file");
assertTrue(ModelUtils.isBinarySchema(fileProp));
}

@Test
public void testIsBinarySchemaOAS31ContentMediaType() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_1/binary-schema.yaml");
Map<String, Schema> props = ModelUtils.getSchema(openAPI, "UploadBody").getProperties();
assertTrue(ModelUtils.isBinarySchema(props.get("file")));
assertFalse(ModelUtils.isBinarySchema(props.get("image")));
}

@Test
public void getParentNameMultipleInterfacesTest() {
OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/oneOf_innerModel.yaml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
openapi: 3.0.3
info:
title: t
version: 1.0.0
paths:
/upload:
post:
operationId: upload
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/UploadBody'
responses:
'200':
description: ok
components:
schemas:
UploadBody:
type: object
properties:
file:
type: string
format: binary
required:
- file
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
openapi: 3.1.0
info:
title: t
version: 1.0.0
paths:
/upload:
post:
operationId: upload
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/UploadBody'
responses:
'200':
description: ok
components:
schemas:
UploadBody:
type: object
properties:
file:
type: string
contentMediaType: application/octet-stream
image:
type: string
contentMediaType: image/png
required:
- file