Skip to content

Commit

Permalink
fix(includers/openapi): default value in query
Browse files Browse the repository at this point in the history
  • Loading branch information
amosov-f authored and moki committed Jan 30, 2023
1 parent ca36fef commit cdc00a3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/services/includers/batteries/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ const compose = <R>(fn1: (a: R) => R, ...fns: Array<(a: R) => R>) =>

const prop = (string: string) => (object: Object) => object[string as keyof typeof object];

export {complement, isMdExtension, isHidden, allPass, compose, prop, getDirs, getFiles};
function concatNewLine(prefix: string, suffix: string) {
return prefix.trim().length ? `${prefix}<br>${suffix}` : suffix;
}

export {complement, isMdExtension, isHidden, allPass, compose, prop, getDirs, getFiles, concatNewLine};
12 changes: 8 additions & 4 deletions src/services/includers/batteries/openapi/generators/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '../types';
import stringify from 'json-stringify-safe';
import {prepareTableRowData, prepareSampleObject, tableFromSchema, tableParameterName} from './traverse';
import {concatNewLine} from '../../common';

function endpoint(allRefs: Refs, data: Endpoint) {
// try to remember, which tables we are already printed on page
Expand Down Expand Up @@ -84,12 +85,15 @@ function parameters(params?: Parameters) {

function parameterRow(param: Parameter) {
const row = prepareTableRowData({}, param.schema, param.name);
let description = param.description;
let description = param.description ?? '';
if (row.description.length) {
description += `<br>${row.description}`;
description = concatNewLine(description, row.description);
}
if (param.example) {
description += `<br>Example: \`${param.example}\``;
if (param.example !== undefined) {
description = concatNewLine(description, `Example: \`${param.example}\``);
}
if (param.default !== undefined) {
description = concatNewLine(description, `Default: \`${param.default}\``);
}
return [tableParameterName(param.name, param.required), row.type, description];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Refs} from '../types';
import {JSONSchema6, JSONSchema6Definition} from 'json-schema';
import {table} from './common';
import slugify from 'slugify';
import {concatNewLine} from '../../common';

type TableRow = [string, string, string];

Expand Down Expand Up @@ -201,7 +202,3 @@ function merge(value: JSONSchema6Definition): JSONSchema6 {
}
return {type: 'object', description, properties};
}

function concatNewLine(prefix: string, suffix: string) {
return prefix.trim().length ? `${prefix}<br>${suffix}` : suffix;
}
7 changes: 5 additions & 2 deletions src/services/includers/batteries/openapi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ export type Parameters = Parameter[];

export type In = 'path' | 'query' | 'header' | 'cookie';

export type Primitive = string | number | boolean;

export type Parameter = {
name: string;
in: In;
required: boolean;
description: string;
example: string | number;
description?: string;
example?: Primitive;
default?: Primitive;
schema: JSONSchema6;
};

Expand Down

0 comments on commit cdc00a3

Please sign in to comment.