mirror of
https://github.com/netbirdio/docs.git
synced 2026-04-16 07:26:35 +00:00
page titles
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import template from './templates/ApiTemplate'
|
||||
import { slugify, toArrayWithKey, toTitle, writeToDisk } from './helpers'
|
||||
import { OpenAPIV3, OpenAPIV2 } from 'openapi-types'
|
||||
import * as yaml from 'yaml';
|
||||
import * as fs from 'fs'
|
||||
import * as ejs from 'ejs'
|
||||
|
||||
export default async function gen(inputFileName: string, outputDir: string, apiUrl: string) {
|
||||
const specRaw = fs.readFileSync(inputFileName, 'utf8')
|
||||
const spec = yaml.parse(specRaw) as any
|
||||
const spec = JSON.parse(specRaw) as any
|
||||
// console.log('spec', spec)
|
||||
|
||||
switch (spec.openapi || spec.swagger) {
|
||||
@@ -167,6 +166,7 @@ async function gen_v3(spec: OpenAPIV3.Document, dest: string, { apiUrl }: { apiU
|
||||
|
||||
const content = ejs.render(template, {
|
||||
info: spec.info,
|
||||
tag: key,
|
||||
sections,
|
||||
operations,
|
||||
schemas,
|
||||
|
||||
@@ -3,6 +3,8 @@ import {HeroPattern} from "@/components/HeroPattern"; import {Note} from "@/comp
|
||||
|
||||
<HeroPattern />
|
||||
|
||||
export const title = '<%- tag %>'
|
||||
|
||||
<% operations.forEach(function(operation){ %>
|
||||
|
||||
## <%- operation.summary %> {{ tag: '<%- operation.operation.toUpperCase() %>' , label: '<%- operation.path %>' }}
|
||||
@@ -171,7 +173,7 @@ url = URI("<%- operation.fullPath %>")
|
||||
https = Net::HTTP.new(url.host, url.port)
|
||||
https.use_ssl = true
|
||||
|
||||
request = Net::HTTP::<% operation.operation.slice(0, 1).toUpperCase() + operation.operation.slice(1).toLowerCase() %>.new(url)
|
||||
request = Net::HTTP::<%- operation.operation.slice(0,1).toUpperCase() + operation.operation.slice(1).toLowerCase()%>.new(url)
|
||||
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>request["Content-Type"] = "application/json"<% }; %>
|
||||
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ -%>request["Accept"] = "application/json"<% }; %>
|
||||
request["Authorization"] = "Token <TOKEN>"
|
||||
@@ -185,11 +187,12 @@ puts response.read_body
|
||||
\`\`\`java
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.build();
|
||||
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
RequestBody body = RequestBody.create(mediaType, '<%- JSON.stringify(schemas.get(operation.requestBody?.content['application/json'].schema.$ref?.split('/').pop())?.examples, null, 2) %>');
|
||||
RequestBody body = RequestBody.create(mediaType, '<%- JSON.stringify(schemas.get(operation.requestBody?.content['application/json'].schema.$ref?.split('/').pop())?.examples, null, 2) %>');<% }; %>
|
||||
Request request = new Request.Builder()
|
||||
.url("<%- operation.fullPath %>")
|
||||
.method("<%- operation.operation.toUpperCase() %>", body)
|
||||
.method("<%- operation.operation.toUpperCase() %>"<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>, body<% }; %>)
|
||||
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>.addHeader("Content-Type", "application/json")<% }; %>
|
||||
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ -%>.addHeader("Accept", "application/json")<% }; %>
|
||||
.addHeader("Authorization: Token <TOKEN>")
|
||||
@@ -211,7 +214,8 @@ curl_setopt_array($curl, array(
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => '<%- operation.operation.toUpperCase() %>',
|
||||
CURLOPT_POSTFIELDS =>'<%- JSON.stringify(schemas.get(operation.requestBody?.content['application/json'].schema.$ref?.split('/').pop())?.examples, null, 2) %>',
|
||||
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>
|
||||
CURLOPT_POSTFIELDS =>'<%- JSON.stringify(schemas.get(operation.requestBody?.content['application/json'].schema.$ref?.split('/').pop())?.examples, null, 2) %>',<% }; %>
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ -%>'Content-Type: application/json',<% }; %>
|
||||
<% if(operation.responseList[0].content && operation.responseList[0].content['application/json']){ -%>'Accept: application/json',<% }; %>
|
||||
|
||||
Reference in New Issue
Block a user