mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Almost ready
This commit is contained in:
parent
eca24b0c35
commit
5193884511
@ -3,7 +3,9 @@
|
||||
/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
|
||||
export type FieldSchema = {
|
||||
import { Dictionary } from "../models/Dictionary";
|
||||
|
||||
type FieldSchema = {
|
||||
readonly type?: string;
|
||||
readonly isReadOnly?: boolean;
|
||||
readonly isRequired?: boolean;
|
||||
@ -24,8 +26,22 @@ export type FieldSchema = {
|
||||
readonly minProperties?: number;
|
||||
}
|
||||
|
||||
export type Schema<T> = FieldSchema & {
|
||||
readonly item?: string | Schema<T> | FieldSchema;
|
||||
} & {
|
||||
readonly [K in keyof T]: Schema<T[K]> | FieldSchema;
|
||||
type ArraySchema<T> = FieldSchema & {
|
||||
readonly item: Schema<T>;
|
||||
}
|
||||
|
||||
type ObjectSchema<T> = FieldSchema & {
|
||||
readonly [K in keyof T]: Schema<T[K]>;
|
||||
}
|
||||
|
||||
export type Schema<T = any> =
|
||||
T extends string ? FieldSchema :
|
||||
T extends number ? FieldSchema :
|
||||
T extends boolean ? FieldSchema :
|
||||
T extends File ? FieldSchema :
|
||||
T extends Blob ? FieldSchema :
|
||||
T extends Array<infer U> ? ArraySchema<U> :
|
||||
// T extends Dictionary<infer U> ? ArraySchema<U> :
|
||||
// Check if infer type!
|
||||
T extends Object ? ObjectSchema<T> :
|
||||
FieldSchema
|
||||
|
||||
@ -27,13 +27,13 @@ export { {{{this}}} } from './services/{{{this}}}';
|
||||
{{/if}}
|
||||
{{#if models}}
|
||||
|
||||
const schemas = {
|
||||
const schemas: Schema = {
|
||||
{{#each models}}
|
||||
'{{{this}}}': {{{this}}}.schema,
|
||||
{{/each}}
|
||||
};
|
||||
|
||||
export function getSchema<T>(schema: string): Schema<T> | FieldSchema | null {
|
||||
export function getSchema<T>(schema: string): Schema<T> | null {
|
||||
if (schemas.hasOwnProperty(schema)) {
|
||||
return schemas[schema];
|
||||
}
|
||||
|
||||
@ -3,7 +3,9 @@
|
||||
{{#if link~}}
|
||||
item: {{>schema link}},
|
||||
{{else}}
|
||||
item: '{{{base}}}',
|
||||
item: {
|
||||
type: '{{{base}}}',
|
||||
}
|
||||
{{/if}}
|
||||
{{#if isReadOnly~}}
|
||||
isReadOnly: {{{isReadOnly}}},
|
||||
|
||||
@ -3,7 +3,9 @@
|
||||
{{#if link~}}
|
||||
item: {{>schema link}},
|
||||
{{else}}
|
||||
item: '{{{base}}}',
|
||||
item: {
|
||||
type: '{{{base}}}',
|
||||
}
|
||||
{{/if}}
|
||||
{{#if isReadOnly~}}
|
||||
isReadOnly: {{{isReadOnly}}},
|
||||
|
||||
@ -1,10 +1,5 @@
|
||||
{
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
{{#each enum}}
|
||||
{{{value}}},
|
||||
{{/each}}
|
||||
],
|
||||
{{#if isReadOnly~}}
|
||||
isReadOnly: {{{isReadOnly}}},
|
||||
{{/if}}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user