Closed blaluc closed 4 years ago
Yes.
// api.js
import OpenAPIClientAxios from 'openapi-client-axios';
const api = new OpenAPIClientAxios({ definition: './api.json' });
export const getClient = () => api.getClient();
// usage
import { getClient } from './api.js';
getClient().then(client => {
// client.getPets();
});
Or synchronously:
npm install --save openapi-client-axios json-schema-deref-sync
// api.js
import fs from 'fs';
import OpenAPIClientAxios from 'openapi-client-axios';
const api = new OpenAPIClientAxios({ definition: JSON.parse(fs.readFileSync('./api.json')) });
export const client = api.initSync();
// usage
import { client } from './api.js';
// client.getPets();
Hello @anttiviljami
Does this also work from a React web app? Currently when I try to use this, it keeps trying to get the definitions from 'http://mybaseurl.com/swagger.json' instead of the static file called './swagger.json' Is this expected?
Thanks!
@paul-hristea you can use:
import definition from "./swagger.json"
Is it possible to generate the client code offline, starting from the api json spec file?