Git Product home page Git Product logo

Comments (9)

justin-tay avatar justin-tay commented on July 25, 2024

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

from json-schema-validator.

mpet avatar mpet commented on July 25, 2024

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.

from json-schema-validator.

justin-tay avatar justin-tay commented on July 25, 2024

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.

from json-schema-validator.

justin-tay avatar justin-tay commented on July 25, 2024

@Test
void fixedSwaggerIoExample() {
String document = "paths:\r\n"
+ " /pets:\r\n"
+ " patch:\r\n"
+ " requestBody:\r\n"
+ " content:\r\n"
+ " application/json:\r\n"
+ " schema:\r\n"
+ " oneOf:\r\n"
+ " - $ref: '#/components/schemas/Cat'\r\n"
+ " - $ref: '#/components/schemas/Dog'\r\n"
+ " responses:\r\n"
+ " '200':\r\n"
+ " description: Updated\r\n"
+ "components:\r\n"
+ " schemas:\r\n"
+ " Dog:\r\n"
+ " type: object\r\n"
+ " properties:\r\n"
+ " bark:\r\n"
+ " type: boolean\r\n"
+ " breed:\r\n"
+ " type: string\r\n"
+ " enum: [Dingo, Husky, Retriever, Shepherd]\r\n"
+ " required:\r\n"
+ " - bark\r\n"
+ " - breed\r\n"
+ " Cat:\r\n"
+ " type: object\r\n"
+ " properties:\r\n"
+ " hunts:\r\n"
+ " type: boolean\r\n"
+ " age:\r\n"
+ " type: integer\r\n"
+ " required:\r\n"
+ " - hunts\r\n"
+ " - age";
JsonSchema schema = JsonSchemaFactory
.getInstance(VersionFlag.V202012,
builder -> builder.schemaLoaders(schemaLoaders -> schemaLoaders
.schemas(Collections.singletonMap("http://example.org/example.yaml", document))))
.getSchema(SchemaLocation.of(
"http://example.org/example.yaml#/paths/~1pets/patch/requestBody/content/application~1json/schema"));
String example1 = "{\r\n"
+ " \"bark\": true,\r\n"
+ " \"breed\": \"Dingo\" \r\n"
+ "}";
assertTrue(schema.validate(example1, InputFormat.JSON, OutputFormat.BOOLEAN));
String example2 = "{\r\n"
+ " \"bark\": true,\r\n"
+ " \"hunts\": true\r\n"
+ "}";
assertFalse(schema.validate(example2, InputFormat.JSON, OutputFormat.BOOLEAN));
String example3 = "{\r\n"
+ " \"bark\": true,\r\n"
+ " \"hunts\": true,\r\n"
+ " \"breed\": \"Husky\",\r\n"
+ " \"age\": 3 \r\n"
+ "}";
assertFalse(schema.validate(example3, InputFormat.JSON, OutputFormat.BOOLEAN));
}

from json-schema-validator.

mpet avatar mpet commented on July 25, 2024

This is schema used:

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

from json-schema-validator.

justin-tay avatar justin-tay commented on July 25, 2024

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" ]
    }
  } ]
}

from json-schema-validator.

mpet avatar mpet commented on July 25, 2024

@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?

from json-schema-validator.

justin-tay avatar justin-tay commented on July 25, 2024

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

from json-schema-validator.

mpet avatar mpet commented on July 25, 2024

thx

from json-schema-validator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.