org.eclipse.microprofile.openapi.OASFactory Java Examples

The following examples show how to use org.eclipse.microprofile.openapi.OASFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OASFactoryResolverImplTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for
 * {@link OASFactoryResolverImpl#createObject(java.lang.Class)}.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testCreateObject_All() {
    Class modelClasses[] = { APIResponse.class, APIResponses.class, Callback.class, Components.class,
            Contact.class, Content.class, Discriminator.class, Encoding.class, Example.class,
            ExternalDocumentation.class, Header.class, Info.class, License.class, Link.class, MediaType.class,
            OAuthFlow.class, OAuthFlows.class, OpenAPI.class, Operation.class, Parameter.class, PathItem.class,
            Paths.class, RequestBody.class, Schema.class, SecurityRequirement.class,
            SecurityScheme.class, Server.class, ServerVariable.class, Tag.class, XML.class };
    for (Class modelClass : modelClasses) {
        Constructible object = OASFactory.createObject(modelClass);
        Assert.assertNotNull(object);
    }
}
 
Example #2
Source File: OASFactoryResolverImplTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for
 * {@link OASFactoryResolverImpl#createObject(java.lang.Class)}.
 */
@Test
public void testCreateObject_License() {
    License license = OASFactory.createObject(License.class).name("Test License").url("urn:test-url");
    Assert.assertNotNull(license);
    Assert.assertEquals(LicenseImpl.class, license.getClass());
    Assert.assertEquals("Test License", license.getName());
    Assert.assertEquals("urn:test-url", license.getUrl());
}
 
Example #3
Source File: OASFactoryResolverImplTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for
 * {@link OASFactoryResolverImpl#createObject(java.lang.Class)}.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testCreateObject_RTE() {
    Class c = String.class;
    try {
        OASFactory.createObject(c);
        Assert.fail("Expected a runtime error.");
    } catch (RuntimeException e) {
        Assert.assertEquals("SROAP09000: Class 'java.lang.String' is not Constructible.", e.getMessage());
    }
}
 
Example #4
Source File: ModelConstructionTest.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
private <T extends Constructible> T createConstructibleInstance(Class<T> clazz) {
    // Check that the OASFactory is able to create an instance of the given Class.
    final T o1 = OASFactory.createObject(clazz);
    assertNotNull(o1, "The return value of OASFactory.createObject(" + clazz.getName() + ") must not be null.");
    assertTrue(clazz.isInstance(o1), "The return value of OASFactory.createObject() is expected to be an instance of: " + clazz.getName());
    final T o2 = OASFactory.createObject(clazz);
    assertNotNull(o2, "The return value of OASFactory.createObject(" + clazz.getName() + ") must not be null.");
    assertTrue(clazz.isInstance(o2), "The return value of OASFactory.createObject() is expected to be an instance of: " + clazz.getName());
    assertNotSame(o2, o1, "OASFactory.createObject(" + clazz.getName() + ") is expected to create a new object on each invocation.");
    return o1;
}
 
Example #5
Source File: AirlinesOASFilter.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@Override
public PathItem filterPathItem(PathItem pathItem){
    if(pathItem.getGET() != null && "Retrieve all available flights".equals(pathItem.getGET().getSummary())){
        //Add new operation
        pathItem.PUT(OASFactory.createObject(Operation.class).
                summary("filterPathItem - added put operation")
                .responses(OASFactory.createObject(APIResponses.class).addAPIResponse("200", 
                        OASFactory.createObject(APIResponse.class).description("filterPathItem - successfully put airlines"))));
        
        //Spec states : All filterable descendant elements of a filtered element must be called before its ancestor
        //Override the operatioId value that was previously overridden by the filterOperation method
        pathItem.getGET().setOperationId("filterPathItemGetFlights");
    }
    
    if (pathItem.getPOST() != null && "createBooking".equals(pathItem.getPOST().getOperationId())) {
        Map<String, Callback> callbacks = pathItem.getPOST().getCallbacks();
        if (callbacks.containsKey("bookingCallback")) {
            Callback callback = callbacks.get("bookingCallback");
            if (callback.hasPathItem("http://localhost:9080/airlines/bookings")
                    && callback.getPathItem("http://localhost:9080/airlines/bookings").getGET() != null) {
                if ("child - Retrieve all bookings for current user".equals(callback.getPathItem("http://localhost:9080/airlines/bookings")
                        .getGET().getDescription())) {   
                    callback.getPathItem("http://localhost:9080/airlines/bookings").getGET()
                    .setDescription("parent - Retrieve all bookings for current user"); 
                }
            }
        }   
    }
    
    return pathItem;
}
 
Example #6
Source File: HelloModelReader.java    From microprofile1.4-samples with MIT License 4 votes vote down vote up
@Override
public OpenAPI buildModel() {
    return OASFactory.createObject(OpenAPI.class);
}
 
Example #7
Source File: OASFactoryErrorTest.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = { NullPointerException.class })
public void nullValueTest() {
    @SuppressWarnings("unused")
    final Object o = OASFactory.createObject(null);
}
 
Example #8
Source File: OASFactoryErrorTest.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = { IllegalArgumentException.class })
public void baseInterfaceTest() {
    @SuppressWarnings("unused")
    final Constructible c = OASFactory.createObject(Constructible.class);
}
 
Example #9
Source File: OASFactoryErrorTest.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = { IllegalArgumentException.class })
public void extendedBaseInterfaceTest() {
    @SuppressWarnings("unused")
    final MyConstructible m = OASFactory.createObject(MyConstructible.class);
}
 
Example #10
Source File: OASFactoryErrorTest.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = { IllegalArgumentException.class })
public void extendedInterfaceTest() {
    @SuppressWarnings("unused")
    final MyLicense m = OASFactory.createObject(MyLicense.class);
}
 
Example #11
Source File: OASFactoryErrorTest.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = { IllegalArgumentException.class })
public void customAbstractClassTest() {
    @SuppressWarnings("unused")
    final MyAbstractLicenseImpl m = OASFactory.createObject(MyAbstractLicenseImpl.class);
}
 
Example #12
Source File: OASFactoryErrorTest.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = { IllegalArgumentException.class })
public void customClassTest() {
    @SuppressWarnings("unused")
    final MyLicenseImpl m = OASFactory.createObject(MyLicenseImpl.class);
}
 
Example #13
Source File: OpenApiSpecStyleValidatorTest.java    From openapi-style-validator with Apache License 2.0 4 votes vote down vote up
private static OpenAPI createSimplePingOpenAPI() {
    return OASFactory.createOpenAPI()
            .openapi("3.0.1")
            .info(
                    OASFactory.createInfo()
                            .title("Ping Specification")
                            .version("1.0")
                            .license(OASFactory.createLicense()
                                    .name("Eclipse Public License - v2.0")
                                    .url("https://www.eclipse.org/legal/epl-2.0/"))
                            .description("This is a test spec")
                            .contact(
                                    OASFactory.createContact()
                                            .name("OpenAPI Tools")
                                            .email("[email protected]"))
            )
            .addServer(
                    OASFactory.createServer()
                            .url("http://localhost:8000/")
            )
            .paths(
                    OASFactory.createPaths()
                            .addPathItem(
                                    "/ping", OASFactory.createPathItem()
                                            .GET(
                                                    OASFactory.createOperation()
                                                            .operationId("pingGet")
                                                            .summary("A simple get call")
                                                            .description("When this method is called, the server answers with 200 OKs")
                                                            .addTag("demo")
                                                            .responses(
                                                                    OASFactory.createAPIResponses()
                                                                            .addAPIResponse(
                                                                                    "200", OASFactory.createAPIResponse()
                                                                                            .description("OK")
                                                                            )
                                                            )
                                            )
                            )
            );
}
 
Example #14
Source File: OpenApiSpecStyleValidatorTest.java    From openapi-style-validator with Apache License 2.0 4 votes vote down vote up
private static OpenAPI createPingOpenAPI() {
    return OASFactory.createOpenAPI()
            .openapi("3.0.1")
            .info(
                    OASFactory.createInfo()
                            .title("Ping Specification")
                            .version("1.0")
                            .license(OASFactory.createLicense()
                                    .name("Eclipse Public License - v2.0")
                                    .url("https://www.eclipse.org/legal/epl-2.0/"))
                            .description("This is a test spec")
                            .contact(
                                    OASFactory.createContact()
                                            .name("OpenAPI Tools")
                                            .email("[email protected]"))
            )
            .addServer(
                    OASFactory.createServer()
                            .url("http://localhost:8000/")
            )
            .paths(
                    OASFactory.createPaths()
                            .addPathItem(
                                    "/ping", OASFactory.createPathItem()
                                            .GET(
                                                    OASFactory.createOperation()
                                                            .operationId("pingGet")
                                                            .summary("A simple get call")
                                                            .description("When this method is called, the server answers with 200 OKs")
                                                            .addTag("demo")
                                                            .responses(
                                                                    OASFactory.createAPIResponses()
                                                                            .addAPIResponse(
                                                                                    "200", OASFactory.createAPIResponse()
                                                                                            .description("OK")
                                                                            )
                                                            )
                                            )
                            )
                            .addPathItem(
                                    "/ping2", OASFactory.createPathItem()
                                            .GET(
                                                    OASFactory.createOperation()
                                                            .operationId("ping2Get")
                                                            .summary("A get that return an object response")
                                                            .description("When this method is called, the server answers with 200 and a json object as response")
                                                            .addTag("demo")
                                                            .responses(
                                                                    OASFactory.createAPIResponses()
                                                                            .addAPIResponse(
                                                                                    "200", OASFactory.createAPIResponse()
                                                                                    .content(OASFactory.createContent()
                                                                                            .addMediaType("application/json", OASFactory.createMediaType()
                                                                                                    .schema(OASFactory.createSchema()
                                                                                                            .ref("'#/components/schemas/Myobject'")))
                                                                                    )
                                                                                    .description("A second path to test validation of ref examples")
                                                                            )
                                                            )
                                            )
                            )
            ).components(OASFactory
                    .createComponents()
                            .addSchema("Myobject", OASFactory.createSchema()
                                    .type(SchemaType.OBJECT)
                                    .addProperty("name", OASFactory.createSchema()
                                            .type(SchemaType.STRING))
                                    .addProperty("prop1", OASFactory.createSchema()
                                            .type(SchemaType.STRING)
                                            .example("prop 1 description"))
                                    .addProperty("status", OASFactory.createSchema()
                                            .ref("#/components/schemas/Status"))
                            ).addSchema("Status", OASFactory.createSchema()
                                    .type(SchemaType.STRING)
                                    .description("status description")
                                    .example("status example")
                                    .addEnumeration("item1")
                                    .addEnumeration("item2")
                            )

            );
}