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

io.openapiprocessor.jsonschema.converter.VocabularyConverter Maven / Gradle / Ivy

There is a newer version: 2024.4
Show newest version
/*
 * Copyright 2023 https://github.com/openapi-processor/openapi-parser
 * PDX-License-Identifier: Apache-2.0
 */

package io.openapiprocessor.jsonschema.converter;

import io.openapiprocessor.jsonschema.schema.JsonSchemaContext;
import io.openapiprocessor.jsonschema.schema.Vocabularies;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;

import static io.openapiprocessor.jsonschema.support.Types.asBoolean;
import static io.openapiprocessor.jsonschema.support.Types.convertMapOrNull;
import static io.openapiprocessor.jsonschema.support.Uris.createUri;

public class VocabularyConverter implements PropertyConverter {
    private final JsonSchemaContext context;

    public VocabularyConverter (JsonSchemaContext context) {
        this.context = context;
    }

    @Override
    public @Nullable Vocabularies convert (String name, @Nullable Object value, String location) {
        Map objects = convertMapOrNull (location, value);
        if (objects == null)
            return null;

        Map vocabularies = new LinkedHashMap<> ();
        objects.forEach ((propKey, propValue) -> {
            vocabularies.put (createUri (propKey), asBoolean (propValue));
        });

        return Vocabularies.create (vocabularies, context.getVersion ());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy