All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.apicurio.datamodels.asyncapi.models.AaiDocument Maven / Gradle / Ivy

/*
 * Copyright 2019 Red Hat
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.apicurio.datamodels.asyncapi.models;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import io.apicurio.datamodels.compat.JsonCompat;
import io.apicurio.datamodels.core.models.Document;

/**
 * Models an AsyncAPI root document.
 *
 * @author [email protected]
 * @author Jakub Senko 
 */
public abstract class AaiDocument extends Document {

    /**
     * @see AsyncAPI 2.0.0 spec
     */
    public String asyncapi;

    /**
     * @see AsyncAPI 2.0.0 spec
     */
    public String id;

    /**
     * @see AsyncAPI 2.0.0 spec
     */
    public Map channels = new LinkedHashMap<>();

    /**
     * @see AsyncAPI 2.0.0 spec
     */
    public Map servers;

    /**
     * @see AsyncAPI 2.0.0 spec
     */
    public AaiComponents components;

    public String defaultContentType;
    
    /**
     * Constructor.
     */
    public AaiDocument() {
    }

    public AaiServer addServer(String name, AaiServer server) {
        if (this.servers == null) {
            this.servers = new LinkedHashMap<>();
        }
        this.servers.put(name, server);
        return server;
    }

    public List getChannels() {
        return JsonCompat.mapToList(this.channels);
    }

    public void addChannelItem(AaiChannelItem item) {
        if (channels == null)
            channels = new LinkedHashMap<>();
        channels.put(item.getName(), item);
    }

    public abstract AaiServer createServer(String name);

    public abstract AaiServer createServer(String name, String url, String description);

    public abstract AaiChannelItem createChannelItem(String name);

    public abstract AaiComponents createComponents();

    public List getServers() {
        return JsonCompat.mapToList(servers);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy