-
-
Notifications
You must be signed in to change notification settings - Fork 13
Feature/yangkit complete validation #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lllyfeng
merged 7 commits into
yang-central:main
from
network-analytics:feature/yangkit-complete-validation
Apr 15, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3f82891
fix: fix undeterministic JsonCodecDataTestGetSource integration test
ahuangfeng 7e43df5
update antlr4-runtime to 4.11.1
ahuangfeng 15b06c0
feature: add App5 example for ietf-interfaces & fix App3 example
ahuangfeng 3bbe3ea
feature: new App6 example with ietf-telemetry-message.yang example
ahuangfeng 7d63369
fix: augmentations within same yang module without when statements valid
ahuangfeng 87e301c
feature: automate IETF yang model validation
ahuangfeng 9fdef76
update Github CI to java 11
ahuangfeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
yangkit-examples/src/main/java/org/yangcentral/yangkit/examples/App5.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * Copyright 2023 INSA Lyon. | ||
| * | ||
| * 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 org.yangcentral.yangkit.examples; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.dom4j.DocumentException; | ||
| import org.yangcentral.yangkit.common.api.validate.ValidatorRecord; | ||
| import org.yangcentral.yangkit.common.api.validate.ValidatorResult; | ||
| import org.yangcentral.yangkit.common.api.validate.ValidatorResultBuilder; | ||
| import org.yangcentral.yangkit.data.api.model.YangDataDocument; | ||
| import org.yangcentral.yangkit.data.codec.json.YangDataDocumentJsonParser; | ||
| import org.yangcentral.yangkit.model.api.schema.YangSchemaContext; | ||
| import org.yangcentral.yangkit.model.api.stmt.Module; | ||
| import org.yangcentral.yangkit.parser.YangParserException; | ||
| import org.yangcentral.yangkit.parser.YangYinParser; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.net.URL; | ||
|
|
||
| /** | ||
| * Usecase on how to use yang to validate YANG-push notification | ||
| * | ||
| */ | ||
| public class App5 { | ||
| public static void main(String[] args) throws IOException, YangParserException, DocumentException { | ||
|
|
||
| URL yangUrl = App5.class.getClassLoader().getResource("App5/interfaces"); | ||
| String yangDir = yangUrl.getFile(); | ||
|
|
||
| // Parsing module | ||
| YangSchemaContext schemaContext = YangYinParser.parse(yangDir); | ||
| ValidatorResult result = schemaContext.validate(); | ||
| System.out.println("Valid? " + result.isOk()); | ||
| System.out.println("Size modules = " + schemaContext.getModules().size()); | ||
|
|
||
| int count = 0; | ||
| for (Module module : schemaContext.getModules()) { | ||
| System.out.println(count + "->Module["+ module.getModuleId().getModuleName()+"] prefix[" + module.getSelfPrefix()+"] | revision[" + module.getCurRevision().get() + "] ; root? [" + module.isSchemaTreeRoot() + "]"); | ||
| count++; | ||
| } | ||
|
|
||
| if (!result.isOk()) { | ||
| for (ValidatorRecord<?, ?> record : result.getRecords()) { | ||
| System.out.println("Error: "+ record.getBadElement() + ':' + record.getErrorMsg().getMessage()); | ||
| } | ||
| } else { | ||
| System.out.println("YANGs valid"); | ||
| for (ValidatorRecord<?, ?> record : result.getRecords()) { | ||
| System.out.println("valid: "+ record.getBadElement() + ':' + record.getErrorMsg().getMessage() + "; Severity:" + record.getSeverity().getFieldName()); | ||
| } | ||
| } | ||
| System.out.println("------------ Validating valid message ------------"); | ||
| InputStream jsonInputStream = App5.class.getClassLoader().getResourceAsStream("App5/json/interface.json"); | ||
| JsonNode jsonElement = null; | ||
| ObjectMapper objectMapper = new ObjectMapper(); | ||
| jsonElement = objectMapper.readTree(jsonInputStream); | ||
|
|
||
| System.out.println("Valid Message: " + jsonElement); | ||
|
|
||
| // Validating | ||
| ValidatorResultBuilder validatorResultBuilder = new ValidatorResultBuilder(); | ||
| YangDataDocument doc = new YangDataDocumentJsonParser(schemaContext).parse(jsonElement, validatorResultBuilder); | ||
| doc.update(); | ||
| ValidatorResult validatorResult = validatorResultBuilder.build(); | ||
|
|
||
| System.out.println("Is deserialization ok (should be true)? " + validatorResult.isOk()); | ||
|
|
||
| ValidatorResult validationResult = doc.validate(); | ||
| System.out.println("second validation: " + validationResult.isOk()); | ||
| if (!validationResult.isOk()) System.out.println(validationResult); | ||
|
|
||
| } | ||
| } | ||
89 changes: 89 additions & 0 deletions
89
yangkit-examples/src/main/java/org/yangcentral/yangkit/examples/App6.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * Copyright 2023 INSA Lyon. | ||
| * | ||
| * 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 org.yangcentral.yangkit.examples; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.dom4j.DocumentException; | ||
| import org.yangcentral.yangkit.common.api.validate.ValidatorRecord; | ||
| import org.yangcentral.yangkit.common.api.validate.ValidatorResult; | ||
| import org.yangcentral.yangkit.common.api.validate.ValidatorResultBuilder; | ||
| import org.yangcentral.yangkit.data.api.model.YangDataDocument; | ||
| import org.yangcentral.yangkit.data.codec.json.YangDataDocumentJsonParser; | ||
| import org.yangcentral.yangkit.model.api.schema.YangSchemaContext; | ||
| import org.yangcentral.yangkit.model.api.stmt.Module; | ||
| import org.yangcentral.yangkit.parser.YangParserException; | ||
| import org.yangcentral.yangkit.parser.YangYinParser; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.net.URL; | ||
|
|
||
| /** | ||
| * Usecase on how to use yang to validate YANG-push notification | ||
| * | ||
| */ | ||
| public class App6 { | ||
| public static void main(String[] args) throws IOException, YangParserException, DocumentException { | ||
|
|
||
| URL yangUrl = App6.class.getClassLoader().getResource("App6/yangs"); | ||
| String yangDir = yangUrl.getFile(); | ||
|
|
||
| // Parsing module | ||
| YangSchemaContext schemaContext = YangYinParser.parse(yangDir); | ||
| ValidatorResult result = schemaContext.validate(); | ||
| System.out.println("Valid? " + result.isOk()); | ||
| System.out.println("Size modules = " + schemaContext.getModules().size()); | ||
|
|
||
| int count = 0; | ||
| for (Module module : schemaContext.getModules()) { | ||
| System.out.println(count + "->Module["+ module.getModuleId().getModuleName()+"] prefix[" + module.getSelfPrefix()+"] | revision[" + module.getCurRevision().get() + "] ; root? [" + module.isSchemaTreeRoot() + "]"); | ||
| count++; | ||
| } | ||
|
|
||
| if (!result.isOk()) { | ||
| for (ValidatorRecord<?, ?> record : result.getRecords()) { | ||
| System.out.println("Error: "+ record.getBadElement() + ':' + record.getErrorMsg().getMessage()); | ||
| } | ||
| } else { | ||
| System.out.println("YANGs valid"); | ||
| for (ValidatorRecord<?, ?> record : result.getRecords()) { | ||
| System.out.println("valid: "+ record.getBadElement() + ':' + record.getErrorMsg().getMessage() + "; Severity:" + record.getSeverity().getFieldName()); | ||
| } | ||
| } | ||
| System.out.println("------------ Validating valid message ------------"); | ||
| InputStream jsonInputStream = App6.class.getClassLoader().getResourceAsStream("App6/json/telemetry-msg.json"); | ||
| JsonNode jsonElement = null; | ||
| ObjectMapper objectMapper = new ObjectMapper(); | ||
| jsonElement = objectMapper.readTree(jsonInputStream); | ||
|
|
||
| System.out.println("Valid Message: " + jsonElement); | ||
|
|
||
| // Validating | ||
| ValidatorResultBuilder validatorResultBuilder = new ValidatorResultBuilder(); | ||
| YangDataDocument doc = new YangDataDocumentJsonParser(schemaContext).parse(jsonElement, validatorResultBuilder); | ||
| doc.update(); | ||
| ValidatorResult validatorResult = validatorResultBuilder.build(); | ||
|
|
||
| System.out.println("Is deserialization ok (should be true)? " + validatorResult.isOk()); | ||
|
|
||
| ValidatorResult validationResult = doc.validate(); | ||
| System.out.println("second validation: " + validationResult.isOk()); | ||
| if (!validationResult.isOk()) System.out.println(validationResult); | ||
|
|
||
| } | ||
| } |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for those printed info, how about using
record.getSeverity()instead of all asError?(so that other severities such as
Warningetc. can be distinguished from here)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only ‘Error’ means result is not ok,:)