Search in sources :

Example 21 with Schema

use of org.eclipse.microprofile.openapi.models.media.Schema in project Payara by payara.

the class ContentImpl method merge.

public static void merge(ContentImpl from, Content to, boolean override, ApiContext context) {
    if (from == null) {
        return;
    }
    for (Map.Entry<String, MediaType> fromEntry : from.getMediaTypes().entrySet()) {
        final String typeName = fromEntry.getKey();
        final MediaType fromMediaType = fromEntry.getValue();
        // Get or create the corresponding media type
        MediaTypeImpl toMediaType = (MediaTypeImpl) to.getMediaTypes().getOrDefault(typeName, new MediaTypeImpl());
        to.addMediaType(typeName, toMediaType);
        // Merge encoding
        for (Map.Entry<String, Encoding> encoding : fromMediaType.getEncoding().entrySet()) {
            EncodingImpl.merge(encoding.getKey(), encoding.getValue(), toMediaType.encoding, override, context);
        }
        // Merge examples
        for (Map.Entry<String, Example> example : fromMediaType.getExamples().entrySet()) {
            ExampleImpl.merge(example.getKey(), example.getValue(), toMediaType.examples, override);
        }
        toMediaType.setExample(mergeProperty(toMediaType.getExample(), fromMediaType.getExample(), override));
        // Merge schema
        if (fromMediaType.getSchema() != null) {
            if (toMediaType.getSchema() == null) {
                toMediaType.setSchema(new SchemaImpl());
            }
            Schema schema = toMediaType.getSchema();
            SchemaImpl.merge(fromMediaType.getSchema(), schema, true, context);
        }
    }
}
Also used : Example(org.eclipse.microprofile.openapi.models.examples.Example) Schema(org.eclipse.microprofile.openapi.models.media.Schema) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) Encoding(org.eclipse.microprofile.openapi.models.media.Encoding) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 22 with Schema

use of org.eclipse.microprofile.openapi.models.media.Schema in project Payara by payara.

the class ComponentsImpl method merge.

public static void merge(Components from, Components to, boolean override, ApiContext context) {
    if (from == null) {
        return;
    }
    // Handle @Schema
    if (from.getSchemas() != null) {
        for (Entry<String, Schema> fromEntry : from.getSchemas().entrySet()) {
            final String schemaName = fromEntry.getKey();
            if (schemaName != null) {
                final Schema fromSchema = fromEntry.getValue();
                final Schema toSchema = to.getSchemas().getOrDefault(schemaName, new SchemaImpl());
                SchemaImpl.merge(fromSchema, toSchema, override, context);
                to.addSchema(schemaName, toSchema);
            }
        }
    }
    // Handle @Callback
    if (from.getCallbacks() != null) {
        for (String callbackName : from.getCallbacks().keySet()) {
            if (callbackName != null) {
                Callback newCallback = new CallbackImpl();
                CallbackImpl.merge(from.getCallbacks().get(callbackName), newCallback, override, context);
                to.addCallback(callbackName, newCallback);
            }
        }
    }
    // Handle @ExampleObject
    if (from.getExamples() != null) {
        for (String exampleName : from.getExamples().keySet()) {
            if (exampleName != null) {
                Example newExample = new ExampleImpl();
                ExampleImpl.merge(from.getExamples().get(exampleName), newExample, override);
                to.addExample(exampleName, newExample);
            }
        }
    }
    // Handle @Header
    if (from.getHeaders() != null) {
        for (String headerName : from.getHeaders().keySet()) {
            if (headerName != null) {
                Header newHeader = new HeaderImpl();
                HeaderImpl.merge(from.getHeaders().get(headerName), newHeader, override, context);
                to.addHeader(headerName, newHeader);
            }
        }
    }
    // Handle @Link
    if (from.getLinks() != null) {
        for (String linkName : from.getLinks().keySet()) {
            if (linkName != null) {
                Link newLink = new LinkImpl();
                LinkImpl.merge(from.getLinks().get(linkName), newLink, override);
                to.addLink(linkName, newLink);
            }
        }
    }
    // Handle @Parameter
    if (from.getParameters() != null) {
        for (String parameterName : from.getParameters().keySet()) {
            if (parameterName != null) {
                Parameter newParameter = new ParameterImpl();
                ParameterImpl.merge(from.getParameters().get(parameterName), newParameter, override, context);
                to.addParameter(parameterName, newParameter);
            }
        }
    }
    // Handle @RequestBody
    if (from.getRequestBodies() != null) {
        for (String requestBodyName : from.getRequestBodies().keySet()) {
            if (requestBodyName != null) {
                RequestBody newRequestBody = new RequestBodyImpl();
                RequestBodyImpl.merge(from.getRequestBodies().get(requestBodyName), newRequestBody, override, context);
                to.addRequestBody(requestBodyName, newRequestBody);
            }
        }
    }
    // Handle @APIResponse
    if (from.getResponses() != null) {
        for (String responseName : from.getResponses().keySet()) {
            if (responseName != null) {
                APIResponse newResponse = new APIResponseImpl();
                APIResponseImpl.merge(from.getResponses().get(responseName), newResponse, override, context);
                to.addResponse(responseName, newResponse);
            }
        }
    }
    // Handle @SecurityScheme
    if (from.getSecuritySchemes() != null) {
        for (String securitySchemeName : from.getSecuritySchemes().keySet()) {
            if (securitySchemeName != null) {
                SecurityScheme newSecurity = new SecuritySchemeImpl();
                SecuritySchemeImpl.merge(from.getSecuritySchemes().get(securitySchemeName), newSecurity, override);
                to.addSecurityScheme(securitySchemeName, newSecurity);
            }
        }
    }
}
Also used : APIResponse(org.eclipse.microprofile.openapi.models.responses.APIResponse) CallbackImpl(fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl) HeaderImpl(fish.payara.microprofile.openapi.impl.model.headers.HeaderImpl) Schema(org.eclipse.microprofile.openapi.models.media.Schema) SecuritySchemeImpl(fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl) RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Callback(org.eclipse.microprofile.openapi.models.callbacks.Callback) Header(org.eclipse.microprofile.openapi.models.headers.Header) ParameterImpl(fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl) Example(org.eclipse.microprofile.openapi.models.examples.Example) LinkImpl(fish.payara.microprofile.openapi.impl.model.links.LinkImpl) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) ExampleImpl(fish.payara.microprofile.openapi.impl.model.examples.ExampleImpl) SecurityScheme(org.eclipse.microprofile.openapi.models.security.SecurityScheme) Link(org.eclipse.microprofile.openapi.models.links.Link) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody)

Example 23 with Schema

use of org.eclipse.microprofile.openapi.models.media.Schema in project Payara by payara.

the class GenericSchemaMappingTest method genericSchemaTest.

@Test
public void genericSchemaTest() {
    APIResponses responses = getDocument().getPaths().getPathItem("/test/response").getGET().getResponses();
    assertNotNull("The default response should have been created.", responses.getDefaultValue());
    assertNotNull("The default response should return */*.", responses.getDefaultValue().getContent().getMediaType(WILDCARD));
    assertEquals("The default response */* should match the specified schema.", "#/components/schemas/JsonAnimalList", responses.getDefaultValue().getContent().getMediaType(WILDCARD).getSchema().getRef());
    Map<String, Schema> schemas = getDocument().getComponents().getSchemas();
    assertEquals(2, schemas.size());
    Schema jsonAnimalList = schemas.get("JsonAnimalList");
    assertNotNull(jsonAnimalList);
    assertEquals(1, jsonAnimalList.getProperties().size());
    assertEquals("JSON wrapper for a list of animals", jsonAnimalList.getDescription());
    assertEquals(SchemaType.OBJECT, jsonAnimalList.getType());
    Schema data = jsonAnimalList.getProperties().get("data");
    assertNotNull(data);
    assertEquals(5, data.getProperties().size());
    assertEquals(SchemaType.OBJECT, data.getType());
    Schema totalItems = data.getProperties().get("totalItems");
    assertNotNull(totalItems);
    assertEquals(SchemaType.INTEGER, totalItems.getType());
    Schema items = data.getProperties().get("items");
    assertNotNull(items);
    assertEquals(SchemaType.ARRAY, items.getType());
    assertEquals("#/components/schemas/Animal", items.getItems().getRef());
    Schema itemMap = data.getProperties().get("itemMap");
    assertNotNull(itemMap);
    assertEquals(SchemaType.OBJECT, itemMap.getType());
    assertNotNull(itemMap.getAdditionalPropertiesSchema());
    assertEquals("#/components/schemas/Animal", itemMap.getAdditionalPropertiesSchema().getRef());
    Schema textMap = data.getProperties().get("textMap");
    assertNotNull(textMap);
    assertEquals(SchemaType.OBJECT, textMap.getType());
    assertNotNull(textMap.getAdditionalPropertiesSchema());
    assertEquals(SchemaType.STRING, textMap.getAdditionalPropertiesSchema().getType());
    Schema itemsMap = data.getProperties().get("itemsMap");
    assertNotNull(itemsMap);
    assertEquals(SchemaType.OBJECT, itemsMap.getType());
    assertNotNull(itemsMap.getAdditionalPropertiesSchema());
    assertEquals(SchemaType.ARRAY, itemsMap.getAdditionalPropertiesSchema().getType());
    assertEquals("#/components/schemas/Animal", itemsMap.getAdditionalPropertiesSchema().getItems().getRef());
    Schema animal = schemas.get("Animal");
    assertNotNull(animal);
    assertEquals(2, animal.getProperties().size());
    assertEquals(SchemaType.OBJECT, animal.getType());
    Schema name = animal.getProperties().get("name");
    assertNotNull(name);
    assertEquals(SchemaType.STRING, name.getType());
    Schema age = animal.getProperties().get("age");
    assertNotNull(age);
    assertEquals(SchemaType.INTEGER, age.getType());
}
Also used : Schema(org.eclipse.microprofile.openapi.models.media.Schema) APIResponses(org.eclipse.microprofile.openapi.models.responses.APIResponses) Test(org.junit.Test) OpenApiApplicationTest(fish.payara.microprofile.openapi.test.app.OpenApiApplicationTest)

Example 24 with Schema

use of org.eclipse.microprofile.openapi.models.media.Schema in project drools by kiegroup.

the class DMNOASGeneratorImpl method prepareSerializaton.

private void prepareSerializaton() {
    ObjectNode tree = JsonUtil.objectNode();
    ObjectNode definitions = JsonUtil.objectNode();
    tree.set("definitions", definitions);
    for (Entry<DMNType, Schema> kv : schemas.entrySet()) {
        SchemaWriter.writeSchema(definitions, kv.getValue(), namingPolicy.getName(kv.getKey()));
    }
    jsonSchema = tree;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Schema(org.eclipse.microprofile.openapi.models.media.Schema) DMNType(org.kie.dmn.api.core.DMNType)

Example 25 with Schema

use of org.eclipse.microprofile.openapi.models.media.Schema in project drools by kiegroup.

the class DMNTypeSchemas method generateSchemas.

public Map<DMNType, Schema> generateSchemas() {
    Map<DMNType, Schema> schemas = new HashMap<>();
    for (DMNType t : typesIndex) {
        Schema schema = schemaFromType(t);
        schemas.put(t, schema);
    }
    return schemas;
}
Also used : HashMap(java.util.HashMap) Schema(org.eclipse.microprofile.openapi.models.media.Schema) DMNType(org.kie.dmn.api.core.DMNType)

Aggregations

Schema (org.eclipse.microprofile.openapi.models.media.Schema)51 Type (org.jboss.jandex.Type)15 Test (org.junit.Test)15 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)10 ClassType (org.jboss.jandex.ClassType)10 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)7 ArrayList (java.util.ArrayList)5 Parameter (org.eclipse.microprofile.openapi.models.parameters.Parameter)5 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)5 SchemaImpl (org.wildfly.swarm.microprofile.openapi.api.models.media.SchemaImpl)5 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)4 LinkedHashMap (java.util.LinkedHashMap)4 List (java.util.List)4 DMNType (org.kie.dmn.api.core.DMNType)4 Components (org.eclipse.microprofile.openapi.models.Components)3 Operation (org.eclipse.microprofile.openapi.models.Operation)3 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)3 SchemaType (org.eclipse.microprofile.openapi.models.media.Schema.SchemaType)3 APIResponse (org.eclipse.microprofile.openapi.models.responses.APIResponse)3 APIResponses (org.eclipse.microprofile.openapi.models.responses.APIResponses)3