rdme icon indicating copy to clipboard operation
rdme copied to clipboard

Sync specs without requiring an API Definition ID

Open Shanjeef opened this issue 3 years ago • 3 comments

I'm attempting to sync a set of API specs in my project through Github Actions. In order to do so I require an API definition ID per spec. I can obtain this through the admin portal once I upload a spec file using the CLI or manual approach you've documented here.

I'd like to automate syncing specs through GH Actions and not require the initial step of having to upload manually in order to get this API definition ID. I'm still new to GH actions, but my desire is to store all my team's "published-ready" specs in one directory, and create an action that will iterate through each spec file in this directory and upload them to Readme.

Feature Request: Wondering if Readme can implicitly match and formulate this ID based on some properties (ex: info.title) within a spec file's definition without explicitly requiring it?

Shanjeef avatar Mar 09 '22 22:03 Shanjeef

Hi @Shanjeef! Thanks for writing in. I like this idea but it will require some potentially breaking changes in our API to support this. We're in the process of formulating plans for API changes in the coming months, we'll make sure this is being taken into consideration!

cc: @erunion @Dashron

kanadgupta avatar Mar 10 '22 16:03 kanadgupta

Is there any way I could list Api Definitions IDs for 'Stable', 'Main' or 'Latest' readme versions via api/cli? Then I could use the Api Definition ID in the command. Otherwise, It is hard to to rely upon Readme API Docs it is easy to forget to update the Definition ID.

joshp-f avatar Apr 14 '22 00:04 joshp-f

I used the Readme API to achieve this!

import fetch from 'node-fetch';
import fs from 'fs';
import FormData from 'form-data';
export const BtoA = (v:string) => Buffer.from(v).toString('base64');
async function FetchReadme(path:string,{method,body,headers}:{method:'GET'|'POST'|'PUT',body?:any,headers?:any}){
  const res = await fetch(`https://dash.readme.com/api/v1${path}`, {
    "headers": {
      "authorization": `Basic ${BtoA(`YOUR_API_KEY`)}`,
      ...(headers??{})
    },
    method,
    body
  });
  return res;
}
async function SynchroniseReadmeSchema(){
  const specifications = await (await FetchReadme(`/api-specification`,{method:'GET'})).json();
  const mySpec = specifications.filter(spec => spec.title === 'YOUR_SPEC_NAME')[0];
  const form = new FormData();
  const buffer = fs.createReadStream('./YOUR_SCHEMA.json');
  form.append('spec', buffer);
  const putres = await FetchReadme(`/api-specification/${mySpec._id}`,{
    method:'PUT',
    body:form,
  });
}
SynchroniseReadmeSchema();

joshp-f avatar Apr 14 '22 02:04 joshp-f