Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

[SW-502] Fixed SDK, added a working schema.json from vim-sw PHP SDK #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export default class Api {
this.url = url;
this.client = createClient(url, token, version)
this.version = version;
this.schema = require('./data/schema.json')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we load the schematic from the local file

}

async _initialize() {
let schema = await this.client.get('_info/entity-schema.json');

this.EntityDefinition = EntityDefinition;

Object.keys(schema.data).forEach((entityName) => {
this.EntityDefinition.add(entityName, schema.data[entityName]);
Object.keys(this.schema).forEach((entityName) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small refactor. data subkey is not exist in the new schema file.

this.EntityDefinition.add(entityName, this.schema[entityName]);
});

const hydrator = new EntityHydrator(this.EntityDefinition);
Expand All @@ -39,7 +39,7 @@ export default class Api {

return new Repository(
route,
definition.entity,
entityName,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously definition.entity returned null. Changed to another variable.

this.client,
hydrator,
changesetGenerator,
Expand Down
2 changes: 1 addition & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from 'axios';

export function createClient(url, token, version) {
const client = axios.create({
baseURL: `${url}/api/v${version}`
baseURL: `${url}/api`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed version from URL

})

client.defaultUrl = url;
Expand Down
2 changes: 1 addition & 1 deletion src/data/entity-definition.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class EntityDefinition {
*/
getPrimaryKeyFields() {
return this.filterProperties((property) => {
return property.flags.primary_key === true;
return property.flags.primary === true;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now primary field called 'primary' in the new schema.json

});
}

Expand Down
3 changes: 1 addition & 2 deletions src/data/repository.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,7 @@ export default class Repository {
let headers = {
Accept: 'application/vnd.api+json',
Authorization: `Bearer ${context.authToken.access}`,
'Content-Type': 'application/json',
'sw-api-compatibility': compatibility
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, otherwise there was a cors error

'Content-Type': 'application/json'
};

if (context.languageId) {
Expand Down
1 change: 1 addition & 0 deletions src/data/schema.json

Large diffs are not rendered by default.