Is it possible to generate expanded/resolved schemas with AJV where $ref is used? $ref is extremely useful for keeping schemas DRY, but but not if you need an expanded representation of the schema.
When a schema is compiled, the returned function has the schema property, but that returns the non expanded schema that was supplied to the compile function in the first place. Further, there doesn't seem to be anything in the docs about it or even from a google search.
Is it possible to get an expanded schema where $ref is used?
While some tools provide some level of functionality to do this, it's not always possible to do this correctly, and sometimes impossible. ajv documents that it will not implement this functionality for reasons:
recursive $refs
List item $ref is not equivalent to the object inclusion,
because the $refs inside $ref should be resolved based on id in the
source schema and not based on id of the current schema.
https://github.com/epoberezkin/ajv/issues/336#issuecomment-258538008
Related
According to the "Writing a schema" guide for Google FlatBuffers it is possible to share data using references: "Remember that you can share data (refer to the same string/table within a buffer), so factoring out repeating data into its own data structure may be worth it."
However, I don't quite understand how this is meant to be accomplished. I have a flatbuffer that I'm trying to reverse engineer and I discovered that there are multiple offsets pointing to the same string value. When I compile the decoded JSON file again, there are multiple occurences of that string. What exactly do I have to specify in the schema file to prevent this?
Thank you :)
JSON has no way to represent such references, so a buffer is "flattened" to a tree when output as JSON. Only at the binary level can a FlatBuffer represent a DAG. You can construct such a DAG simply by using a child offset twice in parent(s) while serializing.
How would you handle dynamic fields indexing on nested documents so that you can query dynamic fields of a deep graph object with RavenDB?
Using the example from the documentation: http://ravendb.net/docs/2.0/client-api/advanced/dynamic-fields
What if the value of a product's attribute is also a product? Think of a CMS with dynamic fields where everything is a content and a root entity content (for the DDD guys) may embed another one, etc (deep graph).
This is very important since, aggregating child contents instead of relating to them (like you would do in a relational database world), is one of the core concept of document databases.
If the data conforms to a pattern, such as with hierarchical data, then you can recurse into that data to index according to the recursion pattern.
You already found how to index dynamic fields. You can combine these techniques to get at most any pattern that you can describe.
If the data is arbitrarily dynamic (i.e. you have no way of knowing what the object structure is ahead of time), then you are going to have a hard time reaching any particular field because you can't describe how to access it.
You can't be arbitrarily dynamic and be completely indexable at the same time.
New to XSD here.
Has anyone found or written a framework for validating XML with an XML schema in Cocoa/Obj-C?
What I really need is the ability to define permitted types of modifications to an NSXMLDocument, as described in an XSD file. This includes defining sequences of child elements, list of attributes and their permitted values, etc etc. I need to expose these modification rules in my UI. For example:
I want to constrain the names of the new child elements added to an existing NSXMLElement node in my NSOutlineView
If the XSD says that Node A has required child elements (Nodes Aa and Ab) then when the user adds Node A to the XML tree, I want to automatically create Nodes Aa & Ab and add them to the just-created Node A.
etc etc
It seems to me that a good solution would be a Cocoa counterpart of JAXB. XSOM (which doesn't create schema-derived classes, but rather gives an query-able object model of the XSD) would work too.
My question is similar to this one, but I don't want to limit myself to JAXB-like solution. I'm interested in finding out other solutions that people have come up to this problem.
Cheers!!
You can create a DTD and validate against it, or create a recursive parser based on your XSD, such as existing ones for RSS or Atom based on the spec.
I got a legacy database which have about 10 identical tables (only name differs).
Is it possible to be able to use the same business entity for all tables without having to create several classes/mapping files?
You can use the entity-name feature if you are using NHibernate v2.1 or higher. It is poorly documented but I am actively using the feature. It has gotten hard to find the documentation on it but look here:
Section 5.3 in
http://docs.jboss.org/hibernate/core/3.2/reference/en/html/mapping.html#mapping-entityname
A couple of things to be aware of. You must now use entity-name instead of class name to refer to the objects. In general it is not an entirely transparent change moving from class names to entity names.
Session actions now require two parameters, for example:
_session.Save("MyEntity", myobject)
The entity-name controls what table the data goes into.
Some HQL queries do not work right anymore, sometimes you must use Criteria instead.
If you need a set of sample code I may be able post some, but far too busy at the moment. I suggest you look at the limited info you can find and set it up for a very simple object and multiple tables to learn how it all works. It does work.
You can create a base class with all the properties, but you still need to map them all.
For that, you can either use copy&paste, XML entities (see examle at http://nhibernate.info/doc/nh/en/index.html#inheritance-tableperconcreate-polymorphism), or a code-based mapping method (Fluent or ConfORM). They usually make reuse easier.
Since there aren no respositories for value objects. How can I load all value objects?
Suppose we are modeling a blog application and we have this classes:
Post (Entity)
Comment (Value object)
Tag (Value object)
PostsRespository (Respository)
I Know that when I save a new post, its tags are saved with it in the same table. But how could I load all tags of all posts. Should PostsRespository have a method to load all tags?
I usually do it, but I want to know others opinions
I'm looking for a better solution for this question and I found this post:
http://gojko.net/2009/09/30/ddd-and-relational-databases-the-value-object-dilemma/
This post explain very well why there is a lot of confusion with value objects and databases.
Here you are phrase which liked me too much:
"Persistence is not an excuse to turn everything to entities."
Gojko Adzic, give us three alternatives to save our value objects.
I am currently working through a similar example. Once you need to uniquely refer to tags they are no long simple value objects and may continue to grow in complexity. I decided to make them their own entities and create a separate repository to retrieve them. In most scenarios they are loaded or saved with the post but when they are required alone the other repository is used.
I hope this helps.
EDIT:
In part thanks to this post I decided to restructure my application slightly. You are right that I probably was incorrectly making tags an entity. I have since changed my application so that tags are just strings and the post repository handles all the storage requirements around tags. For operations that need posts the tags are loaded with them. For any operation that just requires tags or lists of tags the repository has methods for that.
Here is my take in how I might solve this type of problem in the way that I'm currently practicing DDD.
If you are editing something that requires tags to be added and removed from such as a Post then tags may be entities but perhaps they could be value objects and are loaded and saved along with the post either way. I personally tend to favor value objects unless the object needs to be modified but I do realize that there is a difference between entity object modeled as read only "snapshots" and actual value objects that lack identity. The tricky part is that perhaps sometimes what you would normally think of as a key could be part of a value object as long as it is not used as identity in that context and I think tags fall into this category.
If you are editing the tags themselves then it is probably a separate bounded context or at least a separate aggregate in which tags are themselves are the aggregate root and persisted through a repository. Note that the entity class that represents tags in this context doesn't have to be the same entity class for tags used in Post aggregate.
If your listing available tags on the display for read only purposes such as to provide a selection list, then that is probably a list of value objects. These value objects can but don't have to be in the Domain Model since they are mainly about supporting the UI and not about the actual domain.
Please chime in if anybody has any thoughts on why my take on this might be wrong but this is the way I've been doing it.