Skip to content

Commit

Permalink
fix: solve error with absolute paths
Browse files Browse the repository at this point in the history
Now user introduced local paths are saved as absolute paths

Closes #30
  • Loading branch information
javier-sierra-sngular authored and jorgecasar committed Jan 12, 2024
1 parent aefbf3d commit 80b83ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/services/start-mock-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ async function startMockServer(schemas) {
* @returns {Promise<Schema[]>}
*/
async function validateSchemas(schemas) {
const allSchemasExists = schemas.reduce(
(acc, schema) => (fs.existsSync(`${process.cwd()}/${schema.path}`) ? acc : false),
true
);
const allSchemasExists = schemas.every((schema) => fs.existsSync(schema.path));

if (!allSchemasExists) {
Logger.warn(messages.SOME_SCHEMA_DOES_NOT_EXIST);
const config = await init();
Expand Down
8 changes: 5 additions & 3 deletions src/services/user-flow-steps.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { checkbox, confirm, input } from '@inquirer/prompts';
import * as fs from 'node:fs';
import path from 'node:path';
import { OpenApiSchemaNotFoundError } from '../errors/openapi-schema-not-found-error.js';
import cloneGitRepository from '../services/clone-git-repository.js';
import { findOasFromDir, findOasFromDirRecursive } from '../services/find-oas-from-dir.js';
Expand Down Expand Up @@ -50,17 +51,18 @@ async function getSchemas(origin) {
}

/**
* get initial values from user
* Get the schemas origin from the user
* @async
* @function getOrigin
* @returns {Promise<string>} The origin of the schemas (local or remote)
* @returns {Promise<string>} The origin of the schemas (local absolute path or remote origin)
*/
async function getOrigin() {
const schemasOrigin = await input({
message: 'Enter a remote origin (https:// or git@) or local path',
validate: originValidator,
});
return schemasOrigin;

return verifyRemoteOrigin(schemasOrigin) ? schemasOrigin : path.resolve(schemasOrigin);
}

/**
Expand Down

0 comments on commit 80b83ce

Please # to comment.