Fork me on GitHub
#yada
<
2016-01-20
>
malcolmsparks00:01:03

@aspra - hi, it is possible but a little tricky. Swagger specs are just plain yada resources, you can hijack these resources (change them before you create handlers from them) and override the :get method to return a modified (:response ctx) rather than the current implementation

malcolmsparks00:01:25

if you can describe what you're trying to achieve I could help more

malcolmsparks00:01:36

(by providing code snippets)

malcolmsparks00:01:43

alternatively you could add in your own interceptor - again, depends on what you're trying to do as to which approach is the most sensible

aspra09:01:45

thanks @malcolmsparks. I want to use a swagger UI hosted somewhere else and I wanted to add the cors headers to the swaggered response. Now I am thinking of adding a proxy instead.

malcolmsparks10:01:50

yada does do CORS, and if you look at the swaggered phonebook on http://yada.juxt.pro you'll notice the phonebook itself is on a different origin from the swagger console

malcolmsparks10:01:28

@aspra I realise this isn't the same as your set up, but it would be fairly straight-forward to build a swagger spec resource that would publish the swagger spec as a string with CORS headers

malcolmsparks10:01:19

if you delve into the code, you'll see that the swagger resource is simply a yada resource that serves up a swagger spec - you could write your own resource, with the CORS headers, and use the same logic that swaggered uses to generate the swagger spec (as a string).

malcolmsparks10:01:16

The 'swaggered' function is a bit of a convenience and assumes you are serving the swagger spec on the same origin as your API. For the phonebook example, that doesn't work because they're on different origins. Therefore you'll see it's done a little different - yada is quite flexible in this regard

malcolmsparks10:01:55

If you look into the code and examples you should begin to see the various pieces involved and be able to reassemble them in different ways

malcolmsparks10:01:16

(I must confess that the CORS stuff is new and not well documented but will be in the coming weeks)

aspra11:01:27

ok, I will try to get my head around it and skip the proxy idea

aspra11:01:55

at a previous versions :access-control was :cors right? That got me a bit confused

malcolmsparks15:01:38

yes - use the examples/phonebook project as a guide. That actually has a few tests around it so is usually accurate simple_smile

malcolmsparks15:01:09

you can see the examples/phonebook project from the repo, suggest you git clone the yada repo too

malcolmsparks15:01:29

(sorry, I meant to say the examples/phonebook application is in the same repo as yada)