Vuex ORM define id´s for objects inside properties - orm

I get a response from an API looking like this:
{
"error": null,
"h": {
"event": "EVENT",
"date": 1621265337566,
"edited": "me",
"changed": [
{
"old": "",
"new": "test",
"field": "Name",
"class": "form"
}
]
}
}
I am looking for a way to represent this in a Vuex ORM Model. In my understanding this should result in 3 Model Classes. One for the whole object, one for "h" and one for "changed". Vuex ORM provides methods to join these like hasMany but these seem to work with set id´s only which the api response does not provide.
Does anyone know how to represent this response in Vuex ORM ?

Related

NJson Schema additional property without Attribute

I'm using NJsonSchema to create json shema from my backend to API UI.
I would like to add some customer properies to each properies of backend classıs. I know there is an attribute ([JsonSchemaExtensionData("description", "FirstName")]) whicj is working as expected. But I don't wanna do this for every single POCO classes and attributes.
What I want to do is showen in the below.For this example I wanna add "description": "FirstName" to every properties of my classes.
"$schema": "http://json-schema.org/draft-04/schema#", "title": "Person", "type": "object", "additionalProperties": false, "properties": {
"FirstName": {
"type": [
"null",
"string"
],
"description": "FirstName"
},
And I have seen an another (custom shema processor) solution which is looks like better way. But I don'y know how to implement .
Unfortunately unable to find fully working code sample.
public class MySchemaProcessor : ISchemaProcessor
{
public void Process(SchemaProcessorContext context)
{
// Don't know what to do here ??
}
}

API standard design - swagger parameter body VS URI

I would like to clarify what is the design standard to query a list of array.
json data:
"ids": [
{
"id": "bbbbeeee1111",
"type": "student"
},
{
"id": "bbbbeeee2222",
"type": "teacher"
}
],
GET endpoint
/api/testitem
swagger parameter body
{
"ids": ["bbbbeeee1111;student"]
}
swagger returned the URI like this , the %3B seems wrong. some coding issues at API design?
http://localhost:8888/api/testitem?ids=bbbbeeee1111%3Bstudent

Make collection propertie render as relation instead of property in json HAL representaion

I got hal formatted response as this:
{
"name": "Publisher A",
"bookPublishers": [
{
"publishedDate": "2019-07-12T08:19:04.583+0000",
"_links": {
"publisher": {
"href": "http://localhost:8080/api/publishers/1"
},
"book": {
"href": "http://localhost:8080/api/books/2"
}
}
},
{
"publishedDate": "2019-07-12T08:19:04.564+0000",
"_links": {
"publisher": {
"href": "http://localhost:8080/api/publishers/1"
},
"book": {
"href": "http://localhost:8080/api/books/1"
}
}
}
],
"_links": {
"self": {
"href": "http://localhost:8080/api/publishers/1"
},
"publisher": {
"href": "http://localhost:8080/api/publishers/1"
},
"friends": {
"href": "http://localhost:8080/api/publishers/1/friends"
},
"createdBy": {
"href": "http://localhost:8080/api/publishers/1/contact"
}
}
}
I see there property bookPublishers and also in links friends. Imho they should be both association links (see 2.4. Creating the Associations) where can I "put" another resources.
I would like to make spring render bookPublishers same as friends.
Sample project is here: https://github.com/luvarqpp/poc-springHalRelations
You can do:
git clone https://github.com/luvarqpp/poc-springHalRelations.git
cd poc-springHalRelations
mvn clean spring-boot:run
And than open http://localhost:8080/api
PS: Bonus question, what is easiest way to provide own relation for business logic, like relation "renameAuthor" for example.
For collection relationships, Spring Data will provide a link when a repository exists for the relevant type. Where no repository exists then the collection will be in-lined in the response, otherwise, how else will the client get the data.
Therefore, create a repository for your BookPublisher type.
Relevant documentation part citation:
the component responsible for creating the links to referenced entities (such as those objects under the _links property in the object’s JSON representation). It takes an #Entity and iterates over its properties, creating links for those properties that are managed by a Repository and copying across any embedded or simple properties.
You can also create a projection that would in-line the data when required. Clients could specify this projection in the request therefore preventing an additional server call.
e.g.
/publisher/1?projection=withBookPublishers.
https://docs.spring.io/spring-data/rest/docs/current/reference/html/#projections-excerpts.projections

How to define a related resource URI in JSON:API

In the json:api format relationships are defined with a type and a id.
Like in the example bellow. The article has a relationship with the type people and the id 9.
Now if i want to fetch the related resource i use the URI from "links.related"
// ...
{
"type": "articles",
"id": "1",
"attributes": {
"title": "Rails is Omakase"
},
"relationships": {
"author": {
"links": {
"self": "http://example.com/articles/1/relationships/author",
"related": "http://example.com/articles/1/author"
},
"data": { "type": "people", "id": "9" }
}
},
"links": {
"self": "http://example.com/articles/1"
}
}
// ...
But in my case the related resource (people) are in a separate API. There is no way to get the full people data from the articles API nor is it possible to include it. The only way to get the related data would be a call to:
http://example.com/v1-2/people/9/
Where can i define the relation between the URI and people:9
Or in other words: How would a client know where to fetch the related resource?

reusing an object for multiple JSON schemas

I have two separate JSON schemas (used to validate HTTP request endpoints for a REST API) where they both accept the same exact object, but have different required fields (this is a create vs update request). Is there a way I can reuse a single definition of this object and only change the required fields? I know how to use $ref for reusing an object as a property of another object, but I cannot figure out how to reuse an entire object as the top-level object in a schema. My failed attempt so far:
event.json
{
"id": "event",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"start_date": {
"type": "integer"
},
"end_date": {
"type": "integer"
},
"description": {
"type": "string"
}
},
"additionalProperties": false
}
event-create.json
{
"id": "event-create",
"type": "object",
"$ref": "event",
"additionalProperties": false,
"required": [ "name", "description" ]
}
Obviously that doesn't work. It seems like it tries to insert the entirety of 'event' into the definition of 'event-create', including the ID and such. I tried referincing event#/properties to no avail. I can't seem to do a $ref as the sole value inside a properties property either. Any ideas?
Any members other than "$ref" in a JSON Reference object SHALL be ignored.
- https://datatracker.ietf.org/doc/html/draft-pbryan-zyp-json-ref-03#section-3
This is why your example doesn't work. Anything other than the $ref field is supposed to be ignored.
Support for $ref is limited to fields whose type is a JSON Schema. That is why trying to use it for properties doesn't work. properties is a plain object whose values are JSON Schemas.
The best way to do this is with allOf. In this case allOf can sort-of be thought of as a list of mixin schemas.
{
"id": "event-create",
"type": "object",
"allOf": [{ "$ref": "event" }],
"required": ["name", "description"]
}
I found some syntax that seems to work, but I'm not terribly happy with it:
{
"id": "event-create",
"allOf": [
{ "$ref": "event" },
{ "required": [ "name", "description" ] }
]
}
Seems like an abuse of the allOf operator, particularly for another case where there are no required fields (thus only one element insid the allof). But it works, so I'm going with it unless someone has a better idea.