Skip to content

Commit

Permalink
Schema annotation new field TCKs
Browse files Browse the repository at this point in the history
Test new parameters on the Schema annotation which don't involve
subschemas.

- comment
- const
- dependentRequired
- contentEncoding
- contentMediaType
  • Loading branch information
Azquelt committed May 7, 2024
1 parent 908a398 commit 5660eba
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 5 deletions.
Expand Up @@ -115,7 +115,8 @@
type = SchemaType.ARRAY,
implementation = Airline.class,
extensions = @Extension(name = "x-schema",
value = "test-schema")),
value = "test-schema"),
comment = "This is an airline"),
@Schema(name = "id", type = SchemaType.INTEGER, format = "int32"),
@Schema(name = "AirlinesRef",
ref = "#/components/schemas/Airlines"),
Expand Down
Expand Up @@ -13,9 +13,19 @@

package org.eclipse.microprofile.openapi.apps.airlines.model;

import org.eclipse.microprofile.openapi.annotations.media.Schema;
import java.time.LocalDate;

@Schema(maxProperties = 1024, minProperties = 1, requiredProperties = {"id", "username", "password"})
import org.eclipse.microprofile.openapi.annotations.media.DependentRequired;
import org.eclipse.microprofile.openapi.annotations.media.DependentSchema;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.media.Schema.False;
import org.eclipse.microprofile.openapi.annotations.media.Schema.True;

@Schema(maxProperties = 1024, minProperties = 1,
requiredProperties = {"id", "username", "password"},
dependentRequired = @DependentRequired(name = "frequentFlyerNumber",
requires = {"frequentFlyerProgrammeName", "frequentFlyerStartDate"}),
dependentSchemas = @DependentSchema(name = "forbiddenField", schema = False.class))
public class User {

@Schema(example = "3456")
Expand Down Expand Up @@ -51,6 +61,22 @@ public class User {
@Schema(hidden = true)
private String undocumentedProperty;

private String frequentFlyerNumber;

private String frequentFlyerProgrammeName;

private LocalDate frequentFlyerStartDate;

@Schema(constValue = "true")
private boolean human;

/** Base64 encoded JPEG photo */
@Schema(contentEncoding = "base64", contentMediaType = "image/jpeg")
private String photo;

@Schema(implementation = True.class)
private Object freeformNotes;

/**
* Creates a User instance with the parameters specified.
*
Expand Down Expand Up @@ -290,4 +316,52 @@ public void setUndocumentedProperty(String undocumentedProperty) {
this.undocumentedProperty = undocumentedProperty;
}

public String getFrequentFlyerNumber() {
return frequentFlyerNumber;
}

public void setFrequentFlyerNumber(String frequentFlyerNumber) {
this.frequentFlyerNumber = frequentFlyerNumber;
}

public String getFrequentFlyerProgrammeName() {
return frequentFlyerProgrammeName;
}

public void setFrequentFlyerProgrammeName(String frequentFlyerProgrammeName) {
this.frequentFlyerProgrammeName = frequentFlyerProgrammeName;
}

public LocalDate getFrequentFlyerStartDate() {
return frequentFlyerStartDate;
}

public void setFrequentFlyerStartDate(LocalDate frequentFlyerStartDate) {
this.frequentFlyerStartDate = frequentFlyerStartDate;
}

public String getPhoto() {
return photo;
}

public void setPhoto(String photo) {
this.photo = photo;
}

public boolean getHuman() {
return human;
}

public void setHuman(boolean human) {
this.human = human;
}

public Object getFreeformNotes() {
return freeformNotes;
}

public void setFreeformNotes(Object freeformNotes) {
this.freeformNotes = freeformNotes;
}

}
Expand Up @@ -700,6 +700,7 @@ public void testSchema(String type) {
// Basic properties
vr.body("components.schemas.AirlinesRef.$ref", equalTo("#/components/schemas/Airlines"));
vr.body("components.schemas.Airlines.title", equalTo("Airlines"));
vr.body("components.schemas.Airlines.$comment", equalTo("This is an airline"));
vr.body("components.schemas.Airlines.x-schema", equalTo("test-schema"));
vr.body("paths.'/bookings'.post.responses.'201'.content.'application/json'.schema.type",
itemOrSingleton("string"));
Expand All @@ -714,6 +715,17 @@ public void testSchema(String type) {
vr.body("components.schemas.User.required", hasItems("id", "username", "password")); // requiredProperties
vr.body("components.schemas.User", not(hasItem("undocumentedProperty"))); // hidden property
vr.body("components.schemas.Gender.enum", hasItems("Male", "Female", "Other"));
vr.body("components.schemas.User.dependentRequired", aMapWithSize(1));
vr.body("components.schemas.User.dependentRequired.frequentFlyerNumber",
contains("frequentFlyerProgrammeName", "frequentFlyerStartDate"));
String photoPath = dereference(vr, "components.schemas.User.properties.photo");
vr.body(photoPath + ".contentEncoding", equalTo("base64"));
vr.body(photoPath + ".contentMediaType", equalTo("image/jpeg"));
String humanPath = dereference(vr, "components.schemas.User.properties.human");
vr.body(humanPath + ".const", equalTo(true));
vr.body("components.schemas.User.properties.freeformNotes", equalTo(true));
vr.body("components.schemas.User.dependentSchemas", aMapWithSize(1));
vr.body("components.schemas.User.dependentSchemas.forbiddenField", equalTo(false));

// Array properties
String createSchema = "paths.'/user/createWithArray'.post.requestBody.content.'application/json'.schema";
Expand All @@ -727,7 +739,7 @@ public void testSchema(String type) {
@Test(dataProvider = "formatProvider")
public void testSchemaProperty(String type) {
ValidatableResponse vr = callEndpoint(type);
vr.body("components.schemas.User.properties", IsMapWithSize.aMapWithSize(10));
vr.body("components.schemas.User.properties", IsMapWithSize.aMapWithSize(16));
vr.body("components.schemas.User.properties.phone.examples", contains("123-456-7891"));
vr.body("components.schemas.User.properties.phone.description",
equalTo("Telephone number to contact the user"));
Expand All @@ -737,7 +749,7 @@ public void testSchemaProperty(String type) {
@Test(dataProvider = "formatProvider")
public void testSchemaPropertyValuesOverrideClassPropertyValues(String type) {
ValidatableResponse vr = callEndpoint(type);
vr.body("components.schemas.User.properties", IsMapWithSize.aMapWithSize(10));
vr.body("components.schemas.User.properties", IsMapWithSize.aMapWithSize(16));
vr.body("components.schemas.User.properties.phone.examples", not(contains("123-456-7890")));
vr.body("components.schemas.User.properties.phone.examples", contains("123-456-7891"));
}
Expand Down

0 comments on commit 5660eba

Please sign in to comment.