I'm trying to use Newtonsoft JSON.Net Schema to generate schemas from my POCOs. JSON Schema supports the idea of combining sub-schemas via anyOf/oneOf/allOf. I can't figure out how to make this work with JSON.Net Schema. I've seen this issue, but there's no resolution there, though there is a reference to using the KnownTypeAttribute but then a comment that it doesn't work.
Any pointers on generating schemas with anyOf/oneOf/allOf?
Related
We are in situation to create the separate API in Python FastApi for one functionality. Other functionality in Laravel. The application which exists already. It created set of tables and using them. Now, we are required to create Pydantic schemas for new API. That schema has a relationship with existing tables. We don't want to create separate schemas for existing tables.
We are forced to create schemas for existing tables as well in the new API. We don't want to create the separate schemas and models for existing tables.
Kindly suggest
Thanks in advance
If you don't care about automatic documentation you don't need to use pydantic at all - you can just return dict and use swagger. If you do, I have no good news.
As far as I know it's not easily achievable. Even if you have tables definitions implemented in sqlalchemy there is not easy way of creating schema from them (there is a tool but it's still experimental).
There are ORM's that can do that (like tortoise) but you still need to implement schema somewhere. Dynamic creation of python class based on database schema would be very hard, very long, very bugable and would break static checkers so I am pretty sure they never exist.
I'm attempting to setup Entity Framework using Code First on an existing database. The database isnt in great shape (poor naming convention and some constraints are needed). The application I'm building is an MVC app. I have a "Model", "Repository", and "Web" (mvc) tiers.
To setup EF and map my model objects (POCO objects), is it required that I match my objects to database tables? Can I, instead, use my own stored procedures for CRUD operations? Would it help if I use WCF data services?
I'm planning on using fluent configurations to map my objects, but having some issues due to the database schema. I'm know considering redesigning the database just to get EF to map correctly. Any suggestions would be greatly appreciated!!
Looks awfully similar to this question:
Does Entity Framework Code First support stored procedures?
The answers there may be helpful to you, as well as the discussion surrounding how Code First and Stored Procedures don't make a whole lot of sense.
Wow, Julie Lerman answered!
Yes, it's possible, but not particularly easy. In particular, you must call context.Database.SqlQuery<T>() where T is the entity type you want to return, and your SQL must match up to that entity type. Otherwise, you will have to massage a result set into a type.
In general, you will have to do most of this manually, although you could probably figure out a T4 template to generate it for you, or maybe use some other tool like CodeSmith.
Recently I am using LINQ. But when facing an interview I am unable to explain:
What is LINQ?
Moreover, is DataSet deprecated due to the introduction of LINQ?
From an interview point of view, how should I answer those questions?
LINQ is a set of extensions to the .NET framework that enables language-integrated queries. This basically means that we can use the same type of syntax to query any set of data - whether it be a SQL database, Active Directory, or XML file - we can use the same syntax to execute queries.
The mechanism that LINQ uses to communicate with the different datasources is through providers - you can write your own provider if you wish, but the default providers are LINQ-to-Objects, LINQ-to-SQL and LINQ-to-XML. So again - LINQ allows you to use the same syntax for retrieving data from a SQL database, XML file or in-memory objects.
LINQ does not replace DataSets - in fact, you can use LINQ in conjunction with datasets. The only reason why there is a debate of DataSets vs LINQ is due to LINQ-to-SQL being an ORM. This means that we now have a choice in terms of built-in technologies for communicating with the database - previously datasets would be the default built-in option, now you can also opt for LINQ-to-SQL.
Nice introduction to LINQ Just pick few most important sequences from there for your interview question. As for the second question DataSet's are not deprecated, LINQ is just adding a different way you can work with your data.
In addition to what #RaYell said you should have asked your interviewer if they were talking about LINQ or LINQ to SQL when asking if the DataSet was deprecated.
Entity Framework replaces LINQ to SQL, using an OOD approach, shielding it from the database with a mapping layer. This layer uses xml and csql to enable it to pass the data to a variety of databases, without the overhead of sql. The objects dont expose any tables, and neither would you expect it, as the objective is to abstract to enable mapping. This is clearly at odds with the dataset approach. I guess if you considered "Entity Framework to Dataset", or "Entity Framework to XML" in the same vein as LINQ, and to enable loading of these objects shielded by mapping, then you can see the value of each of these technologies. Such transformation atm seem to be via LINQ to XML, or LINQ to DATASET, and then pushing into Entity Framework. I would add that the DataSet allows for accessing tables, rows, columns dynamically and I am not sure the Entity FrameWork has such capability, it must know the data framework, hence they are complementary technologies.
I have seen questions here asking about xsd->actionscript objects, but these seem to require xsd->java->actionscript and is all in source code. Our requirements are a bit different:
receive an xsd during runtime that we have never seen before
Create an instance object based on the xsd
fill in the values of the instance (either from an xml document or user input - whatever)
Anyone know of an actionscript library or tool that would help us accomplish this at runtime? It would be nice if something like this already existed - but we would certainly settle for a library that gave us a programmatic interface to extract information from an xsd schema. Additionally, we would take suggestions on alternate methods to accomplish the same ends.
Have you looked at the SchemaLaoder...? Not EXACTLY what you're looking for ... But a great start.
First - you should check this blog entry and this blog entry which walks you through Dominic De Lorenzo experiences with utilising functionality within the Flex SDK that provides the automatic mapping of custom ActionScript classes to element definitions within an XML Schema (XSD).
The steps to get moving here include (from Dominic's blog):
0) Create an instance of SchemaLoader and asynchronously load an XML schema from a given URL
1) Once the schema is loaded, add it to the SchemaManager and register any ActionScript classes to their corresponding schema type
---- At this stage you can do several operation based on the schema
2) Load an XML file based off that schema
3) Once the XML is loaded, decode the contents using XMLDecoder. Any classes registered in the schemaTypeRegistry will be used when decoding the xml
4) Encode a custom ActionScript class back into XML using XMLEncoder. XMLEncoder.encode() supports various ways to define the corresponding element in the schema (top level element, a specific type or even a custom XSD definition) that will be used to encode the Actionscript object.
The blog entry has links to code samples, etc...
Hope this helps.
Our Flex app would like to work with requests and responses as object graphs (nothing unusual there) e.g. response becomes the model of some view, and would be a structure with several layers of nesting.
** Now, ideally we would like to use the same client (and server) side objects for different message formats e.g. XML and AMF, and have a pluggable serialization/de-serialization layer (!)
AMF has serialization and matching of client to server using
[RemoteClass(alias="samples.contact.Contact")]
but it seems there is no equivalent for XML.
I am (somewhat optimistically) looking for a neat way of serializing the object graph to XML, to send through a HTTPService from the client.
For responses, the default 'object' and 'E4X' provide some de-serialization. This is handy, but of course we don't have the niceties of unpacking the XML back into specific AS classes like we do with AMF.
Any suggestions?
(did have one idea come through about wrapping/casting object as XML or XMLList - this does not seem to work, however)
Update:
Both these libraries look useful, and I will very likely use them at some point.
For now, I really need the simplicity of re-using the metadata set for the AMF3 serialization which we are using in any case ([RemoteClass],[Transient])
.. so the best option at the moment is AMFX - used Flex Data Services for AMF transfer using XML - classes in mx.messaging.channels.amfx package - only drawback at the moment is any Externalizable class is transformed into a Hex byte stream - and ArrayCollection is Externalizable! (hoping to workaround by serializing the internal Array in a subclass ..)
Hope that's useful to someone ..
Regarding the Xml serialization I can give you a starting point (as biased as it may be, though :D).
I am working on a project that allows for automatic conversion of AS3 objects to and from xml. It basically uses annotations on the model objects you use for communication in order to construct the xml structure or populating an object from xml.
It is called FlexXB and you can check it out at http://code.google.com/p/flexxb/.
I started this project cos I got into the same issues at work (namely I have a server that communicates through xml) and I hoped it be of use to someone else.
Cheers,
Alex
Yet another project: FleXMLer (http://code.google.com/p/flexmler/).
It has both the straightforward attitude of asx3m where you can just call:
new FleXMLer().serialize(obj);
Or you can customize XML element names, skip elements and tweak the way arrays and hash tables are serialized.
Would appreciate your input.
checkout asx3m project at http://code.google.com/p/asx3m
It's an AS3 port of Java XStream serialization library and works pretty well.
I made it because I had to connect to a server platform that used XStream for exchanging data objects and put a lot of work in it.
It can be extended to serialize AS3 objects to any format (JSON for example) and could leverage power of user defined metatags.
Cheers,
Tomislav
There's a library including JSON available from Adobe, too. And since ActionScript is a superset of JavaScript ... and JSON is increasingly supported cross-framework ...