diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/annotations/info/License.java b/api/src/main/java/org/eclipse/microprofile/openapi/annotations/info/License.java index 99c3f561..a23beb70 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/annotations/info/License.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/annotations/info/License.java @@ -40,6 +40,13 @@ **/ String name(); + /** + * The license identifier used for the API. + * + * @return the identifier of the license + **/ + String identifier() default ""; + /** * A URL to the license used for the API. MUST be in the format of a URL. * diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/info/License.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/info/License.java index 7844ec48..b0e73131 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/info/License.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/info/License.java @@ -54,6 +54,33 @@ default License name(String name) { return this; } + /** + * Returns the license identifier for this License instance that is used for the API. + * + * @return the license identifier used for the API + **/ + String getIdentifier(); + + /** + * Sets the license identifier for this License instance that is used for the API. + * + * @param identifier + * the license identifier used for the API + */ + void setIdentifier(String identifier); + + /** + * Sets this License instance's identifier used for the API and returns this instance of License. + * + * @param identifier + * the license identifier used for the API + * @return this License instance + */ + default License identifier(String identifier) { + setIdentifier(identifier); + return this; + } + /** * Returns the URL for this License instance that is used for the API. * diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/apps/petstore/PetStoreApp.java b/tck/src/main/java/org/eclipse/microprofile/openapi/apps/petstore/PetStoreApp.java index 80de4891..92792221 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/apps/petstore/PetStoreApp.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/apps/petstore/PetStoreApp.java @@ -35,7 +35,7 @@ @ApplicationPath("/") @OpenAPIDefinition(info = @Info(title = "Pet Store App", version = "2.0", description = "Pet Store App API", license = @License(name = "Apache 2.0", - url = "http://www.apache.org/licenses/LICENSE-2.0.html"), + identifier = "Apache-2.0"), contact = @Contact(name = "PetStore API Support", url = "https://github.com/eclipse/microprofile-open-api", email = "support@petstore.com"), diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASFactoryErrorTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASFactoryErrorTest.java index 738b1293..b8d6eaaa 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASFactoryErrorTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/OASFactoryErrorTest.java @@ -72,6 +72,13 @@ public void setUrl(String url) { public License url(String url) { return null; } + @Override + public String getIdentifier() { + return null; + } + @Override + public void setIdentifier(String identifier) { + } } @Deployment diff --git a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/PetStoreAppTest.java b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/PetStoreAppTest.java index 2bcfd711..1a021ec7 100644 --- a/tck/src/main/java/org/eclipse/microprofile/openapi/tck/PetStoreAppTest.java +++ b/tck/src/main/java/org/eclipse/microprofile/openapi/tck/PetStoreAppTest.java @@ -47,6 +47,16 @@ public static WebArchive createDeployment() { .addPackages(true, "org.eclipse.microprofile.openapi.apps.petstore"); } + // This test covers basic OpenAPI ingredients like licenses, if something is here instead of tested in the + // AirlinesApp + // It is likely because it is mutually exclusive with something in the AirlinesApp + @Test(dataProvider = "formatProvider") + public void testOpenAPIEssentials(String type) { + ValidatableResponse vr = callEndpoint(type); + + vr.body("info.license.identifier", equalTo("Apache-2.0")); + } + @Test(dataProvider = "formatProvider") public void testSchema(String type) { ValidatableResponse vr = callEndpoint(type);