-
Notifications
You must be signed in to change notification settings - Fork 23
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
Fixes #19 - Json schemafor metadata #276
Fixes #19 - Json schemafor metadata #276
Conversation
Created couple of methods and refactored other to support and enahnce the Metadata and related classes. Also created tests to support these changes.
/** | ||
* Returns the description of the FieldConstraint (for documentation propose) | ||
*/ | ||
String describeConstraint(); |
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.
This name was confusing when I first saw it. Maybe if it were getDescription()
it would be clearer?
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.
I will change it. I used 'to describe' (the verb) intended to say that could be dynamic generated (using interpolation of different things to compose a meaning description) .
Have only gotten part way through reviewing this. Hopefully I can continue this afternoon but if not someone else is welcome to take it. |
|
||
JsonNode jsonSchema = metadata.getJSONSchema(entityName, version1); | ||
String actual = jsonSchema.toString(); | ||
String expected = "{\"$schema\":\"http://json-schema.org/draft-04/schema#\",\"type\":\"object\",\"description\":\"JSON schema for entity 'user' version '1.0.0'\",\"properties\":{\"uid\":{\"type\":\"uid\"},\"nonrequid\":{\"type\":\"uid\",\"required\":\"Field not required constraint\"},\"iduid\":{\"type\":\"uid\",\"identity\":\"Field is part of identity constraint\"},\"personalInfo\":{\"type\":\"object\",\"lastName\":{\"type\":\"string\"},\"nonrequid\":{\"type\":\"uid\",\"required\":\"Field not required constraint\"},\"greeting\":{\"type\":\"string\"},\"department\":{\"type\":\"string\"},\"locale\":{\"type\":\"string\"},\"suffix\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"timezone\":{\"type\":\"string\"},\"faxNumber\":{\"type\":\"string\"},\"phoneNumber\":{\"type\":\"string\",\"matches\":\"^\\\\d{3}\\\\-\\\\d{4}\\\\ \\\\d{4}$\"},\"email\":{\"type\":\"string\"},\"company\":{\"type\":\"string\"},\"firstName\":{\"type\":\"string\"},\"requid\":{\"type\":\"uid\",\"required\":\"Field required constraint\"},\"emailConfirmed\":{\"type\":\"boolean\"}},\"updatedDate\":{\"type\":\"date\"},\"password\":{\"type\":\"object\",\"hashed\":{\"type\":\"string\"},\"salt\":{\"type\":\"string\"}},\"contactPermissions\":{\"type\":\"object\",\"allowMailContact\":{\"type\":\"boolean\"},\"allowThirdPartyContact\":{\"type\":\"boolean\"},\"allowPhoneContact\":{\"type\":\"boolean\"},\"allowFaxContact\":{\"type\":\"boolean\"},\"allowEmailContact\":{\"type\":\"boolean\"}},\"_id\":{\"type\":\"string\",\"identity\":\"Field is part of identity constraint\"},\"active\":{\"type\":\"boolean\"},\"login\":{\"type\":\"string\",\"maxLength\":\"64\",\"minLength\":\"1\",\"required\":\"Field required constraint\"},\"objectType\":{\"type\":\"string\"},\"requid\":{\"type\":\"uid\",\"description\":\"test\",\"required\":\"Field required constraint\"},\"createdDate\":{\"type\":\"date\"},\"required\":[\"login\",\"personalInfo.requid\",\"requid\"]}}"; |
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.
Would be easier to manage in a test resource and loaded from disk. Using skyscreamer we can easily verify without worrying about formatting, meaning the file can be pretty printed.
Moving to in progress, please comment when updates are ready for review and I'll work to look as soon as I can. |
@luan-cestari this needs updated still |
Created a simple json-schema for validation and also moved most of the JSON content to files.
updated the PR. @jewzaam |
Just noticed Generated schema is taking constraints on metadata fields and converting them to properties on the simple objects. For example, this:
becomes
It shouldn't do this. Identity isn't part of the json schema spec. I expected the json schema validation to catch this, but I guess it ignores additional properties. Identity should be treated the same as required. See comments below. Also, required constraints should be reflected in a The "uid" type is converted directly to the json schema. There is no "uid" type in the spec. It should become a strong. The "match" constraint is converted directly. It should be instead converted to a "pattern" attribute on the object representing the field. I think min and max constraints are converted correctly. I do not see a unit test including enum. Moving back to in progress. |
Looking. The first change (about move to different module), I did but after I tested it I noticed that it can't be that way with those files, as the FakeMetadataTest class uses some classes from test module and test module have a dependency to the metadata module, so if I move the FakeMetadataTest class to metadata I would need the test module as dependency which would make a cyclic dependency issue. About the other task to do, I'm working on it. I updated the json schema to have the validation necessary. Just one small question (to check if I got what you mean) one the snippets that you gave as example, so the first one* would be the output expected to be generated, right? By 'first one' I mean:
|
If "properties": {
"iduid": {
"type": "string"
}
},
"required": [
"iduid"
] |
Status summary:
|
@jewzaam I update the PR (also put a summary to help to track what have done and what we need to do) but I will focus on RDBMS integration test now, okay? |
@luan-cestari thank you, yes please focus on rdbms. This can be dropped from Ana if necessary. |
@luan-cestari given shift of focus and your work on non-rdbms issues could you consider closing out this issue? |
Merged with the latest changes. Also, As asked in the PR, update the test to cover the enum type usage. I included also the enum definition in the schema generated as it seems strange if you have the schema with external references
@jewzaam I just updated the PR to also cover the enum case. It was working fine, I just made some changes to also output the enum definition on the json as it is defined on teh entityinfo section which would not be included . The output would be something like https://gist.github.com/luan-cestari/a0ee0b58e9a08467d9a2 . Ready for review |
By the way , com.redhat.lightblue.metadata.EnumValue seems to always have empty/null description, is this fiend required at all? Could it be exemplified in the documentation http://docs.lightblue.io/language_specification/metadata.html ? |
Created lightblue-platform/lightblue-docs-specs#7 for the missing documentation. Regarding it being empty, are you supplying descriptions for enum values? If not, yes it should be empty. |
It only accept and array of Strings. It seems that the description is only used when it is bind with a field called "annotatedValues" instead "values". I will try to use both cases and make an exception on the schema generation for that each case, ok? |
Let's discuss enum structure on lightblue-platform/lightblue-docs-specs#7 since it needs documented. |
Alright, I will wait the resolution of that discussion. Let me know the On Thu Feb 12 2015 at 12:20:42 PM Naveen Malik [email protected]
|
I will make little updates to create the Rest service for this feature |
/** | ||
* Returns the description of the FieldConstraint (for documentation propose) | ||
*/ | ||
String getDescription(); |
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.
Why do we need documentation on the constraint? There is nothing in metadata to describe why we set a constraint other than what might be saved in the field's description. But that's part of the field, not the constraint.
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.
The documentation you mean the getDescription method right? This method is just a way to use polymorphism so I can get the specific description of each constraint without casting or checking instanceof. The description is used to generate a user-friendly message in the json schema
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.
Why does the constraint need a description? Each property in the json schema needs a description, yes, but those are given by the field in lightblue metadata. Constraints don't have a description in json schema.
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.
Maybe I chose the wrong word for the method name, it basically helps to generate an user text for a constraint and it can vary a lot. After the iterations we had for the issue that this PR aism to solve, the regex constraint (which uses 'pattern') is the only one using it right now and on this case it use to describe the pattern used for that constraint (which can vary for each request)
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.
It might need to be specific to each constraint. Numeric value constraints (minimum, maximum, minLength, etc) will be a number in json (no quotes) vs a pattern which will be a string (with quotes). I haven't reviewed how this is used yet to see. Interestingly ArrayElementIdConstraint returns a bunch of text, so I assume given your comment this is broken or it isn't used in a generic way.
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.
It was used, by I just quickly reviewed it before we talk about it, but I think it is just the regex case now, but it was used for other cases as well (when I had a different concept of the schema json that we would generate), so I can refactor it to something different just for regex case now if you think it would be better
Fixes #19