Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync specs without requiring an API Definition ID #473

Open
Shanjeef opened this issue Mar 9, 2022 · 3 comments
Open

Sync specs without requiring an API Definition ID #473

Shanjeef opened this issue Mar 9, 2022 · 3 comments
Assignees
Labels
API Underlying issue is with the ReadMe API and not necessarily the `rdme` client itself command:openapi Issues pertaining to the `openapi`, `validate`, `reduce`, or `swagger` commands enhancement New feature or request

Comments

@Shanjeef
Copy link

Shanjeef commented Mar 9, 2022

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?

@kanadgupta kanadgupta added the enhancement New feature or request label Mar 10, 2022
@kanadgupta
Copy link
Member

kanadgupta commented Mar 10, 2022

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

@joshp-f
Copy link

joshp-f commented Apr 14, 2022

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
Copy link

joshp-f commented Apr 14, 2022

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();

@kanadgupta kanadgupta added the command:openapi Issues pertaining to the `openapi`, `validate`, `reduce`, or `swagger` commands label Jul 21, 2022
@kanadgupta kanadgupta added the API Underlying issue is with the ReadMe API and not necessarily the `rdme` client itself label Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Underlying issue is with the ReadMe API and not necessarily the `rdme` client itself command:openapi Issues pertaining to the `openapi`, `validate`, `reduce`, or `swagger` commands enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants