Skip to content
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

Build from YAML OpenAPI Spec Not Working #494

Open
Rcuz8 opened this issue May 10, 2024 · 4 comments
Open

Build from YAML OpenAPI Spec Not Working #494

Rcuz8 opened this issue May 10, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@Rcuz8
Copy link

Rcuz8 commented May 10, 2024

Describe the bug
I'm just trying to run a mock server that builds from a YAML OpenAPI spec. The setup steps in the OpenAPI guide seem to work perfectly for JSON.. but not for YAML.

Here's my config: (Bear mind, my usage of these entities may not be correct)

mocks/documents/api.yaml: (Basic api spec, validated on http://www.yamllint.com/)

openapi: 3.0.0
info:
  title: API
  version: '1.0'
  description: ...
servers:
  - url: /
paths:
  /users:
    get:
      tags:
    ...

mocks/openapi/definitions.yaml: (Basic definitions file)

- basePath: "/testing-api"
  collection:
    id: "testing-api"
    from: "base"
  document:
    $ref: ../documents/api.yaml

mocks/collections.json: (Basic collections file)

[]

mocks.config.js: (Default mocks-server config file)

module.exports = {
  config: {},
  plugins: {
    proxyRoutesHandler: {
    },
    adminApi: {
      https: {
      }
    },
    inquirerCli: {
    },
    openapi: {
      collection: {
      }
    }
  },
  mock: {
    routes: {
    },
    collections: {
    }
  },
  server: {
    cors: {
    },
    jsonBodyParser: {
    },
    urlEncodedBodyParser: {
    },
    https: {
    }
  },
  files: {
    babelRegister: {
    }
  },
  variantHandlers: {
  }
}

When I run npx mocks-server, I see this error:

‧ Error: [plugins:openapi:documents:0] Error resolving openapi $ref: Unexpected token 'o', "openapi: ../documents/api.yaml
     Error: Unexpected token 'o', "openapi: ../documents/api.yaml

Now, I have one other OpenAPI spec file, mocks/documents/alt.json. When I switch to using that one instead of mocks/documents/api.yaml, it works without issue.

My guess is it's an issue with the YAML support in the mocks-server library (Which is why I'm bringing it here).

To Reproduce
Follow the steps in the Installation and OpenAPI integration guides

Expected behavior
I expect the server to start without error and serve the endpoints defined in api.yaml.

Logs
If applicable, add logs to help explain your problem.

** Operating system, Node.js an npm versions, or browser version (please complete the following information):**

  • OS: MacOS Sonoma 14.4.1
  • Node.js: v20.11.0
  • npm: 10.2.4

Additional context
Add any other context about the problem here.

@javierbrea
Copy link
Member

Hi @Rcuz8 ,
I suppose it may be related to the usage of $ref in yaml files. Just to confirm, does it work if you replace the ref directly by the yaml content of the other file?

@javierbrea javierbrea added the stage: needs more info Further information is needed label May 10, 2024
@Rcuz8
Copy link
Author

Rcuz8 commented May 10, 2024

@javierbrea Yes, it does! When the yaml content is injected directly, it works.

@Rcuz8
Copy link
Author

Rcuz8 commented May 14, 2024

Is there any more info you would need? @javierbrea

@javierbrea
Copy link
Member

No, thank you @Rcuz8 , I think that it is enough to confirm where is the problem.

@javierbrea javierbrea added bug Something isn't working and removed stage: needs more info Further information is needed labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants