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

Add required attribute to a JSON field description #2

Open
kaniandr opened this issue Oct 17, 2022 · 0 comments
Open

Add required attribute to a JSON field description #2

kaniandr opened this issue Oct 17, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@kaniandr
Copy link
Member

At this moment all named fields in a JSON are optional, so two cases are possible:

  • an extra field exists in a text representation of JSON and this field does not present in a library level JSON scheme,
  • an extra field exists in a JSON scheme and this field does not present in a text representation of JSON.

To check the first case we can easely fix implementation of:

 json::detail::ParseCellFunctor`;
 bool template<class... Args> struct Traits<bcl::StaticMap<Args...>>::
   parse(bcl::StaticMap<Args...> &Dest, Lexer &Lex, std::pair<Position, Position> Key)

Hence we can check whether a file is found in JSON scheme. We also need to add an attribute the JSON sceme description (a single attribute for each StaticMap in a JSON scheme) to specify if extra fileds must be diagnose.

The second case is more complex.

We need to specify which fields must be check, so we must a corresponding attribute to the description of an each cell in a StaticMap in a JSON scheme. Therefore, macros which are used to specify scheme have to be updated.

Implementation of the check procedure also faces shortcomings.The parser function traverse all fields in a text representation and for each field it searches for a corresponding field in a JSON scheme. This means, that we need to remember fields in a JSON scheme which has a corresponding pair in a text representation, so at the end of the traverse of a text representation we can find missing fields. However, current implementation of traverse and parse methods processes each field separatly and doesn't allow to forward information from the proccessing of one field to another.

To overcome this issue a State argument can be added to traverse and parse method. Another possibility is to traverse a text representation twice, so the first traverse will collect specified filds and than we can visit them again to parse.

@kaniandr kaniandr added the enhancement New feature or request label Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant