Skip to content
Open
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 @@ -173,6 +173,13 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
type = _mapper.constructType(annotatedType.getType());
}

// EARLY special handling for OpenAPI 3.1 and byte[]: treat as array of primitive items
if (openapi31 && type.getRawClass().isArray() && type.getRawClass().getComponentType() == byte.class) {
ArraySchema arraySchema = new ArraySchema().items(PrimitiveType.BYTE.createProperty31());
arraySchema.specVersion(SpecVersion.V31);
return arraySchema;
}

final Annotation resolvedSchemaOrArrayAnnotation = AnnotationsUtils.mergeSchemaAnnotations(annotatedType.getCtxAnnotations(), type);
final io.swagger.v3.oas.annotations.media.Schema resolvedSchemaAnnotation =
resolvedSchemaOrArrayAnnotation == null ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("string").format("byte");
return new JsonSchema().typesItem("integer");
}
},
BINARY(Byte.class, "binary") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package io.swagger.v3.core.resolving.v31;

import io.swagger.v3.core.converter.AnnotatedType;
import io.swagger.v3.core.converter.ModelConverterContextImpl;
import io.swagger.v3.core.jackson.ModelResolver;
import io.swagger.v3.core.matchers.SerializationMatchers;
import io.swagger.v3.core.resolving.SwaggerTestBase;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import org.testng.annotations.Test;

import java.util.Map;

public class ByteObjectOAS31Test extends SwaggerTestBase {

@Test(description = "Test ByteObject schema generation with OAS 3.1")
public void testByteObjectSchemaOAS31() {
final ModelResolver modelResolver = new ModelResolver(mapper()).openapi31(true);
ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);

io.swagger.v3.oas.models.media.Schema model = context.resolve(new AnnotatedType(ByteObject.class));

Map<String, io.swagger.v3.oas.models.media.Schema> definedModels = context.getDefinedModels();

SerializationMatchers.assertEqualsToYaml31(definedModels, "ByteObject:\n" +
" type: object\n" +
" properties:\n" +
" primitiveWithoutSchema:\n" +
" type: integer\n" +
" writeOnly: true\n" +
" primitiveWithSchema:\n" +
" type: integer\n" +
" writeOnly: true\n" +
" primitiveWithSchemaTypeAndFormat:\n" +
" type: integer\n" +
" writeOnly: true\n" +
" primitiveArrayWithoutSchema:\n" +
" type: array\n" +
" items:\n" +
" type: integer\n" +
" writeOnly: true\n" +
" primitiveArrayWithSchema:\n" +
" type: array\n" +
" items:\n" +
" type: integer\n" +
" writeOnly: true"
);
}

public static class ByteObject {

private byte primitiveWithoutSchema;

@Schema
private byte primitiveWithSchema;

@Schema(
type = "string",
format = "byte"
)
private byte primitiveWithSchemaTypeAndFormat;

private byte[] primitiveArrayWithoutSchema;

@ArraySchema(
schema = @Schema(
type = "string",
format = "byte"
)
)
private byte[] primitiveArrayWithSchema;

public byte primitiveWithoutSchema() {
return primitiveWithoutSchema;
}

public byte primitiveWithSchema() {
return primitiveWithSchema;
}

public byte primitiveWithSchemaTypeAndFormat() {
return primitiveWithSchemaTypeAndFormat;
}

public void setPrimitiveWithoutSchema(byte primitiveWithoutSchema) {
this.primitiveWithoutSchema = primitiveWithoutSchema;
}

public void setPrimitiveWithSchema(byte primitiveWithSchema) {
this.primitiveWithSchema = primitiveWithSchema;
}

public void setPrimitiveWithSchemaTypeAndFormat(byte primitiveWithSchemaTypeAndFormat) {
this.primitiveWithSchemaTypeAndFormat = primitiveWithSchemaTypeAndFormat;
}

public byte[] primitiveArrayWithoutSchema() {
return primitiveArrayWithoutSchema;
}

public void setPrimitiveArrayWithoutSchema(byte[] primitiveArrayWithoutSchema) {
this.primitiveArrayWithoutSchema = primitiveArrayWithoutSchema;
}

public byte[] primitiveArrayWithSchema() {
return primitiveArrayWithSchema;
}

public void setPrimitiveArrayWithSchema(byte[] primitiveArrayWithSchema) {
this.primitiveArrayWithSchema = primitiveArrayWithSchema;
}
}
}