4
0
forked from crowetic/commerce

Updated script

This commit is contained in:
Luis Alvarez 2020-10-14 20:58:11 -05:00
parent f4497709e0
commit db7cee4400

View File

@ -7,7 +7,8 @@ const path = require('path')
const fetch = require('node-fetch') const fetch = require('node-fetch')
const swaggerToTS = require('@manifoldco/swagger-to-ts').default const swaggerToTS = require('@manifoldco/swagger-to-ts').default
async function getSchema(url) { async function getSchema(filename) {
const url = `https://next-api.stoplight.io/projects/8433/files/${filename}?ref=version%2F1.3`
const res = await fetch(url) const res = await fetch(url)
if (!res.ok) { if (!res.ok) {
@ -18,14 +19,16 @@ async function getSchema(url) {
} }
const schemas = Object.entries({ const schemas = Object.entries({
'../api/definitions/catalog.ts': '../api/definitions/catalog.ts': 'BigCommerce_Catalog_API.oas2.yml',
'https://next-api.stoplight.io/projects/8433/files/BigCommerce_Catalog_API.oas2.yml?ref=version%2F1.3', // swagger-to-ts is not working for the Cart schema
// '../api/definitions/cart.ts':
// 'BigCommerce_Server_to_Server_Cart_API.oas2.yml',
}) })
async function writeDefinitions() { async function writeDefinitions() {
const ops = schemas.map(async ([dest, url]) => { const ops = schemas.map(async ([dest, filename]) => {
const destination = path.join(__dirname, dest) const destination = path.join(__dirname, dest)
const schema = await getSchema(url) const schema = await getSchema(filename)
const definition = swaggerToTS(schema.content, { const definition = swaggerToTS(schema.content, {
prettierConfig: 'package.json', prettierConfig: 'package.json',
}) })