Skip to content
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

Enhance the YangYinParser API to work with none file-based yang sources #12

Open
ahassany opened this issue Feb 17, 2023 · 7 comments
Open

Comments

@ahassany
Copy link
Contributor

Currently, the YangYinParser provides 8 public methods for parsing YANG schemas, all of which are File or Directory based. This represents a tight coupling to the filesystem and can limit the usage of this API inside other libraries that don't save the schema on a traditional file system.

Is there any futures plans to refactor this API and decouple YangYinParser from how the yang schemas are stored?

The current, API

  1. public static YangSchemaContext parse(List<File> yangFiles)
  2. public static YangSchemaContext parse(File yangDir)
  3. public static YangSchemaContext parse(File yangDir, YangSchemaContext context)
  4. public static YangSchemaContext parse(String yangDir)
  5. public static YangSchemaContext parse(String yangDir, String dependency, String capabilities)
  6. public static YangSchemaContext parse(String yangDir, String capabilities)
  7. public static YangSchemaContext parse(String yangDir, YangSchemaContext context)
  8. public static YangSchemaContext parse(List<File> files, YangSchemaContext context)
@lllyfeng
Copy link
Contributor

lllyfeng commented Feb 17, 2023 via email

@ahassany
Copy link
Contributor Author

Yes, InputStream could a good fit

@lllyfeng
Copy link
Contributor

@ahassany I have added some APIs to support parsing YANG from inputstream. expect your opinion about this.
/**
* parse YANG module from inputStream, not import-only
* @param inputStream
* @param moduleInfo
* @param context
* @return
* @throws YangParserException
* @throws IOException
* @throws DocumentException
*/

public static YangSchemaContext parse(InputStream inputStream,
String moduleInfo,
YangSchemaContext context)
throws YangParserException, IOException, DocumentException;

/**
* parse YANG/YIN module from inputStream
* @param inputStream the candidate input stream
* @param moduleInfo the description of the module, it often indicates the position information and module information
* for example, "ftp://10.1.1.1/ietf-interfaces@2019-07-31"
* or "C:\documents\yang\[email protected]"
* @param isYang
* @param importOnly
* @param context
* @return
* @throws YangParserException
* @throws IOException
* @throws DocumentException
*/
public static YangSchemaContext parse(InputStream inputStream,
String moduleInfo,
boolean isYang,
boolean importOnly,
YangSchemaContext context)
throws YangParserException, IOException, DocumentException;

@marcosbis
Copy link

Hi, is this implemented already somehow?

Thanks

@lllyfeng
Copy link
Contributor

Yes, it has been implemented.

@marcosbis
Copy link

can you please provide sample to implement from String ? the javadoc dont seems to be working and can't find any example
Thanks

@lllyfeng
Copy link
Contributor

@marcosbis I add some examples in README.md of yangkit-parser module. Is it enough for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants