Skip to content

Parse models without type: object as objects if they contain properties? #1705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/openApi/v2/parser/getModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const getModel = (
}
}

if (definition.type === 'object' && typeof definition.additionalProperties === 'object') {
if (typeof definition.additionalProperties === 'object') {
if (definition.additionalProperties.$ref) {
const additionalProperties = getType(definition.additionalProperties.$ref);
model.export = 'dictionary';
Expand Down Expand Up @@ -119,7 +119,7 @@ export const getModel = (
return model;
}

if (definition.type === 'object') {
if (definition.type === 'object' || typeof definition.properties === 'object') {
model.export = 'interface';
model.type = 'any';
model.base = 'any';
Expand Down
57 changes: 26 additions & 31 deletions src/openApi/v3/parser/getModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ export const getModel = (
}
}

if (
definition.type === 'object' &&
(typeof definition.additionalProperties === 'object' || definition.additionalProperties === true)
) {
if (typeof definition.additionalProperties === 'object' || definition.additionalProperties === true) {
const ap = typeof definition.additionalProperties === 'object' ? definition.additionalProperties : {};
if (ap.$ref) {
const additionalProperties = getType(ap.$ref);
Expand Down Expand Up @@ -149,34 +146,32 @@ export const getModel = (
return model;
}

if (definition.type === 'object') {
if (definition.properties) {
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);
model.enums.push(...modelProperty.enums);
model.properties.push(modelProperty);
if (modelProperty.export === 'enum') {
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;
}
const modelProperties = getModelProperties(openApi, definition, getModel, model);
modelProperties.forEach(modelProperty => {
model.imports.push(...modelProperty.imports);
model.enums.push(...modelProperty.enums);
model.properties.push(modelProperty);
if (modelProperty.export === 'enum') {
model.enums.push(modelProperty);
}
});
return model;
} else if (definition.type === 'object') {
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;
}

// If the schema has a type than it can be a basic or generic type.
Expand Down