Skip to content

Commit

Permalink
fix(includers/openapi): bubble up erroneous values
Browse files Browse the repository at this point in the history
  • Loading branch information
moki committed Mar 31, 2023
1 parent 619fc90 commit bd8f0b4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/services/includers/batteries/openapi/generators/traverse.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import {JsType, Refs, SupportedEnumType} from '../types';
import {JSONSchema6} from 'json-schema';
import {table} from './common';
import slugify from 'slugify';
import stringify from 'json-stringify-safe';

import {concatNewLine} from '../../common';
import {openapiBlock} from './constants';
import {SUPPORTED_ENUM_TYPES} from '../constants';

import {JsType, Refs, SupportedEnumType} from '../types';

type TableRow = [string, string, string];

function anchor(ref: string) {
Expand Down Expand Up @@ -241,14 +244,17 @@ function inferType(value: OpenJSONSchema): Exclude<JSONSchema6['type'], undefine
if (value.type) {
return value.type;
}

if (value.enum) {
const enumType = typeof value.enum[0];
if (isSupportedEnumType(enumType)) {
return enumType;
}
throw new Error('Unsupported enum type');

throw new Error(`Unsupported enum type in value: ${stringify(value)}`);
}
throw new Error('Unsupported value type');

throw new Error(`Unsupported value: ${stringify(value)}`);
}

function isSupportedEnumType(enumType: JsType): enumType is SupportedEnumType {
Expand Down

0 comments on commit bd8f0b4

Please sign in to comment.