-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Service that exposes resource named "api" #1314
Comments
@nunogoncalves - I was sure we solved the issue with Which version of swagger-ui do you use? Have you tried the latest master with it? |
@webron My swagger-ui.js doesn't seem to have a version on it. |
@nunogoncalves - did you get a chance to check? |
Sorry, not yet. I had a weekly commitment I had to stick to and couldn't No dia quinta-feira, 28 de maio de 2015, Ron [email protected]
Cumprimentos, |
We'll leave it open for a few more days, but would appreciate the feedback to see if there's work do be done here. |
Well, I'll definitely do it, because it's part of one of my tasks. :) Might be as late as early next week. :) Sorry for the delay though. |
Hi! I think I got it! I refreshed the whole JS folder to use the new Swagger-UI and this issue is now working. However, I'm hitting on two new problems: I'm getting a warning about the api which exposes "api" resource
I don't really know what I should do when the warning states use 'client._apis'... should I actually change the swagger-ui.js code? And second, our apis, use JWT authentication, and I'm trying to add the auth token in the request, but I'm facing problems:
window.authorizations.add( 'api_key', new ApiKeyAuthorization('authorization', data.token, 'header')); I get warnings:
swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("Authorization", "XXXX", "header")); Then I get
swaggerUI exists, but api is null... this is for any API, not just the api which exposes a resource called api. :) Sorry for the trouble. :) |
Hey @nunogoncalves, Lets see if we can clear things up...
|
Thanks for your answer @ponelat Indeed I need to add the auth token in every request, including to fetch the spec file. I'm very confused with all this. I'm using swagger-ui which, the way I see it, besides providing the ui, hides the swagger-js details. Looking at swagger-ui readme here it says that If I want to add custom headers I can do like so: swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("Authorization", "XXXX", "header")); But doing It trows the error I showed earlier. swaggerUI.api is null so api isn't built at the time. So I guess that for this to work to also fetch the spec file, I have to create the SwaggerClient object, right? For what I see in the issue your pointed to, I would have to create that SwaggerClient object myself, right? But then I don't know how to make it work with swagger-ui... :/ I have tried something basic if (swaggerUi.api === undefined || swaggerUi.api == null) {
var client = new SwaggerClient({
authorizations: { // will become a SwaggerAuthorization object
api_key: new SwaggerClient.ApiKeyAuthorization("Authorization", "XXXX", "header")
}
});
swaggerUi.api = client
} but it'll brake elsewhere saying
|
@nunogoncalves ok, if you need to add auth for the spec itself you'll have to wait for the issue above. I'll probably have it done soon, within this week most likely. You're right about swagger-ui hiding the details of swagger-js. Or more specifically, it simply uses swagger-js for its purposes. It also exposes the swagger-js instance as The reason you're getting that error, is because we can only rely on |
Hi @ponelat . Maybe I should consider opening a new issue with this, but I'll post it here anyway. If it's better to open a new one, I'll do it. I just updated the swagger-ui (which if I'm not mistaken includes the updated version of swagger-js as well) and my preivous issues are fixed. I now can authenticate my requests, including the spec file request. Now another problem issue arouse. I'm having an error on swagger-ui.js (line 2363) Resolver.prototype.resolveAllOf = function(spec, obj, depth) {
depth = depth || 0;
obj = obj || spec;
var name;
So the resolveAllOf method it's being called indefinitely and throws the error. Since this happened with APIs that were already closed, I started triming down code to see where the problem was coming from. If I remove this required, then it works. Before posting the examples, can you tell me if the behaviour is intended? Because if it's not, I must then fill an issue with the owner of swagger-docs, which I'm building my rails swagger docs with. I tried in there to remove this property with no effect. I'll paste here two examples. One working and one broken. Working example: {
"apiVersion": "0",
"swaggerVersion": "1.2",
"basePath": "http://localhost:3000/",
"resourcePath": "dogs",
"apis": [
{
"path": "v0/dogs/{id}/notes.json",
"operations": [
{
"summary": "Update dog notes",
"notes": "Update dog notes",
"parameters": [
{
"paramType": "body",
"name": "dog",
"type": "notes",
"description": null,
"required": false
}
],
"method": "put",
"nickname": "V0::Dogs#update_dog_notes"
}
]
}
],
"models": {
"dog": {
"id": "dog",
"required": "foo",
"properties": {
"id": {
"type": "integer",
"description": "Dog notes"
}
}
}
}
} {
"apiVersion": "0",
"swaggerVersion": "1.2",
"basePath": "http://localhost:3000/",
"resourcePath": "dogs",
"apis": [
{
"path": "v0/dogs/{id}/notes.json",
"operations": [
{
"summary": "Update dog notes",
"notes": "Update dog notes",
"parameters": [
{
"paramType": "body",
"name": "dog",
"type": "notes",
"description": null,
"required": false
}
],
"method": "put",
"nickname": "V0::Dogs#update_dog_notes"
}
]
}
],
"models": {
"dog": {
"id": "dog",
"required": null,
"properties": {
"id": {
"type": "integer",
"description": "Dog notes"
}
}
}
}
} |
@nunogoncalves - Since you say the original issue is resolved, I'll close this one. In general, yeah, it's better to open a different issue. However, I can tell you that |
@nunogoncalves thanks for the above specs, they'll definitely help! Copy/paste will be fine for the new issue. |
Hello,
I'm having a hard time trying to figure this out. We have a service which serves a resource name called "api".
Here's the json:
When calling the /apis I get the following json: (simplified)
And when swagger-ui builds the html, the
is empty:
If I change the name of the resource, say to apis, then I get proper endpoints built.
I was trying to dig into the code, but I find it very hard, so I decided to come here asking for help.
I guess it has something to do with these lines in swagger.js file. When I have the resource name api, it never gets "ready" and always exits the method in the resource.ready == null condition.
Thank you in advance.
The text was updated successfully, but these errors were encountered: