Skip to content

Commit

Permalink
Merge pull request #9 from clark1013/digest-auth
Browse files Browse the repository at this point in the history
fix: add digest auth to code sample
  • Loading branch information
Oreoxmt authored Jul 18, 2022
2 parents 8766590 + 5074e83 commit f097b20
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/gencode.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
const OpenAPISnippet = require('openapi-snippet');
const fs = require("fs");
const targets = ["shell_curl", "shell_wget"]
const targets = ["shell_curl"]

async function genSampleCode(file) {
let openApi = JSON.parse(fs.readFileSync(file, 'utf8'));
openApi.components = {
securitySchemes: openApi.securityDefinitions
}

try {
Object.keys(openApi.paths).forEach(path => {
Object.keys(openApi.paths[path]).forEach(method => {
const snippets = OpenAPISnippet.getEndpointSnippets(openApi, path, method, targets);
const samples = []
openApi.paths[path][method]['x-code-samples'] = samples;
snippets.snippets.forEach(snippet => {
snippet.content = snippet.content.replace("curl", "curl --digest \\\n --user 'YOUR_PUBLIC_KEY:YOUR_PRIVATE_KEY' \\\n ").replaceAll("%7B", "{").replaceAll("%7D", "}");
samples.push({
lang: snippet.id.split('_')[1],
source: snippet.content
Expand Down

0 comments on commit f097b20

Please sign in to comment.