- Schema is to comonly used model name

This commit is contained in:
Ferdi Koomen 2019-12-16 11:34:57 +01:00
parent 49f95d33f8
commit 1b9de75df6
26 changed files with 609 additions and 680 deletions

View File

@ -1,6 +1,6 @@
{
"name": "openapi-typescript-codegen",
"version": "0.1.2",
"version": "0.1.3",
"description": "NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification.",
"author": "Ferdi Koomen",
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",

View File

@ -25,15 +25,15 @@ export { {{{this}}} } from './services/{{{this}}}';
{{/if}}
{{#if models}}
const schemas = {
const definitions = {
{{#each models}}
'{{{this}}}': {{{this}}}.schema,
'{{{this}}}': {{{this}}}.definition,
{{/each}}
};
export function getSchema(schema) {
if (schemas.hasOwnProperty(schema)) {
return schemas[schema];
export function getDefinition(definition) {
if (definitions.hasOwnProperty(definition)) {
return definitions[definition];
}
return null;
}

View File

@ -7,7 +7,7 @@
export let Dictionary;
(function (Dictionary) {
Dictionary.schema = {
Dictionary.definition = {
type: 'Dictionary',
item: {
type: 'any'

View File

@ -1,11 +1,11 @@
{{#equals export 'interface'}}
{{>schemaInterface}}
{{>definitionInterface}}
{{else equals export 'enum'}}
{{>schemaEnum}}
{{>definitionEnum}}
{{else equals export 'array'}}
{{>schemaArray}}
{{>definitionArray}}
{{else equals export 'dictionary'}}
{{>schemaDictionary}}
{{>definitionDictionary}}
{{else}}
{{>schemaGeneric}}
{{>definitionGeneric}}
{{/equals}}

View File

@ -1,11 +1,11 @@
{
type: 'Array',
{{#if link~}}
item: {{>schema link}},
item: {{>definition link}},
{{else}}
item: {
type: '{{{base}}}',
}
},
{{/if}}
{{#if isReadOnly~}}
isReadOnly: {{{isReadOnly}}},

View File

@ -1,11 +1,11 @@
{
type: 'Dictionary',
{{#if link~}}
item: {{>schema link}},
item: {{>definition link}},
{{else}}
item: {
type: '{{{base}}}',
}
},
{{/if}}
{{#if isReadOnly~}}
isReadOnly: {{{isReadOnly}}},

View File

@ -1,6 +1,6 @@
{
{{#each properties}}
{{{name}}}: {{>schema}},
{{{name}}}: {{>definition}},
{{/each}}
{{#if isReadOnly~}}
isReadOnly: {{{isReadOnly}}},

View File

@ -12,6 +12,6 @@ export let {{{name}}};
{{/each}}
{{/if}}
{{{name}}}.schema = {{>schema}};
{{{name}}}.definition = {{>definition}};
})({{{name}}} || ({{{name}}} = {}));

View File

@ -6,6 +6,6 @@
export let {{{name}}};
(function ({{{name}}}) {
{{{name}}}.schema = {{>schema}};
{{{name}}}.definition = {{>definition}};
})({{{name}}} || ({{{name}}} = {}));

View File

@ -21,6 +21,6 @@ export let {{{name}}};
{{/each}}
{{/if}}
{{{name}}}.schema = {{>schema}};
{{{name}}}.definition = {{>definition}};
})({{{name}}} || ({{{name}}} = {}));

View File

@ -5,7 +5,7 @@
import { Dictionary } from "../models/Dictionary";
type FieldSchema = {
type FieldDefinition = {
readonly type?: string;
readonly isReadOnly?: boolean;
readonly isRequired?: boolean;
@ -26,25 +26,25 @@ type FieldSchema = {
readonly minProperties?: number;
}
type ArraySchema<T> = FieldSchema & {
readonly item: Schema<T>;
type ArrayDefinition<T> = FieldDefinition & {
readonly item: Definition<T>;
}
type DictionarySchema<T> = FieldSchema & {
readonly item: Schema<T>;
type DictionaryDefinition<T> = FieldDefinition & {
readonly item: Definition<T>;
}
type ObjectSchema<T> = FieldSchema & {
readonly [K in keyof T]: Schema<T[K]>;
type ObjectDefinition<T> = FieldDefinition & {
readonly [K in keyof T]: Definition<T[K]>;
}
export type Schema<T> =
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> ? DictionarySchema<U> :
T extends Object ? ObjectSchema<T> :
FieldSchema
export type Definition<T> =
T extends string ? FieldDefinition :
T extends number ? FieldDefinition :
T extends boolean ? FieldDefinition :
T extends File ? FieldDefinition :
T extends Blob ? FieldDefinition :
T extends Array<infer U> ? ArrayDefinition<U> :
T extends Dictionary<infer U> ? DictionaryDefinition<U> :
T extends Object ? ObjectDefinition<T> :
FieldDefinition

View File

@ -4,9 +4,9 @@
/* prettier-ignore */
export { ApiError } from './core/ApiError';
export { Definition } from './core/Definition';
export { isSuccess } from './core/isSuccess';
export { OpenAPI } from './core/OpenAPI';
import { Schema } from './core/Schema';
{{#if models}}
{{#each models}}
@ -27,15 +27,15 @@ export { {{{this}}} } from './services/{{{this}}}';
{{/if}}
{{#if models}}
const schemas = {
const definitions = {
{{#each models}}
'{{{this}}}': {{{this}}}.schema,
'{{{this}}}': {{{this}}}.definition,
{{/each}}
};
export function getSchema<K extends keyof typeof schemas>(schema: K) {
if (schemas.hasOwnProperty(schema)) {
return schemas[schema];
export function getDefinition<K extends keyof typeof definitions>(definition: K) {
if (definitions.hasOwnProperty(definition)) {
return definitions[definition];
}
return null;
}

View File

@ -3,7 +3,7 @@
/* eslint-disable */
/* prettier-ignore */
import { Schema } from '../core/Schema';
import { Definition } from '../core/Definition';
{{#if imports}}
{{#each imports}}
import { {{{this}}} } from '../models/{{{this}}}';

View File

@ -3,7 +3,7 @@
/* eslint-disable */
/* prettier-ignore */
import { Schema } from '../core/Schema';
import { Definition } from '../core/Definition';
export interface Dictionary<T> {
@ -17,7 +17,7 @@ export interface Dictionary<T> {
export namespace Dictionary {
export const schema: Schema<Dictionary<any>> = {
export const definition: Definition<Dictionary<any>> = {
type: 'Dictionary',
item: {
type: 'any'

View File

@ -1,11 +1,11 @@
{{#equals export 'interface'}}
{{>schemaInterface}}
{{>definitionInterface}}
{{else equals export 'enum'}}
{{>schemaEnum}}
{{>definitionEnum}}
{{else equals export 'array'}}
{{>schemaArray}}
{{>definitionArray}}
{{else equals export 'dictionary'}}
{{>schemaDictionary}}
{{>definitionDictionary}}
{{else}}
{{>schemaGeneric}}
{{>definitionGeneric}}
{{/equals}}

View File

@ -1,9 +1,11 @@
{
type: 'Array',
{{#if link~}}
item: {{>schema link}},
item: {{>definition link}},
{{else}}
item: '{{{base}}}',
item: {
type: '{{{base}}}',
},
{{/if}}
{{#if isReadOnly~}}
isReadOnly: {{{isReadOnly}}},

View File

@ -1,9 +1,11 @@
{
type: 'Dictionary',
{{#if link~}}
item: {{>schema link}},
item: {{>definition link}},
{{else}}
item: '{{{base}}}',
item: {
type: '{{{base}}}',
},
{{/if}}
{{#if isReadOnly~}}
isReadOnly: {{{isReadOnly}}},

View File

@ -1,10 +1,5 @@
{
type: 'Enum',
enums: [
{{#each enum}}
{{{value}}},
{{/each}}
],
{{#if isReadOnly~}}
isReadOnly: {{{isReadOnly}}},
{{/if}}

View File

@ -1,6 +1,6 @@
{
{{#each properties}}
{{{name}}}: {{>schema}},
{{{name}}}: {{>definition}},
{{/each}}
{{#if isReadOnly~}}
isReadOnly: {{{isReadOnly}}},

View File

@ -11,6 +11,6 @@ export enum {{{name}}} {
export namespace {{{name}}} {
export const schema: Schema<{{{name}}}> = {{>schema}};
export const definition: Definition<{{{name}}}> = {{>definition}};
}

View File

@ -7,6 +7,6 @@ export type {{{name}}} = {{>type}};
export namespace {{{name}}} {
export const schema: Schema<{{{name}}}> = {{>schema}};
export const definition: Definition<{{{name}}}> = {{>definition}};
}

View File

@ -31,6 +31,6 @@ export namespace {{{name}}} {
{{/each}}
{{/if}}
export const schema: Schema<{{{name}}}> = {{>schema}};
export const definition: Definition<{{{name}}}> = {{>definition}};
}

File diff suppressed because it is too large Load Diff