shotstack / shotstack-sdk-node

Node SDK for Shotstack, the cloud video editing API
https://shotstack.io/product/sdk/node/
28 stars 7 forks source link

Assets not loading from object #11

Open emilsedgh opened 2 years ago

emilsedgh commented 2 years ago

Using editor.constructFromObject to populate a whole editor fails on Assets.

From what I'm seeing here, this fails because at here, it's obvious that Asset can't really populate from an object.

It appears that for each asset, there is a different model defined, like LumaAsset or TitleAsset.

But the Clip model doesn't really distribute the asset to any of them. Instead it goes directly to Asset model, which does nothing.

I think Asset.constructFromObject should be able to see the type, and based on that, invoke another model.

I would normally provide a pull request, but this is all auto-generated so I have no idea how to fix this.

jeffski commented 2 years ago

Hi @emilsedgh, There is actually a big bug in the generator. The Clip when generated is trying to load a file model/OneOfVideoAssetImageAssetTitleAssetHtmlAssetAudioAssetLumaAsset for the assets, but this file is never actually created. It obviously does not know how to handle Swagger/OAS3 oneOf types.

To work around that we just created the Assets.js file and updated the references to it. We have to manually update this part of the codebase every time anyway along with one or two other things.

If you wanted to submit a pull request that would be awesome. We'll work it in with the generated code each time which we do anyway right now until we can fully automate it.

It would be great if you could submit a pull requ

emilsedgh commented 2 years ago

I'll try to come up with a patch soon. Is there any similar bug that'd prevent constructFromObject working reliably? I'm trying to figure out if I can rely on it or I should switch to imperative function calls.

jeffski commented 2 years ago

I never used constructFromObject or tried to work it out to be honest, which is why it never got any attention or checks. Most users just use the classes similar to how we use them in our demo project, like this: https://github.com/shotstack/node-demos/blob/main/examples/images.js.

The other way is to skip the SDK and just JSON.stringify the whole edit object and use fetch or axios to post to the API.

If you don't get a chance to look at it I will see what I can do in the next SDK update.