Merge branch 'master' into keywords

This commit is contained in:
Ferdi Koomen 2022-10-28 10:41:27 +02:00 committed by GitHub
commit 31ce4a23df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 910 additions and 542 deletions

View File

@ -48,7 +48,8 @@ $ openapi --help
--exportModels <value> Write models to disk (default: true)
--exportSchemas <value> Write schemas to disk (default: false)
--indent <value> Indentation options [4, 2, tab] (default: "4")
--postfix <value> Service name postfix (default: "Service")
--postfixServices Service name postfix (default: "Service")
--postfixModels Model name postfix
--request <value> Path to custom request file
-h, --help display help for command

View File

@ -21,7 +21,9 @@ const params = program
.option('--exportModels <value>', 'Write models to disk', true)
.option('--exportSchemas <value>', 'Write schemas to disk', false)
.option('--indent <value>', 'Indentation options [4, 2, tabs]', '4')
.option('--postfix <value>', 'Service name postfix', 'Service')
.option('--postfix <value>', 'Deprecated: Use --postfixServices instead. Service name postfix', 'Service')
.option('--postfixServices <value>', 'Service name postfix', 'Service')
.option('--postfixModels <value>', 'Model name postfix')
.option('--request <value>', 'Path to custom request file')
.parse(process.argv)
.opts();
@ -41,7 +43,8 @@ if (OpenAPI) {
exportModels: JSON.parse(params.exportModels) === true,
exportSchemas: JSON.parse(params.exportSchemas) === true,
indent: params.indent,
postfix: params.postfix,
postfixServices: params.postfixServices ?? params.postfix,
postfixModels: params.postfixModels,
request: params.request,
})
.then(() => {

View File

@ -34,8 +34,10 @@ describe('bin', () => {
'true',
'--indent',
'4',
'--postfix',
'--postfixServices',
'Service',
'--postfixModels',
'Dto',
]);
expect(result.stdout.toString()).toBe('');
expect(result.stderr.toString()).toBe('');
@ -67,4 +69,18 @@ describe('bin', () => {
expect(result.stdout.toString()).toContain(`-o, --output <value>`);
expect(result.stderr.toString()).toBe('');
});
it('should still support the deprecated --postfix parameter', () => {
const result = crossSpawn.sync('node', [
'./bin/index.js',
'--input',
'./test/spec/v3.json',
'--output',
'./test/generated/bin',
'--postfix',
'Service',
]);
expect(result.stdout.toString()).toBe('');
expect(result.stderr.toString()).toBe('');
});
});

View File

@ -18,7 +18,8 @@ $ openapi --help
--exportModels <value> Write models to disk (default: true)
--exportSchemas <value> Write schemas to disk (default: false)
--indent <value> Indentation options [4, 2, tab] (default: "4")
--postfix <value> Service name postfix (default: "Service")
--postfixServices Service name postfix (default: "Service")
--postfixModels Model name postfix
--request <value> Path to custom request file
-h, --help display help for command

1052
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -78,27 +78,27 @@
"@angular/platform-browser-dynamic": "14.0.1",
"@angular/router": "14.0.1",
"@babel/cli": "7.18.10",
"@babel/core": "7.18.10",
"@babel/preset-env": "7.18.10",
"@babel/core": "7.18.13",
"@babel/preset-env": "7.19.0",
"@babel/preset-typescript": "7.18.6",
"@rollup/plugin-commonjs": "22.0.2",
"@rollup/plugin-node-resolve": "13.3.0",
"@rollup/plugin-typescript": "8.3.4",
"@rollup/plugin-typescript": "8.5.0",
"@types/cross-spawn": "6.0.2",
"@types/express": "4.17.13",
"@types/fs-extra": "^9.0.13",
"@types/glob": "7.2.0",
"@types/jest": "28.1.6",
"@types/node": "18.6.5",
"@types/jest": "28.1.8",
"@types/node": "18.7.17",
"@types/node-fetch": "2.6.1",
"@types/qs": "6.9.7",
"@typescript-eslint/eslint-plugin": "5.33.0",
"@typescript-eslint/parser": "5.33.0",
"@typescript-eslint/eslint-plugin": "5.36.2",
"@typescript-eslint/parser": "5.37.0",
"abort-controller": "3.0.0",
"axios": "0.27.2",
"codecov": "3.8.3",
"cross-spawn": "7.0.3",
"eslint": "8.21.0",
"eslint": "8.23.1",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-simple-import-sort": "7.0.0",
@ -111,13 +111,13 @@
"puppeteer": "15.5.0",
"qs": "6.11.0",
"rimraf": "3.0.2",
"rollup": "2.77.2",
"rollup": "2.79.0",
"rollup-plugin-terser": "7.0.2",
"rxjs": "7.5.6",
"ts-node": "10.9.1",
"tslib": "2.4.0",
"typescript": "4.7.3",
"zone.js": "0.11.7"
"zone.js": "0.11.8"
},
"resolutions": {
"node-fetch": "2.6.7"

View File

@ -24,7 +24,8 @@ export type Options = {
exportModels?: boolean;
exportSchemas?: boolean;
indent?: Indent;
postfix?: string;
postfixServices?: string;
postfixModels?: string;
request?: string;
write?: boolean;
};
@ -44,7 +45,8 @@ export type Options = {
* @param exportModels Generate models
* @param exportSchemas Generate schemas
* @param indent Indentation options (4, 2 or tab)
* @param postfix Service name postfix
* @param postfixServices Service name postfix
* @param postfixModels Model name postfix
* @param request Path to custom request file
* @param write Write the files to disk (true or false)
*/
@ -60,7 +62,8 @@ export const generate = async ({
exportModels = true,
exportSchemas = false,
indent = Indent.SPACE_4,
postfix = 'Service',
postfixServices = 'Service',
postfixModels = '',
request,
write = true,
}: Options): Promise<void> => {
@ -89,7 +92,8 @@ export const generate = async ({
exportModels,
exportSchemas,
indent,
postfix,
postfixServices,
postfixModels,
clientName,
request
);
@ -112,7 +116,8 @@ export const generate = async ({
exportModels,
exportSchemas,
indent,
postfix,
postfixServices,
postfixModels,
clientName,
request
);

View File

@ -95,9 +95,13 @@ export const getModel = (
}
}
if (definition.type === 'object' && typeof definition.additionalProperties === 'object') {
if (definition.additionalProperties.$ref) {
const additionalProperties = getType(definition.additionalProperties.$ref);
if (
definition.type === 'object' &&
(typeof definition.additionalProperties === 'object' || definition.additionalProperties === true)
) {
const ap = typeof definition.additionalProperties === 'object' ? definition.additionalProperties : {};
if (ap.$ref) {
const additionalProperties = getType(ap.$ref);
model.export = 'dictionary';
model.type = additionalProperties.type;
model.base = additionalProperties.base;
@ -106,7 +110,7 @@ export const getModel = (
model.default = getModelDefault(definition, model);
return model;
} else {
const additionalProperties = getModel(openApi, definition.additionalProperties);
const additionalProperties = getModel(openApi, ap);
model.export = 'dictionary';
model.type = additionalProperties.type;
model.base = additionalProperties.base;
@ -146,12 +150,12 @@ export const getModel = (
}
if (definition.type === 'object') {
model.export = 'interface';
model.type = 'any';
model.base = 'any';
model.default = getModelDefault(definition, model);
if (definition.properties) {
model.export = 'interface';
model.type = 'any';
model.base = 'any';
model.default = getModelDefault(definition, model);
const modelProperties = getModelProperties(openApi, definition, getModel, model);
modelProperties.forEach(modelProperty => {
model.imports.push(...modelProperty.imports);
@ -161,8 +165,18 @@ export const getModel = (
model.enums.push(modelProperty);
}
});
return model;
} else {
const additionalProperties = getModel(openApi, {});
model.export = 'dictionary';
model.type = additionalProperties.type;
model.base = additionalProperties.base;
model.template = additionalProperties.template;
model.link = additionalProperties;
model.imports.push(...additionalProperties.imports);
model.default = getModelDefault(definition, model);
return model;
}
return model;
}
// If the schema has a type than it can be a basic or generic type.

View File

@ -3,7 +3,8 @@ const getResponseBody = async (response: Response): Promise<any> => {
try {
const contentType = response.headers.get('Content-Type');
if (contentType) {
const isJSON = contentType.toLowerCase().startsWith('application/json');
const jsonTypes = ['application/json', 'application/problem+json']
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
if (isJSON) {
return await response.json();
} else {

View File

@ -3,7 +3,8 @@ const getResponseBody = async (response: Response): Promise<any> => {
try {
const contentType = response.headers.get('Content-Type');
if (contentType) {
const isJSON = contentType.toLowerCase().startsWith('application/json');
const jsonTypes = ['application/json', 'application/problem+json']
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
if (isJSON) {
return await response.json();
} else {

View File

@ -3,7 +3,8 @@ const getResponseBody = (xhr: XMLHttpRequest): any => {
try {
const contentType = xhr.getResponseHeader('Content-Type');
if (contentType) {
const isJSON = contentType.toLowerCase().startsWith('application/json');
const jsonTypes = ['application/json', 'application/problem+json']
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
if (isJSON) {
return JSON.parse(xhr.responseText);
} else {

View File

@ -32,7 +32,9 @@ import { request as __request } from '../core/request';
{{/if}}
{{#equals @root.httpClient 'angular'}}
@Injectable()
@Injectable({
providedIn: 'root',
})
{{/equals}}
export class {{{name}}}{{{@root.postfix}}} {
{{#if @root.exportClient}}

View File

@ -18,13 +18,13 @@ export type { OpenAPIConfig } from './core/OpenAPI';
{{#each models}}
{{#if @root.useUnionTypes}}
export type { {{{name}}} } from './models/{{{name}}}';
export type { {{{name}}}{{#if @root.postfixModels}} as {{{name}}}{{{@root.postfixModels}}}{{/if}} } from './models/{{{name}}}';
{{else if enum}}
export { {{{name}}} } from './models/{{{name}}}';
export { {{{name}}}{{#if @root.postfixModels}} as {{{name}}}{{{@root.postfixModels}}}{{/if}} } from './models/{{{name}}}';
{{else if enums}}
export { {{{name}}} } from './models/{{{name}}}';
export { {{{name}}}{{#if @root.postfixModels}} as {{{name}}}{{{@root.postfixModels}}}{{/if}} } from './models/{{{name}}}';
{{else}}
export type { {{{name}}} } from './models/{{{name}}}';
export type { {{{name}}}{{#if @root.postfixModels}} as {{{name}}}{{{@root.postfixModels}}}{{/if}} } from './models/{{{name}}}';
{{/if}}
{{/each}}
{{/if}}
@ -41,7 +41,7 @@ export { ${{{name}}} } from './schemas/${{{name}}}';
{{#if services}}
{{#each services}}
export { {{{name}}}{{{@root.postfix}}} } from './services/{{{name}}}{{{@root.postfix}}}';
export { {{{name}}}{{{@root.postfixServices}}} } from './services/{{{name}}}{{{@root.postfixServices}}}';
{{/each}}
{{/if}}
{{/if}}

View File

@ -10,5 +10,7 @@ describe('getPattern', () => {
expect(getPattern('\\')).toEqual('\\\\');
expect(getPattern('\\/')).toEqual('\\\\/');
expect(getPattern('\\/\\/')).toEqual('\\\\/\\\\/');
// eslint-disable-next-line prettier/prettier
expect(getPattern("'")).toEqual("\\'");
});
});

View File

@ -3,8 +3,12 @@
* However, to use it in HTML or inside new RegExp() we need to
* escape the pattern to become: '^\\d{3}-\\d{2}-\\d{4}$' in order
* to make it a valid regexp string.
*
* Also, escape single quote characters, because the output uses single quotes for strings
*
* @param pattern
*/
export const getPattern = (pattern?: string): string | undefined => {
return pattern?.replace(/\\/g, '\\\\');
// eslint-disable-next-line prettier/prettier
return pattern?.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
};

View File

@ -28,7 +28,8 @@ import { writeClientServices } from './writeClientServices';
* @param exportSchemas Generate schemas
* @param exportSchemas Generate schemas
* @param indent Indentation options (4, 2 or tab)
* @param postfix Service name postfix
* @param postfixServices Service name postfix
* @param postfixModels Model name postfix
* @param clientName Custom client class name
* @param request Path to custom request file
*/
@ -44,7 +45,8 @@ export const writeClient = async (
exportModels: boolean,
exportSchemas: boolean,
indent: Indent,
postfix: string,
postfixServices: string,
postfixModels: string,
clientName?: string,
request?: string
): Promise<void> => {
@ -75,7 +77,7 @@ export const writeClient = async (
useUnionTypes,
useOptions,
indent,
postfix,
postfixServices,
clientName
);
}
@ -94,7 +96,7 @@ export const writeClient = async (
if (isDefined(clientName)) {
await mkdir(outputPath);
await writeClientClass(client, templates, outputPath, httpClient, clientName, indent, postfix);
await writeClientClass(client, templates, outputPath, httpClient, clientName, indent, postfixServices);
}
if (exportCore || exportServices || exportSchemas || exportModels) {
@ -108,7 +110,8 @@ export const writeClient = async (
exportServices,
exportModels,
exportSchemas,
postfix,
postfixServices,
postfixModels,
clientName
);
}

View File

@ -34,7 +34,7 @@ describe('writeClientIndex', () => {
},
};
await writeClientIndex(client, templates, '/', true, true, true, true, true, 'Service');
await writeClientIndex(client, templates, '/', true, true, true, true, true, 'Service', '');
expect(writeFile).toBeCalledWith('/index.ts', 'index');
});

View File

@ -19,7 +19,8 @@ import { sortServicesByName } from './sortServicesByName';
* @param exportServices Generate services
* @param exportModels Generate models
* @param exportSchemas Generate schemas
* @param postfix Service name postfix
* @param postfixServices Service name postfix
* @param postfixModels Model name postfix
* @param clientName Custom client class name
*/
export const writeClientIndex = async (
@ -31,7 +32,8 @@ export const writeClientIndex = async (
exportServices: boolean,
exportModels: boolean,
exportSchemas: boolean,
postfix: string,
postfixServices: string,
postfixModels: string,
clientName?: string
): Promise<void> => {
const templateResult = templates.index({
@ -40,7 +42,8 @@ export const writeClientIndex = async (
exportModels,
exportSchemas,
useUnionTypes,
postfix,
postfixServices,
postfixModels,
clientName,
server: client.server,
version: client.version,

View File

@ -463,7 +463,8 @@ const getResponseBody = async (response: Response): Promise<any> => {
try {
const contentType = response.headers.get('Content-Type');
if (contentType) {
const isJSON = contentType.toLowerCase().startsWith('application/json');
const jsonTypes = ['application/json', 'application/problem+json']
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
if (isJSON) {
return await response.json();
} else {
@ -548,55 +549,6 @@ export { CancelablePromise, CancelError } from './core/CancelablePromise';
export { OpenAPI } from './core/OpenAPI';
export type { OpenAPIConfig } from './core/OpenAPI';
export type { _default } from './models/_default';
export type { ArrayWithArray } from './models/ArrayWithArray';
export type { ArrayWithBooleans } from './models/ArrayWithBooleans';
export type { ArrayWithNumbers } from './models/ArrayWithNumbers';
export type { ArrayWithProperties } from './models/ArrayWithProperties';
export type { ArrayWithReferences } from './models/ArrayWithReferences';
export type { ArrayWithStrings } from './models/ArrayWithStrings';
export type { CommentWithBackticks } from './models/CommentWithBackticks';
export type { CommentWithBreaks } from './models/CommentWithBreaks';
export type { CommentWithExpressionPlaceholders } from './models/CommentWithExpressionPlaceholders';
export type { CommentWithQuotes } from './models/CommentWithQuotes';
export type { CommentWithReservedCharacters } from './models/CommentWithReservedCharacters';
export type { CommentWithSlashes } from './models/CommentWithSlashes';
export type { Date } from './models/Date';
export type { DictionaryWithArray } from './models/DictionaryWithArray';
export type { DictionaryWithDictionary } from './models/DictionaryWithDictionary';
export type { DictionaryWithProperties } from './models/DictionaryWithProperties';
export type { DictionaryWithReference } from './models/DictionaryWithReference';
export type { DictionaryWithString } from './models/DictionaryWithString';
export type { EnumFromDescription } from './models/EnumFromDescription';
export { EnumWithExtensions } from './models/EnumWithExtensions';
export { EnumWithNumbers } from './models/EnumWithNumbers';
export { EnumWithStrings } from './models/EnumWithStrings';
export type { ModelThatExtends } from './models/ModelThatExtends';
export type { ModelThatExtendsExtends } from './models/ModelThatExtendsExtends';
export type { ModelWithArray } from './models/ModelWithArray';
export type { ModelWithBoolean } from './models/ModelWithBoolean';
export type { ModelWithCircularReference } from './models/ModelWithCircularReference';
export type { ModelWithDictionary } from './models/ModelWithDictionary';
export type { ModelWithDuplicateImports } from './models/ModelWithDuplicateImports';
export type { ModelWithDuplicateProperties } from './models/ModelWithDuplicateProperties';
export { ModelWithEnum } from './models/ModelWithEnum';
export type { ModelWithEnumFromDescription } from './models/ModelWithEnumFromDescription';
export type { ModelWithInteger } from './models/ModelWithInteger';
export type { ModelWithNestedEnums } from './models/ModelWithNestedEnums';
export type { ModelWithNestedProperties } from './models/ModelWithNestedProperties';
export type { ModelWithNullableString } from './models/ModelWithNullableString';
export type { ModelWithOrderedProperties } from './models/ModelWithOrderedProperties';
export type { ModelWithPattern } from './models/ModelWithPattern';
export type { ModelWithProperties } from './models/ModelWithProperties';
export type { ModelWithReference } from './models/ModelWithReference';
export type { ModelWithString } from './models/ModelWithString';
export type { SimpleBoolean } from './models/SimpleBoolean';
export type { SimpleFile } from './models/SimpleFile';
export type { SimpleInteger } from './models/SimpleInteger';
export type { SimpleReference } from './models/SimpleReference';
export type { SimpleString } from './models/SimpleString';
export type { SimpleStringWithPattern } from './models/SimpleStringWithPattern';
export { $_default } from './schemas/$_default';
export { $ArrayWithArray } from './schemas/$ArrayWithArray';
export { $ArrayWithBooleans } from './schemas/$ArrayWithBooleans';
@ -1312,6 +1264,7 @@ export type ModelWithPattern = {
readonly modified?: string;
id?: string;
text?: string;
patternWithSingleQuotes?: string;
};
"
@ -2117,6 +2070,10 @@ export const $ModelWithPattern = {
type: 'string',
pattern: '^\\\\\\\\w+$',
},
patternWithSingleQuotes: {
type: 'string',
pattern: '^[a-zA-Z0-9\\\\']*$',
},
},
} as const;
"
@ -3550,7 +3507,8 @@ const getResponseBody = async (response: Response): Promise<any> => {
try {
const contentType = response.headers.get('Content-Type');
if (contentType) {
const isJSON = contentType.toLowerCase().startsWith('application/json');
const jsonTypes = ['application/json', 'application/problem+json']
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
if (isJSON) {
return await response.json();
} else {
@ -3635,73 +3593,7 @@ export { CancelablePromise, CancelError } from './core/CancelablePromise';
export { OpenAPI } from './core/OpenAPI';
export type { OpenAPIConfig } from './core/OpenAPI';
export type { _default } from './models/_default';
export type { ArrayWithArray } from './models/ArrayWithArray';
export type { ArrayWithBooleans } from './models/ArrayWithBooleans';
export type { ArrayWithNumbers } from './models/ArrayWithNumbers';
export type { ArrayWithProperties } from './models/ArrayWithProperties';
export type { ArrayWithReferences } from './models/ArrayWithReferences';
export type { ArrayWithStrings } from './models/ArrayWithStrings';
export type { CommentWithBackticks } from './models/CommentWithBackticks';
export type { CommentWithBreaks } from './models/CommentWithBreaks';
export type { CommentWithExpressionPlaceholders } from './models/CommentWithExpressionPlaceholders';
export type { CommentWithQuotes } from './models/CommentWithQuotes';
export type { CommentWithReservedCharacters } from './models/CommentWithReservedCharacters';
export type { CommentWithSlashes } from './models/CommentWithSlashes';
export type { CompositionBaseModel } from './models/CompositionBaseModel';
export type { CompositionExtendedModel } from './models/CompositionExtendedModel';
export type { CompositionWithAllOfAndNullable } from './models/CompositionWithAllOfAndNullable';
export type { CompositionWithAnyOf } from './models/CompositionWithAnyOf';
export type { CompositionWithAnyOfAndNullable } from './models/CompositionWithAnyOfAndNullable';
export type { CompositionWithAnyOfAnonymous } from './models/CompositionWithAnyOfAnonymous';
export type { CompositionWithOneOf } from './models/CompositionWithOneOf';
export type { CompositionWithOneOfAndComplexArrayDictionary } from './models/CompositionWithOneOfAndComplexArrayDictionary';
export type { CompositionWithOneOfAndNullable } from './models/CompositionWithOneOfAndNullable';
export type { CompositionWithOneOfAndSimpleArrayDictionary } from './models/CompositionWithOneOfAndSimpleArrayDictionary';
export type { CompositionWithOneOfAndSimpleDictionary } from './models/CompositionWithOneOfAndSimpleDictionary';
export type { CompositionWithOneOfAnonymous } from './models/CompositionWithOneOfAnonymous';
export type { CompositionWithOneOfDiscriminator } from './models/CompositionWithOneOfDiscriminator';
export type { DeprecatedModel } from './models/DeprecatedModel';
export type { DictionaryWithArray } from './models/DictionaryWithArray';
export type { DictionaryWithDictionary } from './models/DictionaryWithDictionary';
export type { DictionaryWithProperties } from './models/DictionaryWithProperties';
export type { DictionaryWithReference } from './models/DictionaryWithReference';
export type { DictionaryWithString } from './models/DictionaryWithString';
export type { EnumFromDescription } from './models/EnumFromDescription';
export { EnumWithExtensions } from './models/EnumWithExtensions';
export { EnumWithNumbers } from './models/EnumWithNumbers';
export { EnumWithStrings } from './models/EnumWithStrings';
export type { File } from './models/File';
export type { ModelCircle } from './models/ModelCircle';
export type { ModelSquare } from './models/ModelSquare';
export type { ModelThatExtends } from './models/ModelThatExtends';
export type { ModelThatExtendsExtends } from './models/ModelThatExtendsExtends';
export type { ModelWithArray } from './models/ModelWithArray';
export type { ModelWithBoolean } from './models/ModelWithBoolean';
export type { ModelWithCircularReference } from './models/ModelWithCircularReference';
export type { ModelWithDictionary } from './models/ModelWithDictionary';
export type { ModelWithDuplicateImports } from './models/ModelWithDuplicateImports';
export type { ModelWithDuplicateProperties } from './models/ModelWithDuplicateProperties';
export { ModelWithEnum } from './models/ModelWithEnum';
export type { ModelWithEnumFromDescription } from './models/ModelWithEnumFromDescription';
export type { ModelWithInteger } from './models/ModelWithInteger';
export type { ModelWithNestedEnums } from './models/ModelWithNestedEnums';
export type { ModelWithNestedProperties } from './models/ModelWithNestedProperties';
export type { ModelWithNullableString } from './models/ModelWithNullableString';
export type { ModelWithOrderedProperties } from './models/ModelWithOrderedProperties';
export type { ModelWithPattern } from './models/ModelWithPattern';
export type { ModelWithProperties } from './models/ModelWithProperties';
export type { ModelWithReference } from './models/ModelWithReference';
export type { ModelWithString } from './models/ModelWithString';
export type { Pageable } from './models/Pageable';
export type { SimpleBoolean } from './models/SimpleBoolean';
export type { SimpleFile } from './models/SimpleFile';
export type { SimpleInteger } from './models/SimpleInteger';
export type { SimpleReference } from './models/SimpleReference';
export type { SimpleString } from './models/SimpleString';
export type { SimpleStringWithPattern } from './models/SimpleStringWithPattern';
export { $_default } from './schemas/$_default';
export { $ArrayWithArray } from './schemas/$ArrayWithArray';
export { $ArrayWithBooleans } from './schemas/$ArrayWithBooleans';
export { $ArrayWithNumbers } from './schemas/$ArrayWithNumbers';
@ -3738,6 +3630,9 @@ export { $EnumWithExtensions } from './schemas/$EnumWithExtensions';
export { $EnumWithNumbers } from './schemas/$EnumWithNumbers';
export { $EnumWithStrings } from './schemas/$EnumWithStrings';
export { $File } from './schemas/$File';
export { $FreeFormObjectWithAdditionalPropertiesEqEmptyObject } from './schemas/$FreeFormObjectWithAdditionalPropertiesEqEmptyObject';
export { $FreeFormObjectWithAdditionalPropertiesEqTrue } from './schemas/$FreeFormObjectWithAdditionalPropertiesEqTrue';
export { $FreeFormObjectWithoutAdditionalProperties } from './schemas/$FreeFormObjectWithoutAdditionalProperties';
export { $ModelCircle } from './schemas/$ModelCircle';
export { $ModelSquare } from './schemas/$ModelSquare';
export { $ModelThatExtends } from './schemas/$ModelThatExtends';
@ -4376,6 +4271,42 @@ export type File = {
"
`;
exports[`v3 should generate: ./test/generated/v3/models/FreeFormObjectWithAdditionalPropertiesEqEmptyObject.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
/**
* This is a free-form object with additionalProperties: {}.
*/
export type FreeFormObjectWithAdditionalPropertiesEqEmptyObject = Record<string, any>;
"
`;
exports[`v3 should generate: ./test/generated/v3/models/FreeFormObjectWithAdditionalPropertiesEqTrue.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
/**
* This is a free-form object with additionalProperties: true.
*/
export type FreeFormObjectWithAdditionalPropertiesEqTrue = Record<string, any>;
"
`;
exports[`v3 should generate: ./test/generated/v3/models/FreeFormObjectWithoutAdditionalProperties.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
/**
* This is a free-form object without additionalProperties.
*/
export type FreeFormObjectWithoutAdditionalProperties = Record<string, any>;
"
`;
exports[`v3 should generate: ./test/generated/v3/models/ModelCircle.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
@ -4735,6 +4666,7 @@ export type ModelWithPattern = {
readonly modified?: string;
id?: string;
text?: string;
patternWithSingleQuotes?: string;
};
"
@ -5570,6 +5502,48 @@ export const $File = {
"
`;
exports[`v3 should generate: ./test/generated/v3/schemas/$FreeFormObjectWithAdditionalPropertiesEqEmptyObject.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export const $FreeFormObjectWithAdditionalPropertiesEqEmptyObject = {
type: 'dictionary',
contains: {
properties: {
},
},
} as const;
"
`;
exports[`v3 should generate: ./test/generated/v3/schemas/$FreeFormObjectWithAdditionalPropertiesEqTrue.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export const $FreeFormObjectWithAdditionalPropertiesEqTrue = {
type: 'dictionary',
contains: {
properties: {
},
},
} as const;
"
`;
exports[`v3 should generate: ./test/generated/v3/schemas/$FreeFormObjectWithoutAdditionalProperties.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export const $FreeFormObjectWithoutAdditionalProperties = {
type: 'dictionary',
contains: {
properties: {
},
},
} as const;
"
`;
exports[`v3 should generate: ./test/generated/v3/schemas/$ModelCircle.ts 1`] = `
"/* istanbul ignore file */
/* tslint:disable */
@ -5985,6 +5959,10 @@ export const $ModelWithPattern = {
type: 'string',
pattern: '^\\\\\\\\w+$',
},
patternWithSingleQuotes: {
type: 'string',
pattern: '^[a-zA-Z0-9\\\\']*$',
},
},
} as const;
"
@ -7204,14 +7182,14 @@ export class TypesService {
*/
public static types(
parameterArray: Array<string> | null,
parameterDictionary: any,
parameterDictionary: Record<string, any> | null,
parameterEnum: 'Success' | 'Warning' | 'Error' | null,
parameterNumber: number = 123,
parameterString: string | null = 'default',
parameterBoolean: boolean | null = true,
parameterObject: any = null,
parameterObject: Record<string, any> | null = null,
id?: number,
): CancelablePromise<number | string | boolean | any> {
): CancelablePromise<number | string | boolean | Record<string, any>> {
return __request(OpenAPI, {
method: 'GET',
url: '/api/v{api-version}/types',

View File

@ -15,6 +15,7 @@ describe('v2', () => {
exportSchemas: true,
exportModels: true,
exportServices: true,
postfixModels: 'Dto',
});
sync('./test/generated/v2/**/*.ts').forEach(file => {
@ -36,6 +37,7 @@ describe('v3', () => {
exportSchemas: true,
exportModels: true,
exportServices: true,
postfixModels: 'Dto',
});
sync('./test/generated/v3/**/*.ts').forEach(file => {

View File

@ -1507,6 +1507,10 @@
"text": {
"type": "string",
"pattern": "^\\w+$"
},
"patternWithSingleQuotes": {
"type": "string",
"pattern": "^[a-zA-Z0-9']*$"
}
}
}

View File

@ -2466,6 +2466,10 @@
"text": {
"type": "string",
"pattern": "^\\w+$"
},
"patternWithSingleQuotes": {
"type": "string",
"pattern": "^[a-zA-Z0-9']*$"
}
}
},
@ -2535,6 +2539,20 @@
}
}
}
},
"FreeFormObjectWithoutAdditionalProperties": {
"description": "This is a free-form object without additionalProperties.",
"type": "object"
},
"FreeFormObjectWithAdditionalPropertiesEqTrue": {
"description": "This is a free-form object with additionalProperties: true.",
"type": "object",
"additionalProperties": true
},
"FreeFormObjectWithAdditionalPropertiesEqEmptyObject": {
"description": "This is a free-form object with additionalProperties: {}.",
"type": "object",
"additionalProperties": {}
}
}
}

3
types/index.d.ts vendored
View File

@ -24,7 +24,8 @@ export type Options = {
exportModels?: boolean;
exportSchemas?: boolean;
indent?: Indent | '4' | '2' | 'tab';
postfix?: string;
postfixServices?: string;
postfixModels?: string;
request?: string;
write?: boolean;
};