fix import spec (#6097)

This commit is contained in:
Jack Kavanagh 2023-07-05 16:13:36 +02:00 committed by GitHub
parent bd0aaf3717
commit ba1f6e4190
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -30,9 +30,6 @@ interface ConvertResult {
};
}
export const isApiSpecImport = ({ id }: Pick<InsomniaImporter, 'id'>) =>
id === 'openapi3' || id === 'swagger2';
export const isInsomniaV4Import = ({ id }: Pick<InsomniaImporter, 'id'>) =>
id === 'insomnia-4';
@ -229,11 +226,29 @@ export const importResourcesToWorkspace = async ({ workspaceId }: { workspaceId:
workspace: existingWorkspace,
};
};
export const isApiSpecImport = ({ id }: Pick<InsomniaImporter, 'id'>) =>
id === 'openapi3' || id === 'swagger2';
const importResourcesToNewWorkspace = async (projectId: string, workspaceToImport?: Workspace) => {
invariant(ResourceCache, 'No resources to import');
const resources = ResourceCache.resources;
const ResourceIdMap = new Map();
// in order to support import from api spec yaml
if (ResourceCache?.type?.id && isApiSpecImport(ResourceCache.type)) {
const newWorkspace = await models.workspace.create({
name: workspaceToImport?.name,
scope: 'design',
parentId: projectId,
});
models.apiSpec.updateOrCreateForParentId(newWorkspace._id, {
contents: ResourceCache.content,
contentType: 'yaml',
fileName: workspaceToImport?.name,
});
return {
resources,
workspace: newWorkspace,
};
}
const newWorkspace = await models.workspace.create({
name: workspaceToImport?.name || 'Imported Workspace',
scope: workspaceToImport?.scope || 'collection',

View File

@ -420,7 +420,6 @@ export const ImportModal: FC<ImportModalProps> = ({
const modalRef = useRef<ModalHandle>(null);
const scanResourcesFetcher = useFetcher<ScanForResourcesActionResult>();
const importFetcher = useFetcher<ImportResourcesActionResult>();
console.log('fetcher', importFetcher.state);
useEffect(() => {
modalRef.current?.show();
}, []);