mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
fix import spec (#6097)
This commit is contained in:
parent
bd0aaf3717
commit
ba1f6e4190
@ -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',
|
||||
|
@ -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();
|
||||
}, []);
|
||||
|
Loading…
Reference in New Issue
Block a user