ericblade / sp-api-simple

Amazon Selling Partner API in TypeScript for Node/Browser
2 stars 1 forks source link

notes on AJV/SwaggerClient combination to try to validate data #4

Open ericblade opened 3 years ago

ericblade commented 3 years ago

Was not able to quickly get this to work -- in short, the Combined Swagger data does not have any definitions (spec.definitions). Attempting to add { includeDefinitions: true } to the swagger-combine config in build-swagger.ts fails with definition conflicts.

Theoretically, if we have those definitions, we should be able to use AJV to validate incoming data. This means that we either need to devise a method that can input all of the different amazon swagger specs (ie, create one swagger-client for each set of APIs), or to validate on the data in each spec separately.. either way would require loading all of the individual swagger files.

So, what I think I'd like to test, is changing build:swagger step to copy all of the individual swagger definition files into a directory under src, so they can be imported, enumerating those files, and loading each one into a separate instance of swagger-client. This would also allow each client function to import the data json and validate against it using AJV.

Should be able to test this with one or two of the definition files fairly quickly, just not sure when i will get time to do it.

ericblade commented 3 years ago

oh, yes, here's how to validate swagger spec data with ajv https://github.com/ajv-validator/ajv/issues/195