networknt / json-schema-validator

A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12
Apache License 2.0
859 stars 325 forks source link

Could not find OpenApi30 in release 1.4.0 #1069

Closed mpet closed 5 months ago

mpet commented 5 months ago

Hi,

I tried the following code:

JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V202012, builder -> builder.metaSchema(OpenApi30.getInstance()) .defaultMetaSchemaIri(OpenApi30.getInstance().getIri())); JsonSchema schema = factory.getSchema(SchemaLocation.of( localUrl));

and I used the following dependency:

com.networknt json-schema-validator 1.4.0

I could find all other classes from your lib but not the OpenApi30 class. I could not import it.

Any ideas?

br,

//mike

justin-tay commented 5 months ago

When you first posted the changes with OpenApi30 weren't in any release yet. You can now try 1.4.2.

mpet commented 5 months ago

Hi I tried:

image

And json data is in invalid:

{ "event": { "commonEventHeader": { "version": "4", "vesEventListenerVersion": 7, "domain": "fault", "eventId": "stndDefined-gNB_Nokia000001", "eventName": "stndDefined-gNB-Nokia-PowerLost", "stndDefinedNamespace": "3GPP-FaultSupervision", "startEpochMicrosec": 1413378172000000, "lastEpochMicrosec": 1413378172000000, "reportingEntityName": "ibcx0001vm002oam001", "sourceName": "scfx0001vm002cap001", "sequence": 1, "priority": "High" }, "stndDefinedFields": { "schemaReference": "http://localhost:8080/external1#components/schemas/NotifyNewAlarm", "data": { "href": 1, "uri": "1", "notificationId": 1, "notificationType": "notifyNewAlarm", "eventTime": "xyz", "systemDN": "xyz", "probableCause": 1, "perceivedSeverity": "INDETERMINATE", "rootCauseIndicator": false, "specificProblem": "xyz", "correlatedNotifications": [], "backedUpStatus": true, "backUpObject": "xyz", "trendIndication": "MORE_SEVERE", "thresholdInfo": { "observedMeasurement": "new", "observedValue": 123 }, "stateChangeDefinition": { }, "monitoredAttributes": { "newAtt": "new" }, "proposedRepairActions": "xyz", "additionalText": "xyz", "additionalInformation": { "addInfo": "new" }, "alarmId": 1, "alarmType": "COMMUNICATIONS_ALARM_INVALID" }, "stndDefinedFieldsVersion": "1.0" } } }

but there are no errors.

justin-tay commented 5 months ago

I can't tell what is the file you are loading for the schema. You will need to supply a junit reproducer if you really think there is an issue.

justin-tay commented 5 months ago

https://github.com/networknt/json-schema-validator/blob/7c518f672b89c3c6c9f60ed28b2aa39f37ee88a3/src/test/java/com/networknt/schema/OneOfValidatorTest.java#L223-L286

mpet commented 5 months ago

This is schema used:

https://forge.3gpp.org/rep/sa5/MnS/-/blob/Integration_Rel16_SA5_155_YAML/OpenAPI/TS28532_FaultMnS.yaml

justin-tay commented 5 months ago

While I see an issue with a schema location with a # in the fragment and a possible issue with discriminators, I don't see your issue. You will need to supply a more complete reproduction of the issue.

package com.networknt.schema;

import org.junit.jupiter.api.Test;

import com.networknt.schema.SpecVersion.VersionFlag;
import com.networknt.schema.oas.OpenApi30;

public class Issue1069Test {
    @Test
    void test() {
        JsonSchema schema = JsonSchemaFactory
                .getInstance(VersionFlag.V202012,
                        builder -> builder.metaSchema(OpenApi30.getInstance())
                                .defaultMetaSchemaIri(OpenApi30.getInstance().getIri()))
                .getSchema(SchemaLocation.of(
                        "https://forge.3gpp.org/rep/sa5/MnS/-/raw/Integration_Rel16_SA5_155_YAML/OpenAPI/TS28532_FaultMnS.yaml#/components/schemas/NotifyNewAlarm"),
                        SchemaValidatorsConfig.builder().build());

        String inputData = "{\r\n"
                + "  \"event\": {\r\n"
                + "    \"commonEventHeader\": {\r\n"
                + "      \"version\": \"4\",\r\n"
                + "      \"vesEventListenerVersion\": 7,\r\n"
                + "      \"domain\": \"fault\",\r\n"
                + "      \"eventId\": \"stndDefined-gNB_Nokia000001\",\r\n"
                + "      \"eventName\": \"stndDefined-gNB-Nokia-PowerLost\",\r\n"
                + "      \"stndDefinedNamespace\": \"3GPP-FaultSupervision\",\r\n"
                + "      \"startEpochMicrosec\": 1413378172000000,\r\n"
                + "      \"lastEpochMicrosec\": 1413378172000000,\r\n"
                + "      \"reportingEntityName\": \"ibcx0001vm002oam001\",\r\n"
                + "      \"sourceName\": \"scfx0001vm002cap001\",\r\n"
                + "      \"sequence\": 1,\r\n"
                + "      \"priority\": \"High\"\r\n"
                + "    },\r\n"
                + "    \"stndDefinedFields\": {\r\n"
                + "      \"schemaReference\": \"http://localhost:8080/external1#components/schemas/NotifyNewAlarm\",\r\n"
                + "      \"data\": {\r\n"
                + "        \"href\": 1,\r\n"
                + "        \"uri\": \"1\",\r\n"
                + "        \"notificationId\": 1,\r\n"
                + "        \"notificationType\": \"notifyNewAlarm\",\r\n"
                + "        \"eventTime\": \"xyz\",\r\n"
                + "        \"systemDN\": \"xyz\",\r\n"
                + "        \"probableCause\": 1,\r\n"
                + "        \"perceivedSeverity\": \"INDETERMINATE\",\r\n"
                + "        \"rootCauseIndicator\": false,\r\n"
                + "        \"specificProblem\": \"xyz\",\r\n"
                + "        \"correlatedNotifications\": [],\r\n"
                + "        \"backedUpStatus\": true,\r\n"
                + "        \"backUpObject\": \"xyz\",\r\n"
                + "        \"trendIndication\": \"MORE_SEVERE\",\r\n"
                + "        \"thresholdInfo\": {\r\n"
                + "          \"observedMeasurement\": \"new\",\r\n"
                + "          \"observedValue\": 123\r\n"
                + "        },\r\n"
                + "        \"stateChangeDefinition\": {},\r\n"
                + "        \"monitoredAttributes\": {\r\n"
                + "          \"newAtt\": \"new\"\r\n"
                + "        },\r\n"
                + "        \"proposedRepairActions\": \"xyz\",\r\n"
                + "        \"additionalText\": \"xyz\",\r\n"
                + "        \"additionalInformation\": {\r\n"
                + "          \"addInfo\": \"new\"\r\n"
                + "        },\r\n"
                + "        \"alarmId\": 1,\r\n"
                + "        \"alarmType\": \"COMMUNICATIONS_ALARM_INVALID\"\r\n"
                + "      },\r\n"
                + "      \"stndDefinedFieldsVersion\": \"1.0\"\r\n"
                + "    }\r\n"
                + "  }\r\n"
                + "}"; 
        System.out.println(schema.validate(inputData, InputFormat.JSON, OutputFormat.HIERARCHICAL));
    }
}
{
  "valid" : false,
  "evaluationPath" : "",
  "schemaLocation" : "https://forge.3gpp.org/rep/sa5/MnS/-/raw/Integration_Rel16_SA5_155_YAML/OpenAPI/TS28532_FaultMnS.yaml#/components/schemas/NotifyNewAlarm",
  "instanceLocation" : "",
  "details" : [ {
    "valid" : false,
    "evaluationPath" : "/components/schemas/NotifyNewAlarm/allOf/0/$ref",
    "schemaLocation" : "https://forge.3gpp.org/rep/sa5/MnS/-/raw/Integration_Rel16_SA5_155_YAML/OpenAPI/TS28623_ComDefs.yaml#/components/schemas/NotificationHeader",
    "instanceLocation" : "",
    "errors" : {
      "required" : [ "required property 'href' not found", "required property 'notificationId' not found", "required property 'notificationType' not found", "required property 'eventTime' not found", "required property 'systemDN' not found" ]
    }
  }, {
    "valid" : false,
    "evaluationPath" : "/components/schemas/NotifyNewAlarm/allOf/1",
    "schemaLocation" : "https://forge.3gpp.org/rep/sa5/MnS/-/raw/Integration_Rel16_SA5_155_YAML/OpenAPI/TS28532_FaultMnS.yaml#/components/schemas/NotifyNewAlarm/allOf/1",
    "instanceLocation" : "",
    "errors" : {
      "required" : [ "required property 'alarmId' not found", "required property 'alarmType' not found", "required property 'probableCause' not found", "required property 'perceivedSeverity' not found" ]
    }
  } ]
}
mpet commented 5 months ago

@justin-tay I think it could be what I add to SchemaLocation.of() I use file:/C:/Users/userid/..../ Is this what I should use in the first mentioned method or is there an alternative to my locally stored file?

justin-tay commented 5 months ago

I have tried with both a file and classpath iri and see no issue.

mpet commented 5 months ago

thx