mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Added getSchema
This commit is contained in:
parent
7d044b8477
commit
eca24b0c35
@ -8,7 +8,11 @@ export { OpenAPI } from './core/OpenAPI';
|
||||
{{#if models}}
|
||||
|
||||
{{#each models}}
|
||||
export { {{{this}}} } from './models/{{{this}}}';
|
||||
import { {{{this}}} } from './models/{{{this}}}';
|
||||
{{/each}}
|
||||
|
||||
{{#each models}}
|
||||
export { {{{this}}} };
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{#if services}}
|
||||
@ -17,3 +21,18 @@ export { {{{this}}} } from './models/{{{this}}}';
|
||||
export { {{{this}}} } from './services/{{{this}}}';
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{#if models}}
|
||||
|
||||
const schemas = {
|
||||
{{#each models}}
|
||||
'{{{this}}}': {{{this}}}.schema,
|
||||
{{/each}}
|
||||
};
|
||||
|
||||
export function getSchema(schema) {
|
||||
if (schemas.hasOwnProperty(schema)) {
|
||||
return schemas[schema];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
{{/if}}
|
||||
|
||||
@ -2,12 +2,6 @@
|
||||
/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
|
||||
{{#if imports}}
|
||||
{{#each imports}}
|
||||
import { {{{this}}} } from '../models/{{{this}}}';
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
|
||||
{{#equals export 'interface'}}
|
||||
{{>exportInterface}}
|
||||
{{else equals export 'enum'}}
|
||||
|
||||
12
src/templates/javascript/models/Dictionary.js
Normal file
12
src/templates/javascript/models/Dictionary.js
Normal file
@ -0,0 +1,12 @@
|
||||
/* istanbul ignore file */
|
||||
/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
|
||||
export let Dictionary;
|
||||
(function (Dictionary) {
|
||||
|
||||
Dictionary.schema = {
|
||||
type: 'Dictionary'
|
||||
};
|
||||
|
||||
})(Dictionary || (Dictionary = {}));
|
||||
@ -1,5 +1,10 @@
|
||||
{
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
{{#each enum}}
|
||||
{{{value}}},
|
||||
{{/each}}
|
||||
],
|
||||
{{#if isReadOnly~}}
|
||||
isReadOnly: {{{isReadOnly}}},
|
||||
{{/if}}
|
||||
|
||||
31
src/templates/typescript/core/Schema.ts
Normal file
31
src/templates/typescript/core/Schema.ts
Normal file
@ -0,0 +1,31 @@
|
||||
/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
|
||||
export type FieldSchema = {
|
||||
readonly type?: string;
|
||||
readonly isReadOnly?: boolean;
|
||||
readonly isRequired?: boolean;
|
||||
readonly isNullable?: boolean;
|
||||
readonly format?: 'int32' | 'int64' | 'float' | 'double' | 'string' | 'boolean' | 'byte' | 'binary' | 'date' | 'date-time' | 'password';
|
||||
readonly maximum?: number;
|
||||
readonly exclusiveMaximum?: boolean;
|
||||
readonly minimum?: number;
|
||||
readonly exclusiveMinimum?: boolean;
|
||||
readonly multipleOf?: number;
|
||||
readonly maxLength?: number;
|
||||
readonly minLength?: number;
|
||||
readonly pattern?: string;
|
||||
readonly maxItems?: number;
|
||||
readonly minItems?: number;
|
||||
readonly uniqueItems?: boolean;
|
||||
readonly maxProperties?: number;
|
||||
readonly minProperties?: number;
|
||||
}
|
||||
|
||||
export type Schema<T> = FieldSchema & {
|
||||
readonly item?: string | Schema<T> | FieldSchema;
|
||||
} & {
|
||||
readonly [K in keyof T]: Schema<T[K]> | FieldSchema;
|
||||
}
|
||||
@ -6,10 +6,17 @@
|
||||
export { ApiError } from './core/ApiError';
|
||||
export { isSuccess } from './core/isSuccess';
|
||||
export { OpenAPI } from './core/OpenAPI';
|
||||
import { FieldSchema, Schema } from './core/Schema';
|
||||
{{#if models}}
|
||||
|
||||
{{#each models}}
|
||||
export { {{{this}}} } from './models/{{{this}}}';
|
||||
import { {{{this}}} } from './models/{{{this}}}';
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{#if models}}
|
||||
|
||||
{{#each models}}
|
||||
export { {{{this}}} };
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{#if services}}
|
||||
@ -18,3 +25,19 @@ export { {{{this}}} } from './models/{{{this}}}';
|
||||
export { {{{this}}} } from './services/{{{this}}}';
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{#if models}}
|
||||
|
||||
const schemas = {
|
||||
{{#each models}}
|
||||
'{{{this}}}': {{{this}}}.schema,
|
||||
{{/each}}
|
||||
};
|
||||
|
||||
export function getSchema<T>(schema: string): Schema<T> | FieldSchema | null {
|
||||
if (schemas.hasOwnProperty(schema)) {
|
||||
return schemas[schema];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
{{/if}}
|
||||
|
||||
@ -2,8 +2,9 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
{{#if imports}}
|
||||
|
||||
import { Schema } from '../core/Schema';
|
||||
{{#if imports}}
|
||||
{{#each imports}}
|
||||
import { {{{this}}} } from '../models/{{{this}}}';
|
||||
{{/each}}
|
||||
|
||||
@ -3,6 +3,16 @@
|
||||
/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
|
||||
import { Schema } from '../core/Schema';
|
||||
|
||||
export interface Dictionary<T> {
|
||||
[key: string]: T;
|
||||
}
|
||||
|
||||
export namespace Dictionary {
|
||||
|
||||
export const schema: Schema<Dictionary> = {
|
||||
type: 'Dictionary'
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -11,6 +11,6 @@ export enum {{{name}}} {
|
||||
|
||||
export namespace {{{name}}} {
|
||||
|
||||
export const schema = {{>schema}};
|
||||
export const schema: Schema<{{{name}}}> = {{>schema}};
|
||||
|
||||
}
|
||||
|
||||
@ -7,6 +7,6 @@ export type {{{name}}} = {{>type}};
|
||||
|
||||
export namespace {{{name}}} {
|
||||
|
||||
export const schema = {{>schema}};
|
||||
export const schema: Schema<{{{name}}}> = {{>schema}};
|
||||
|
||||
}
|
||||
|
||||
@ -31,6 +31,6 @@ export namespace {{{name}}} {
|
||||
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
export const schema = {{>schema}};
|
||||
export const schema: Schema<{{{name}}}> = {{>schema}};
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
{
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
{{#each enum}}
|
||||
{{{value}}},
|
||||
{{/each}}
|
||||
],
|
||||
{{#if isReadOnly~}}
|
||||
isReadOnly: {{{isReadOnly}}},
|
||||
{{/if}}
|
||||
|
||||
@ -687,6 +687,11 @@ export let EnumFromDescription;
|
||||
|
||||
EnumFromDescription.schema = {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
3,
|
||||
1,
|
||||
2,
|
||||
],
|
||||
};
|
||||
|
||||
})(EnumFromDescription || (EnumFromDescription = {}));"
|
||||
@ -710,6 +715,11 @@ export let EnumWithNumbers;
|
||||
|
||||
EnumWithNumbers.schema = {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
};
|
||||
|
||||
})(EnumWithNumbers || (EnumWithNumbers = {}));"
|
||||
@ -733,6 +743,11 @@ export let EnumWithStrings;
|
||||
|
||||
EnumWithStrings.schema = {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Error',
|
||||
'Success',
|
||||
'Warning',
|
||||
],
|
||||
};
|
||||
|
||||
})(EnumWithStrings || (EnumWithStrings = {}));"
|
||||
@ -986,6 +1001,11 @@ export let ModelWithEnum;
|
||||
ModelWithEnum.schema = {
|
||||
test: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Success',
|
||||
'Warning',
|
||||
'Error',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
@ -1016,6 +1036,11 @@ export let ModelWithEnumFromDescription;
|
||||
ModelWithEnumFromDescription.schema = {
|
||||
test: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
@ -1084,24 +1109,44 @@ export let ModelWithNestedEnums;
|
||||
type: 'Array',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
},
|
||||
},
|
||||
arrayWithEnum: {
|
||||
type: 'Array',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Success',
|
||||
'Warning',
|
||||
'Error',
|
||||
],
|
||||
},
|
||||
},
|
||||
dictionaryWithEnum: {
|
||||
type: 'Dictionary',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Success',
|
||||
'Warning',
|
||||
'Error',
|
||||
],
|
||||
},
|
||||
},
|
||||
dictionaryWithEnumFromDescription: {
|
||||
type: 'Dictionary',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -2496,6 +2541,11 @@ export namespace EnumFromDescription {
|
||||
|
||||
export const schema = {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
3,
|
||||
1,
|
||||
2,
|
||||
],
|
||||
};
|
||||
|
||||
}"
|
||||
@ -2520,6 +2570,11 @@ export namespace EnumWithNumbers {
|
||||
|
||||
export const schema = {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
};
|
||||
|
||||
}"
|
||||
@ -2544,6 +2599,11 @@ export namespace EnumWithStrings {
|
||||
|
||||
export const schema = {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Error',
|
||||
'Success',
|
||||
'Warning',
|
||||
],
|
||||
};
|
||||
|
||||
}"
|
||||
@ -2845,6 +2905,11 @@ export namespace ModelWithEnum {
|
||||
export const schema = {
|
||||
test: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Success',
|
||||
'Warning',
|
||||
'Error',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
@ -2881,6 +2946,11 @@ export namespace ModelWithEnumFromDescription {
|
||||
export const schema = {
|
||||
test: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
@ -2966,24 +3036,44 @@ export namespace ModelWithNestedEnums {
|
||||
type: 'Array',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
},
|
||||
},
|
||||
arrayWithEnum: {
|
||||
type: 'Array',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Success',
|
||||
'Warning',
|
||||
'Error',
|
||||
],
|
||||
},
|
||||
},
|
||||
dictionaryWithEnum: {
|
||||
type: 'Dictionary',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Success',
|
||||
'Warning',
|
||||
'Error',
|
||||
],
|
||||
},
|
||||
},
|
||||
dictionaryWithEnumFromDescription: {
|
||||
type: 'Dictionary',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -4339,6 +4429,11 @@ export let EnumFromDescription;
|
||||
|
||||
EnumFromDescription.schema = {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
3,
|
||||
1,
|
||||
2,
|
||||
],
|
||||
};
|
||||
|
||||
})(EnumFromDescription || (EnumFromDescription = {}));"
|
||||
@ -4362,6 +4457,11 @@ export let EnumWithNumbers;
|
||||
|
||||
EnumWithNumbers.schema = {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
};
|
||||
|
||||
})(EnumWithNumbers || (EnumWithNumbers = {}));"
|
||||
@ -4385,6 +4485,11 @@ export let EnumWithStrings;
|
||||
|
||||
EnumWithStrings.schema = {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Error',
|
||||
'Success',
|
||||
'Warning',
|
||||
],
|
||||
};
|
||||
|
||||
})(EnumWithStrings || (EnumWithStrings = {}));"
|
||||
@ -4638,6 +4743,11 @@ export let ModelWithEnum;
|
||||
ModelWithEnum.schema = {
|
||||
Test: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Success',
|
||||
'Warning',
|
||||
'Error',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
@ -4668,6 +4778,11 @@ export let ModelWithEnumFromDescription;
|
||||
ModelWithEnumFromDescription.schema = {
|
||||
Test: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
@ -4736,24 +4851,44 @@ export let ModelWithNestedEnums;
|
||||
type: 'Array',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
},
|
||||
},
|
||||
arrayWithEnum: {
|
||||
type: 'Array',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Success',
|
||||
'Warning',
|
||||
'Error',
|
||||
],
|
||||
},
|
||||
},
|
||||
dictionaryWithEnum: {
|
||||
type: 'Dictionary',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Success',
|
||||
'Warning',
|
||||
'Error',
|
||||
],
|
||||
},
|
||||
},
|
||||
dictionaryWithEnumFromDescription: {
|
||||
type: 'Dictionary',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -6161,6 +6296,11 @@ export namespace EnumFromDescription {
|
||||
|
||||
export const schema = {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
3,
|
||||
1,
|
||||
2,
|
||||
],
|
||||
};
|
||||
|
||||
}"
|
||||
@ -6185,6 +6325,11 @@ export namespace EnumWithNumbers {
|
||||
|
||||
export const schema = {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
};
|
||||
|
||||
}"
|
||||
@ -6209,6 +6354,11 @@ export namespace EnumWithStrings {
|
||||
|
||||
export const schema = {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Error',
|
||||
'Success',
|
||||
'Warning',
|
||||
],
|
||||
};
|
||||
|
||||
}"
|
||||
@ -6510,6 +6660,11 @@ export namespace ModelWithEnum {
|
||||
export const schema = {
|
||||
Test: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Success',
|
||||
'Warning',
|
||||
'Error',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
@ -6546,6 +6701,11 @@ export namespace ModelWithEnumFromDescription {
|
||||
export const schema = {
|
||||
Test: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
@ -6631,24 +6791,44 @@ export namespace ModelWithNestedEnums {
|
||||
type: 'Array',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
},
|
||||
},
|
||||
arrayWithEnum: {
|
||||
type: 'Array',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Success',
|
||||
'Warning',
|
||||
'Error',
|
||||
],
|
||||
},
|
||||
},
|
||||
dictionaryWithEnum: {
|
||||
type: 'Dictionary',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
'Success',
|
||||
'Warning',
|
||||
'Error',
|
||||
],
|
||||
},
|
||||
},
|
||||
dictionaryWithEnumFromDescription: {
|
||||
type: 'Dictionary',
|
||||
item: {
|
||||
type: 'Enum',
|
||||
enums: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -28,5 +28,5 @@ OpenAPI.generate(
|
||||
OpenAPI.HttpClient.XHR,
|
||||
);
|
||||
|
||||
// OpenAPI.compile('./test/result/v2/typescript/');
|
||||
// OpenAPI.compile('./test/result/v3/typescript/');
|
||||
OpenAPI.compile('./test/result/v2/typescript/');
|
||||
OpenAPI.compile('./test/result/v3/typescript/');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user