Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f4884c4
fix: verify Schema object getTypes() is not null or empty
K5qu4r3d Sep 24, 2025
debfed1
fix: add type values to all PrimitiveType JSON schemas
K5qu4r3d Sep 24, 2025
7c0a6af
fix: remove "type" and "types" value declarations from OBJECT enum
K5qu4r3d Sep 25, 2025
4baa804
Revert "fix: remove "type" and "types" value declarations from OBJECT…
K5qu4r3d Sep 26, 2025
e8cfe79
fix: fix existing test cases
K5qu4r3d Sep 26, 2025
5c655c6
Merge branch 'master' into bug/4963-fix-schema-primitive-boxed-type-cast
K5qu4r3d Sep 29, 2025
02179c1
fix: fix existing test cases pt. 2
K5qu4r3d Sep 30, 2025
23253a2
fix: update access modifier of class PrimitiveType.DateStub
K5qu4r3d Sep 30, 2025
26ab407
test: add test cases for updated OpenAPI 3.1 "type"/"types" value sch…
K5qu4r3d Oct 3, 2025
ecb8929
fix: update type values for date/time 3.1 schemas
K5qu4r3d Oct 3, 2025
b7791fa
Merge branch 'master' into bug/4963-fix-schema-primitive-boxed-type-cast
K5qu4r3d Oct 7, 2025
e4d7b45
fix: add "LocalTime" class mappings for PARTIAL_TIME
K5qu4r3d Oct 7, 2025
75bc935
fix: remove duplicate "LocalTime" model from expected YAML
K5qu4r3d Oct 7, 2025
935dacd
fix: convert APIResponsesResourceTest to parameterized test
K5qu4r3d Oct 8, 2025
1e1711a
Merge branch 'master' into bug/4963-fix-schema-primitive-boxed-type-cast
daniel-kmiecik Oct 10, 2025
1f0d050
Merge branch 'master' into bug/4963-fix-schema-primitive-boxed-type-cast
daniel-kmiecik Oct 14, 2025
cecddf1
fix: remove unnecessary comment
K5qu4r3d Nov 3, 2025
e6beba3
fix: remove enablePartialTime() call
K5qu4r3d Nov 3, 2025
c0da882
fix: rename variable for clarity
K5qu4r3d Nov 3, 2025
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 @@ -951,7 +951,10 @@ public static Schema resolveSchemaFromType(Class<?> schemaImplementation, Compon
existingSchemaObject = reResolvedSchema.get();
}
}
if (StringUtils.isBlank(existingSchemaObject.get$ref()) && StringUtils.isBlank(existingSchemaObject.getType())) {
boolean doesSchemaHaveNullOrEmptyTypes = existingSchemaObject.getTypes() == null || existingSchemaObject.getTypes().isEmpty();
if (StringUtils.isBlank(existingSchemaObject.get$ref())
&& StringUtils.isBlank(existingSchemaObject.getType())
&& doesSchemaHaveNullOrEmptyTypes) {
// default to string
existingSchemaObject.setType("string");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("string");
return new JsonSchema().typesItem("string").type("string");
}
},
BOOLEAN(Boolean.class, "boolean") {
Expand All @@ -48,7 +48,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("boolean");
return new JsonSchema().typesItem("boolean").type("boolean");
}
},
BYTE(Byte.class, "byte") {
Expand All @@ -63,7 +63,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("string").format("byte");
return new JsonSchema().typesItem("string").type("string").format("byte");
}
},
BINARY(Byte.class, "binary") {
Expand All @@ -78,7 +78,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("string").format("binary");
return new JsonSchema().typesItem("string").type("string").format("binary");
}
},
URI(java.net.URI.class, "uri") {
Expand All @@ -88,7 +88,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("string").format("uri");
return new JsonSchema().typesItem("string").type("string").format("uri");
}
},
URL(java.net.URL.class, "url") {
Expand All @@ -98,7 +98,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("string").format("url");
return new JsonSchema().typesItem("string").type("string").format("url");
}
},
EMAIL(String.class, "email") {
Expand All @@ -108,7 +108,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("string").format("email");
return new JsonSchema().typesItem("string").type("string").format("email");
}
},
UUID(java.util.UUID.class, "uuid") {
Expand All @@ -118,7 +118,7 @@ public UUIDSchema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("string").format("uuid");
return new JsonSchema().typesItem("string").type("string").format("uuid");
}
},
INT(Integer.class, "integer") {
Expand All @@ -128,7 +128,7 @@ public IntegerSchema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("integer").format("int32");
return new JsonSchema().typesItem("integer").type("integer").format("int32");
}
},
LONG(Long.class, "long") {
Expand All @@ -138,7 +138,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("integer").format("int64");
return new JsonSchema().typesItem("integer").type("integer").format("int64");
}
},
FLOAT(Float.class, "float") {
Expand All @@ -148,7 +148,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("number").format("float");
return new JsonSchema().typesItem("number").type("number").format("float");
}
},
DOUBLE(Double.class, "double") {
Expand All @@ -158,7 +158,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("number").format("double");
return new JsonSchema().typesItem("number").type("number").format("double");
}
},
INTEGER(java.math.BigInteger.class) {
Expand All @@ -168,7 +168,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("integer");
return new JsonSchema().typesItem("integer").type("integer");
}
},
DECIMAL(java.math.BigDecimal.class, "number") {
Expand All @@ -178,7 +178,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("number");
return new JsonSchema().typesItem("number").type("number");
}
},
NUMBER(Number.class, "number") {
Expand All @@ -188,7 +188,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("number");
return new JsonSchema().typesItem("number").type("number");
}
},
DATE(DateStub.class, "date") {
Expand All @@ -198,7 +198,7 @@ public DateSchema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("string").format("date");
return new JsonSchema().typesItem("object").type("object").format("date");
}
},
DATE_TIME(java.util.Date.class, "date-time") {
Expand All @@ -208,7 +208,7 @@ public DateTimeSchema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("string").format("date-time");
return new JsonSchema().typesItem("object").type("object").format("date-time");
}
},
PARTIAL_TIME(java.time.LocalTime.class, "partial-time") {
Expand All @@ -218,7 +218,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("string").format("partial-time");
return new JsonSchema().typesItem("object").type("object").format("partial-time");
}
},
FILE(java.io.File.class, "file") {
Expand All @@ -228,7 +228,7 @@ public FileSchema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema().typesItem("string").format("binary");
return new JsonSchema().typesItem("string").type("string").format("binary");
}
},
OBJECT(Object.class) {
Expand All @@ -239,7 +239,7 @@ public Schema createProperty() {
}
@Override
public Schema createProperty31() {
return new JsonSchema();
return new JsonSchema().typesItem("object").type("object");
}
};

Expand Down Expand Up @@ -572,7 +572,7 @@ private static <K> void addMultiKeys(Map<K, Collection<PrimitiveType>> map, Prim
}
}

private static class DateStub {
public static class DateStub {
private DateStub() {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,6 @@ public void testLocalTime() throws Exception {

ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);

Schema model = context
.resolve(new AnnotatedType(TestObject2992.class));

SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "LocalTime:\n" +
" type: object\n" +
" properties:\n" +
" hour:\n" +
" type: integer\n" +
" format: int32\n" +
" minute:\n" +
" type: integer\n" +
" format: int32\n" +
" second:\n" +
" type: integer\n" +
" format: int32\n" +
" nano:\n" +
" type: integer\n" +
" format: int32\n" +
"TestObject2992:\n" +
" type: object\n" +
" properties:\n" +
" name:\n" +
" type: string\n" +
" a:\n" +
" $ref: \"#/components/schemas/LocalTime\"\n" +
" b:\n" +
" $ref: \"#/components/schemas/LocalTime\"\n" +
" c:\n" +
" $ref: \"#/components/schemas/LocalTime\"\n" +
" d:\n" +
" type: string\n" +
" format: date-time\n" +
" e:\n" +
" type: string\n" +
" format: date-time\n" +
" f:\n" +
" type: string\n" +
" format: date-time");

PrimitiveType.enablePartialTime();
context = new ModelConverterContextImpl(modelResolver);

context
.resolve(new AnnotatedType(TestObject2992.class));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public void testOAS31Fields() {
" type: number\n" +
" status:\n" +
" type:\n" +
" - object\n" +
" - string\n" +
" - number\n" +
" intValue:\n" +
Expand Down Expand Up @@ -160,7 +161,8 @@ public void testOAS31Fields() {
" creditCard:\n" +
" $ref: \"#/components/schemas/CreditCard\"\n" +
" properties:\n" +
" extraObject: {}\n" +
" extraObject: \n" +
" type: object\n" +
"MultipleBaseBean:\n" +
" type: object\n" +
" description: MultipleBaseBean\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void testOAS31JavaRecord() {
" type: number\n" +
" Status:\n" +
" type:\n" +
" - object\n" +
" - string\n" +
" - number\n";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.swagger.v3.jaxrs2;

import io.swagger.v3.jaxrs2.resources.APIResponsesResource;
import io.swagger.v3.oas.integration.SwaggerConfiguration;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.Schema;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import static org.testng.AssertJUnit.assertEquals;

public class APIResponsesResourceTest {
private OpenAPI openAPI;

// Prepare list of resource schema URLs
@DataProvider(name = "schemas")
public String[] getSchemas() {
return new String[] {
"/postStringOrEmailSchemaContent",
"/postBooleanSchemaContent",
"/postByteOrBinarySchemaContent",
"/postURISchemaContent",
"/postURLSchemaContent",
"/postUUIDSchemaContent",
"/postIntegerSchemaContent",
"/postLongSchemaContent",
"/postFloatSchemaContent",
"/postDoubleSchemaContent",
"/postBigIntegerSchemaContent",
"/postBigDecimalSchemaContent",
"/postNumberSchemaContent",
"/postDateStubSchemaContent",
"/postDateSchemaContent",
"/postLocalTimeSchemaContent",
"/postFileSchemaContent",
"/postObjectSchemaContent"
};
}

@BeforeMethod
public void setUp() {
SwaggerConfiguration config = new SwaggerConfiguration().openAPI31(true);
Reader reader = new Reader(config);
openAPI = reader.read(APIResponsesResource.class);
}

private Schema getResponseSchema(String path) {
Operation postOperation = openAPI.getPaths().get(path).getPost();
return postOperation.getResponses().get("200").getContent().get("*/*").getSchema();
}

@Test(dataProvider = "schemas")
public void testSchemaAPIResource31(String schema) {
Schema responseSchema = getResponseSchema(schema);

// Value of field "type" must equal value of field "types"
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3569,6 +3569,7 @@ public void testOas31Petstore() {
" name:\n" +
" type: string\n" +
" annotated:\n" +
" type: object\n" +
" $ref: \"#/components/schemas/Category\"\n" +
" description: child description\n" +
" properties:\n" +
Expand Down Expand Up @@ -3623,6 +3624,7 @@ public void test31RefSiblings() {
" type: object\n" +
" properties:\n" +
" annotated:\n" +
" type: \"object\"\n" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide at least on test with 'null' in type

Copy link
Author

@K5qu4r3d K5qu4r3d Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the new test case, do we want "null" type for SimpleTag class or its annotated property? Sorry if I'm looking at this incorrectly.

" $ref: \"#/components/schemas/SimpleCategory\"\n" +
" description: child description\n" +
" properties:\n" +
Expand Down Expand Up @@ -4006,6 +4008,7 @@ public void testMisc31() {
" type: number\n" +
" status:\n" +
" type:\n" +
" - object\n" +
" - string\n" +
" - number\n" +
" intValue:\n" +
Expand Down Expand Up @@ -4085,6 +4088,7 @@ public void testMisc31() {
" type: object\n" +
" properties:\n" +
" country:\n" +
" type: object\n" +
" const: United States\n" +
" CreditCard:\n" +
" type: object\n" +
Expand All @@ -4095,11 +4099,13 @@ public void testMisc31() {
" type: object\n" +
" properties:\n" +
" postalCode:\n" +
" type: object\n" +
" pattern: \"[0-9]{5}(-[0-9]{4})?\"\n" +
" PostalCodePattern:\n" +
" type: object\n" +
" properties:\n" +
" postalCode:\n" +
" type: object\n" +
" pattern: \"[A-Z][0-9][A-Z] [0-9][A-Z][0-9]\"\n" +
" PropertyNamesPattern:\n" +
" pattern: \"^[A-Za-z_][A-Za-z0-9_]*$\"\n";
Expand Down
Loading