That is true, but it has been very well solved and standardised by OpenAPI and JSON Schema.
* manual:
* schema is maintained manually, independent of the implementation
* usually an afterthought and used mainly for documentation
* implementation-first:
* schema is autogenerated from the code
* used as a reference, possibly to generate clients, and often to run tests
* probably the most common approach, supported by many frameworks
* schema-first:
* schema is maintained manually, with client and server code generated from it
* very rare, but the most correct approachUnless your models are very simple, the best approach is to use three separate layers of model definitions:
* API models for serde and conversion of external requests
* business logic models that carry the actual internal functionality
* (optionally) ORM models to convert the data for persistence to a RDBMSThe thing I’ve noticed when stepping into a codebase where this problem has been allowed to occur is the lack of layers of abstraction. Having those different models built up from the start allows for an application to shift along with the needs of the product. Having a single layer, with the endpoints talking literally directly to the ORM models, almost inevitably leads to calcification, spaghettification, and disastrous performance.