swagger-express-middleware icon indicating copy to clipboard operation
swagger-express-middleware copied to clipboard

Resource not found if swagger basePath is specified.

Open xxvvii opened this issue 7 years ago • 3 comments

Resource not found if swagger basePath is specified when I run the sample2

Added 'basePath' in 'PetStore.yaml' as below:

swagger: "2.0"
info:
  version: 1.0.0
  title: Swagger petstore
  description: A sample API that demonstrates Swagger-Express-Middleware features
basePath: '/api'
consumes:
  - application/json
produces:
  - application/json
http://localhost:8000/api/pets/Lassie

Then got 404 not found error, seems Resource treat whole url as the collection name, any ideas?

xxvvii avatar Mar 20 '18 09:03 xxvvii

To add to this, defining a base path also causes the express app to ignore the data store instance passed to middleware.mock(). It cost me half a day of head-scratching and debugging to realize that this was the sole reason why my mock api always served the example data from the yaml file instead of what I've added to the MemoryDataStore.

Sigma-90 avatar Feb 14 '19 10:02 Sigma-90

I'm also hitting the same issue that when the basePath is defined the datastore instance is ignored. Any sign of a fix or a work around?

chriswinch avatar Jun 11 '19 08:06 chriswinch

So it seems that if you add the basePath when setting the resources it works again.

myDB.save(
    new Resource('/api/v1/pet/fido', {
      name: 'Fido'
    })
)

instead of just /pet/fido

chriswinch avatar Jun 11 '19 08:06 chriswinch