Comparing version 0.1.9 to 0.1.10
@@ -134,5 +134,5 @@ "use strict"; | ||
if (contentSpec) { | ||
Object.entries(contentSpec).forEach(([contentType, spec]) => { | ||
Object.entries(contentSpec).forEach(([contentType, contentSpec]) => { | ||
var _a, _b; | ||
const schemaRef = spec['schema']; | ||
const schemaRef = contentSpec['schema']; | ||
if (schemaRef) { | ||
@@ -144,9 +144,23 @@ const schema = this.parseSchemaRef(schemaRef); | ||
} | ||
this.parseExamples(contentSpec['examples']); | ||
}); | ||
} | ||
if (emptyBody) { | ||
this.doc.para('Empty body.'); | ||
// this.doc.para('Empty body.'); | ||
} | ||
this.doc.lineBreak(); | ||
} | ||
parseExamples(spec) { | ||
if (!spec) { | ||
return; | ||
} | ||
Object.entries(spec).forEach(([name, spec]) => { | ||
if ((spec === null || spec === void 0 ? void 0 : spec.value) && Object.keys(spec.value).length > 0) { | ||
const exampleBody = typeof spec.value === 'object' ? JSON.stringify(spec.value, null, 2) : spec.value; | ||
if (exampleBody) { | ||
this.doc.example(name, exampleBody); | ||
} | ||
} | ||
}); | ||
} | ||
saveSchemasToParseLater(schemas) { | ||
@@ -153,0 +167,0 @@ Object.entries(schemas).forEach(([key, value]) => { |
@@ -16,2 +16,3 @@ "use strict"; | ||
EFont[EFont["BOLD_ITALIC"] = 3] = "BOLD_ITALIC"; | ||
EFont[EFont["MONOSPACED"] = 4] = "MONOSPACED"; | ||
})(EFont || (EFont = {})); | ||
@@ -54,8 +55,7 @@ ; | ||
'Helvetica-Oblique', | ||
'Helvetica-BoldOblique' | ||
'Helvetica-BoldOblique', | ||
'Courier-Bold' | ||
]; | ||
// calculated in applyStyle() | ||
this.paraGap = 0; | ||
this.subHeaderGap = 0; | ||
this.headerGap = 0; | ||
this.headerGap = 0.7; | ||
this.paraGap = 0.5; | ||
this.baseStyle = { | ||
@@ -71,3 +71,2 @@ font: EFont.NORM, | ||
} | ||
this.applyStyle(); | ||
this.doc = new PDFDocument({ | ||
@@ -122,2 +121,6 @@ bufferPages: true, | ||
} | ||
lineBreak(n = 1) { | ||
this.doc.moveDown(n); | ||
return this; | ||
} | ||
text(str, style, options) { | ||
@@ -146,3 +149,6 @@ if (style && Object.keys(style).length > 0) { | ||
header(level, str, anchor) { | ||
this.text(str, { fillColor: this.style.color.headers, font: EFont.BOLD, fontSize: this.style.font.baseSize + 4 - level * 2, lineGap: this.headerGap - level * 3 }, { destination: anchor }); | ||
this.withStyle({ fillColor: this.style.color.headers, font: EFont.BOLD, fontSize: this.style.font.baseSize + 4 - level * 2 }, () => { | ||
this.text(str, {}, { destination: anchor }); | ||
this.lineBreak(this.headerGap); | ||
}); | ||
this.addOutline(level, str); | ||
@@ -174,3 +180,3 @@ } | ||
this.text(` ${endpoint}`, { fillColor: this.style.color.headers }); | ||
this.doc.moveDown(0.7); | ||
this.lineBreak(this.headerGap); | ||
}); | ||
@@ -210,10 +216,10 @@ this.addOutline(headerLevel, `${method} ${endpoint}`); | ||
subHeader(str) { | ||
this.text(str, { fillColor: this.style.color.subHeaders, font: EFont.BOLD, fontSize: this.style.font.baseSize, lineGap: this.subHeaderGap }); | ||
this.withStyle({ fillColor: this.style.color.subHeaders, font: EFont.BOLD, fontSize: this.style.font.baseSize }, () => { | ||
this.text(str); | ||
this.lineBreak(this.headerGap); | ||
}); | ||
} | ||
lineBreak(n = 1) { | ||
this.doc.moveDown(n); | ||
return this; | ||
} | ||
para(str) { | ||
this.text(str, { lineGap: this.paraGap }); | ||
this.text(str); | ||
this.lineBreak(this.paraGap); | ||
return this; | ||
@@ -261,7 +267,2 @@ } | ||
} | ||
objectSchema(dataFields) { | ||
this.text('{').indentStart(); | ||
this.dataFields(dataFields); | ||
this.indentEnd().text('}'); | ||
} | ||
schemaType(typeName, contentType) { | ||
@@ -275,3 +276,14 @@ if (contentType) { | ||
this.text(typeName, { fillColor: this.style.color.highlight }); | ||
this.lineBreak(this.paraGap); | ||
} | ||
objectSchema(dataFields) { | ||
this.text('{').indentStart(); | ||
this.dataFields(dataFields); | ||
this.indentEnd().text('}'); | ||
} | ||
example(name, body) { | ||
this.text(`Example "${name}":`, { font: EFont.BOLD }); | ||
this.lineBreak(this.paraGap); | ||
this.text(body, { fillColor: this.style.color.highlight, fontSize: this.style.font.baseSize - 2, font: EFont.MONOSPACED }); | ||
} | ||
enumValues(values) { | ||
@@ -316,7 +328,2 @@ this.text('Values: '); | ||
} | ||
applyStyle() { | ||
this.paraGap = this.style.font.baseSize / 3; | ||
this.subHeaderGap = this.style.font.baseSize / 2; | ||
this.headerGap = this.style.font.baseSize + 4; | ||
} | ||
setStyle(style) { | ||
@@ -323,0 +330,0 @@ var _a; |
{ | ||
"name": "apibake", | ||
"version": "0.1.9", | ||
"description": "OpenAPI to PDF generator.", | ||
"version": "0.1.10", | ||
"description": "Convert OpenAPI spec to PDF.", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "OpenAPI", |
@@ -163,4 +163,4 @@ import { log } from './logger'; | ||
if (contentSpec) { | ||
Object.entries(contentSpec).forEach(([contentType, spec]) => { | ||
const schemaRef = spec['schema'] as ApiSpec; | ||
Object.entries(contentSpec).forEach(([contentType, contentSpec]) => { | ||
const schemaRef = contentSpec['schema'] as ApiSpec; | ||
if (schemaRef) { | ||
@@ -172,6 +172,8 @@ const schema = this.parseSchemaRef(schemaRef); | ||
} | ||
this.parseExamples(contentSpec['examples'] as ApiSpec); | ||
}); | ||
} | ||
if (emptyBody) { | ||
this.doc.para('Empty body.'); | ||
// this.doc.para('Empty body.'); | ||
} | ||
@@ -181,2 +183,16 @@ this.doc.lineBreak(); | ||
private parseExamples(spec: ApiSpec) { | ||
if (!spec) { | ||
return; | ||
} | ||
Object.entries(spec).forEach(([name, spec]) => { | ||
if (spec?.value && Object.keys(spec.value).length > 0) { | ||
const exampleBody = typeof spec.value === 'object' ? JSON.stringify(spec.value, null, 2) : spec.value; | ||
if (exampleBody) { | ||
this.doc.example(name, exampleBody); | ||
} | ||
} | ||
}); | ||
} | ||
private saveSchemasToParseLater(schemas: ApiSpec) { | ||
@@ -183,0 +199,0 @@ Object.entries(schemas).forEach(([key, value]) => { |
@@ -30,2 +30,3 @@ import fs from 'fs'; | ||
BOLD_ITALIC = 3, | ||
MONOSPACED = 4 | ||
}; | ||
@@ -75,9 +76,8 @@ | ||
'Helvetica-Oblique', | ||
'Helvetica-BoldOblique' | ||
'Helvetica-BoldOblique', | ||
'Courier-Bold' | ||
]; | ||
// calculated in applyStyle() | ||
private paraGap = 0; | ||
private subHeaderGap = 0; | ||
private headerGap = 0; | ||
private headerGap = 0.7; | ||
private paraGap = 0.5; | ||
@@ -96,3 +96,2 @@ private baseStyle: TextStyle = { | ||
} | ||
this.applyStyle(); | ||
@@ -157,2 +156,7 @@ this.doc = new PDFDocument({ | ||
lineBreak(n: number = 1): PdfWriter { | ||
this.doc.moveDown(n); | ||
return this; | ||
} | ||
text(str: string, style?: TextStyle, options?: TextOptions): PdfWriter { | ||
@@ -181,6 +185,6 @@ if (style && Object.keys(style).length > 0) { | ||
header(level: number, str: string, anchor?: string) { | ||
this.text(str, | ||
{ fillColor: this.style.color.headers, font: EFont.BOLD, fontSize: this.style.font.baseSize + 4 - level * 2, lineGap: this.headerGap - level * 3 }, | ||
{ destination: anchor } | ||
); | ||
this.withStyle({ fillColor: this.style.color.headers, font: EFont.BOLD, fontSize: this.style.font.baseSize + 4 - level * 2 }, () => { | ||
this.text(str, {}, { destination: anchor }); | ||
this.lineBreak(this.headerGap); | ||
}); | ||
this.addOutline(level, str); | ||
@@ -217,3 +221,3 @@ } | ||
this.text(` ${endpoint}`, { fillColor: this.style.color.headers }); | ||
this.doc.moveDown(0.7); | ||
this.lineBreak(this.headerGap); | ||
}); | ||
@@ -255,12 +259,11 @@ this.addOutline(headerLevel, `${method} ${endpoint}`); | ||
subHeader(str: string) { | ||
this.text(str, { fillColor: this.style.color.subHeaders, font: EFont.BOLD, fontSize: this.style.font.baseSize, lineGap: this.subHeaderGap }); | ||
this.withStyle({ fillColor: this.style.color.subHeaders, font: EFont.BOLD, fontSize: this.style.font.baseSize }, () => { | ||
this.text(str, ); | ||
this.lineBreak(this.headerGap); | ||
}); | ||
} | ||
lineBreak(n: number = 1): PdfWriter { | ||
this.doc.moveDown(n); | ||
return this; | ||
} | ||
para(str: string): PdfWriter { | ||
this.text(str, { lineGap: this.paraGap }); | ||
this.text(str); | ||
this.lineBreak(this.paraGap); | ||
return this; | ||
@@ -315,8 +318,2 @@ } | ||
objectSchema(dataFields: DataField[]) { | ||
this.text('{').indentStart(); | ||
this.dataFields(dataFields); | ||
this.indentEnd().text('}'); | ||
} | ||
schemaType(typeName: string, contentType?: string) { | ||
@@ -330,4 +327,17 @@ if (contentType) { | ||
this.text(typeName, { fillColor: this.style.color.highlight }); | ||
this.lineBreak(this.paraGap); | ||
} | ||
objectSchema(dataFields: DataField[]) { | ||
this.text('{').indentStart(); | ||
this.dataFields(dataFields); | ||
this.indentEnd().text('}'); | ||
} | ||
example(name: string, body: string) { | ||
this.text(`Example "${name}":`, { font: EFont.BOLD }); | ||
this.lineBreak(this.paraGap); | ||
this.text(body, { fillColor: this.style.color.highlight, fontSize: this.style.font.baseSize - 2, font: EFont.MONOSPACED }); | ||
} | ||
enumValues(values: string[]) { | ||
@@ -380,8 +390,2 @@ this.text('Values: '); | ||
private applyStyle() { | ||
this.paraGap = this.style.font.baseSize / 3; | ||
this.subHeaderGap = this.style.font.baseSize / 2; | ||
this.headerGap = this.style.font.baseSize + 4; | ||
} | ||
private setStyle(style: TextStyle) { | ||
@@ -388,0 +392,0 @@ this.doc.font(this.fonts[style.font ?? 0]).fontSize(style.fontSize).fillColor(style.fillColor); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72680
1829