Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Swagger.prototype = {
spec: this.spec,
http: this.http,
securities: {authorized: this.authorizations},
contextUrl: typeof this.url === 'string' ? this.url : undefined,
...argHash
})
},
Expand Down
32 changes: 32 additions & 0 deletions test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,38 @@ describe('http', () => {
})
})

it('use the host from whence the spec was fetched when constructing swagger2 URLs from a basePath', async () => {
const client = await Swagger('http://localhost:8000/relative-host.swagger.yaml')
try {
const res = await client.apis.default.myOp()
expect(res.status).toBe(404)
}
catch (e) {
expect(e).toInclude({
status: 404,
response: {
url: 'http://localhost:8000/v1/endpoint'
}
})
}
})

it('use the host from whence the spec was fetched when constructing OAS3 URLs from relative servers entries', async () => {
const client = await Swagger('http://localhost:8000/relative-server.openapi.yaml')
try {
const res = await client.apis.default.myOp()
expect(res.status).toBe(404)
}
catch (e) {
expect(e).toInclude({
status: 404,
response: {
url: 'http://localhost:8000/v1/endpoint'
}
})
}
})

it('should err gracefully when requesting https from an http server', () => {
return Swagger({
url: 'http://localhost:8000/petstore.json',
Expand Down
10 changes: 10 additions & 0 deletions test/data/relative-host.swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
swagger: "2.0"
basePath: "/v1/"
paths:
/endpoint:
get:
summary: an operation!
operationId: myOp
parameters:
- name: filter
in: query
13 changes: 13 additions & 0 deletions test/data/relative-server.openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
openapi: "3.0.0"
servers:
- url: "/v1/"
paths:
/endpoint:
get:
summary: an operation!
operationId: myOp
parameters:
- name: filter
in: query
schema:
type: string