mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
Merge pull request #1165 from kshramt/free-form-object
Support free-form objects
This commit is contained in:
commit
4379538a96
@ -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.
|
||||
|
||||
@ -3650,6 +3650,9 @@ export { EnumWithExtensions } from './models/EnumWithExtensions';
|
||||
export { EnumWithNumbers } from './models/EnumWithNumbers';
|
||||
export { EnumWithStrings } from './models/EnumWithStrings';
|
||||
export type { File } from './models/File';
|
||||
export type { FreeFormObjectWithAdditionalPropertiesEqEmptyObject } from './models/FreeFormObjectWithAdditionalPropertiesEqEmptyObject';
|
||||
export type { FreeFormObjectWithAdditionalPropertiesEqTrue } from './models/FreeFormObjectWithAdditionalPropertiesEqTrue';
|
||||
export type { FreeFormObjectWithoutAdditionalProperties } from './models/FreeFormObjectWithoutAdditionalProperties';
|
||||
export type { ModelCircle } from './models/ModelCircle';
|
||||
export type { ModelSquare } from './models/ModelSquare';
|
||||
export type { ModelThatExtends } from './models/ModelThatExtends';
|
||||
@ -3715,6 +3718,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';
|
||||
@ -4341,6 +4347,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 */
|
||||
@ -5522,6 +5564,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 */
|
||||
@ -7160,14 +7244,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',
|
||||
|
||||
@ -2531,6 +2531,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": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user