mirror of
https://github.com/LukeHagar/openapi-definition-generator.git
synced 2025-12-06 12:37:46 +00:00
Migrated to examples
This commit is contained in:
@@ -57,38 +57,38 @@ export type Config = {
|
|||||||
export type StringType = {
|
export type StringType = {
|
||||||
type: 'string';
|
type: 'string';
|
||||||
format?: string;
|
format?: string;
|
||||||
example?: string;
|
examples?: [string];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NumberType = {
|
export type NumberType = {
|
||||||
type: 'number';
|
type: 'number';
|
||||||
format?: string;
|
format?: string;
|
||||||
example?: number;
|
examples?: [number];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ObjectType = {
|
export type ObjectType = {
|
||||||
type: 'object';
|
type: 'object';
|
||||||
properties: { [key: string]: Output };
|
properties: { [key: string]: Output };
|
||||||
additionalProperties?: boolean;
|
additionalProperties?: boolean;
|
||||||
example?: object;
|
examples?: [object];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ArrayType = {
|
export type ArrayType = {
|
||||||
type: 'array';
|
type: 'array';
|
||||||
items?: Output | { oneOf: Output[] };
|
items?: Output | { oneOf: Output[] };
|
||||||
example?: unknown[];
|
examples?: [unknown[]];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type BooleanType = {
|
export type BooleanType = {
|
||||||
type: 'boolean';
|
type: 'boolean';
|
||||||
format?: string;
|
format?: string;
|
||||||
example?: boolean;
|
examples?: [boolean];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type IntegerType = {
|
export type IntegerType = {
|
||||||
type: 'integer';
|
type: 'integer';
|
||||||
format?: string;
|
format?: string;
|
||||||
example?: number;
|
examples?: [number];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NullableType = {
|
export type NullableType = {
|
||||||
@@ -120,7 +120,7 @@ export function convertNumber(number: number, config: Config) {
|
|||||||
output = { type: 'number' } as NumberType;
|
output = { type: 'number' } as NumberType;
|
||||||
}
|
}
|
||||||
if (config.includeExamples) {
|
if (config.includeExamples) {
|
||||||
output.example = number;
|
output.examples = [number];
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
@@ -199,7 +199,7 @@ export function convertString(string: string, config: Config) {
|
|||||||
} else if (regxDate.test(string)) {
|
} else if (regxDate.test(string)) {
|
||||||
output.format = 'date';
|
output.format = 'date';
|
||||||
}
|
}
|
||||||
if (config.includeExamples) output.example = string;
|
if (config.includeExamples) output.examples = [string];
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@@ -224,7 +224,7 @@ export function convertObject(input: unknown, config: Config) {
|
|||||||
return convertString(input, config);
|
return convertString(input, config);
|
||||||
} else if (typeof input === 'boolean') {
|
} else if (typeof input === 'boolean') {
|
||||||
const output: BooleanType = { type: 'boolean' };
|
const output: BooleanType = { type: 'boolean' };
|
||||||
if (config.includeExamples) output.example = input;
|
if (config.includeExamples) output.examples = [input];
|
||||||
return output;
|
return output;
|
||||||
} else if (input === undefined) {
|
} else if (input === undefined) {
|
||||||
throw new Error(`undefined cannot be converted to OAS`);
|
throw new Error(`undefined cannot be converted to OAS`);
|
||||||
|
|||||||
Reference in New Issue
Block a user