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

io.openapiprocessor.jsonschema.schema.IdProvider201909 Maven / Gradle / Ivy

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

package io.openapiprocessor.jsonschema.schema;

import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.Map;

import static io.openapiprocessor.jsonschema.support.Types.asString;
import static io.openapiprocessor.jsonschema.support.Types.isString;

/**
 * draft-2019-09 IdProvider
 */
public class IdProvider201909 implements IdProvider {
    @Override
    public @Nullable String getId (Map properties) {
        Object rawId = properties.get (Keywords.ID);
        if (!isString (rawId))
            return null;

        String id = asString (rawId);

        // id must not contain fragment, except an empty fragment
        if (id.contains (Keywords.HASH) && !id.endsWith (Keywords.HASH)) {
            return null;
        }

        return id;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy