mock mode does not work #342

holleB opened this Issue Jan 14, 2016 · 3 comments


None yet

4 participants

holleB commented Jan 14, 2016

I've tried the mock-mode follwoing the docs. I try to access the web app like so

curl -i
HTTP/1.1 404 Not Found
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 20
Date: Thu, 14 Jan 2016 13:07:37 GMT
Connection: keep-alive

Cannot GET /weather

I expected { "message": "Sample text" }

The swagger debug output looks like

weather-project/ swagger project start -m
  swagger project.api: {"swaggerFile":"redacted/weather-project/api/swagger/swagger.yaml","name":"weather-project","main":"app.js","host":"localhost","basePath":"/","localUrl":"http://localhost/","port":80} +0ms
Starting: redacted/weather-project/app.js...
  project started here: http://localhost/
  project will restart on changes.
  to restart at any time, enter `rs`
  swagger-tools:middleware Initializing middleware +0ms
  swagger-tools:middleware   Identified Swagger version: 2.0 +4ms
  swagger-tools:middleware   Validation: succeeded +42ms
  swagger-tools:middleware:router Initializing swagger-router middleware +14ms
  swagger-tools:middleware:router   Mock mode: enabled +1ms
  swagger-tools:middleware:router   Controllers: +0ms
  swagger-tools:middleware:validator Initializing swagger-validator middleware +1ms
  swagger-tools:middleware:validator   Response validation: enabled +0ms
  swagger-tools:middleware:security Initializing swagger-security middleware +4ms
  swagger-tools:middleware:security   Security handlers: 0 +0ms
  swagger-tools:middleware:metadata Initializing swagger-metadata middleware +75ms
  swagger-tools:middleware:metadata   Identified Swagger version: 2.0 +0ms
  swagger-tools:middleware:metadata   Found Path: /weather +3ms
  swagger-tools:middleware:metadata GET /weather +5s
  swagger-tools:middleware:metadata   Is a Swagger path: true +0ms
  swagger-tools:middleware:metadata   Is a Swagger operation: true +0ms
  swagger-tools:middleware:metadata   Processing Parameters +1ms

Is it currently broken or am I missing a setup step?

Ok, so I'm missing x-swagger-router-controller: weather. For me, that's a documentation bug.

josephearl commented Sep 6, 2016 edited

Why does mock mode require x-swagger-router-controller? This seems unintuitive - I haven't created any controller yet so why does it need a name?

IMO ideally mock mode would not mock routes with both x-swagger-router-controller and operationId - these are ones I've already coded, but should just mock the routes without these attributes.

This would allow me to incrementally design my API, with real code, without having to restart Swagger Node all the time based on whether I'm implementing an API or designing a new one.

xxd3vin commented Oct 21, 2016

I think it is a document bug.

x-swagger-router-controller: weather is not include in the sample yaml config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment