用Swagger隐藏服务(Hiding services with Swagger)
有什么方法可以在进入生产时从swagger UI中隐藏某些服务但是在localhost上运行时会显示?
EX:
/// <summary> /// GET: .../api/SomeController/{id: int} /// </summary> /// <param name="id">int</param> /// <returns></returns> public IHttpActionResult SomeService(int id) { return Ok();}
当我在我的环境中运行并且去swagger UI localhost:12345 / swagger / ui / index我会看到服务文档等,但是当我在http:// someDomain / swagger / ui / index时我不会看见。
我一直在查看文档,但没有找到任何与此相关的内容。
谢谢。
is there any way that some services can be hidden from swagger UI when going into production but when run on localhost be displayed?
EX:
/// <summary> /// GET: .../api/SomeController/{id: int} /// </summary> /// <param name="id">int</param> /// <returns></returns> public IHttpActionResult SomeService(int id) { return Ok();}
When i'm running on my environment and go to swagger UI localhost:12345/swagger/ui/index i will see that service documentation etc, but when i'm on http://someDomain/swagger/ui/index i will not see it.
I've been looking in the documentation but didn't find anything related to this.
Thank you.
原文:https://stackoverflow.com/questions/41037162
最满意答案
与其他答案基本相同。 你需要连接数据块并注册一个结束事件并在那里进行解析。 这是我试过的一个,似乎按预期工作。
var http = require('http'); var artist = 'Beatles' http.request({host: 'api.songkick.com', path: '/api/3.0/search/artists.json?query=' + artist + '&apikey=Z2JWQTvgk4tsCdDn'}, function(res) { var response_data = ''; var id; res.on("data", function(chunk) { response_data += chunk; }); res.on('end', function(){ id = JSON.parse(response_data).resultsPage.results.artist[0].id; console.log(id); http.request({host: 'api.songkick.com', path: '/api/3.0/artists/' + id + '/gigography.json?apikey=Z2JWQTvgk4tsCdDn'}, function(res) { var inner_data = ''; res.on("data", function(chunk) { inner_data += chunk; }); res.on("end", function(){ console.log(JSON.parse(inner_data).resultsPage.results); }); }).end(); }); }).end();
basically the same as the other answer. you need to concat the chunks of data and register for an end event and do the parsing there. Here's one I tried and it seems to work as expected.
var http = require('http'); var artist = 'Beatles' http.request({host: 'api.songkick.com', path: '/api/3.0/search/artists.json?query=' + artist + '&apikey=Z2JWQTvgk4tsCdDn'}, function(res) { var response_data = ''; var id; res.on("data", function(chunk) { response_data += chunk; }); res.on('end', function(){ id = JSON.parse(response_data).resultsPage.results.artist[0].id; console.log(id); http.request({host: 'api.songkick.com', path: '/api/3.0/artists/' + id + '/gigography.json?apikey=Z2JWQTvgk4tsCdDn'}, function(res) { var inner_data = ''; res.on("data", function(chunk) { inner_data += chunk; }); res.on("end", function(){ console.log(JSON.parse(inner_data).resultsPage.results); }); }).end(); }); }).end();
相关问答
更多-
JSON.parse意外令牌(JSON.parse unexpected token s)[2022-11-28]
你要求它解析JSON文本(不是"something" )。 这是无效的JSON,字符串必须用双引号。 如果你想要一个相当于你的第一个例子: var s = '"something"'; var result = JSON.parse(s); You're asking it to parse the JSON text something (not "something"). That's invalid JSON, strings must be in double quotes. If you wan ... -
学习调试代码: 上面的XML无效 - > http://www.xmlvalidation.com 通过使用var_dump($load_api);确保$load_api包含您的想法var_dump($load_api); 确保PHP的错误报告处于最佳水平,搜索SO以了解如何执行此操作。 您的XML有多个
节点,因此必须以不同方式设置$artists 。 你echo $shows ,这是回声 - 什么都没有,因为它有孩子,但没有价值。 $xml = simplexml_load_string( ... -
没有单引号,您正在创建一个数组,其中包含两个对象。 这是JavaScript自己的语法。 当您添加引号时,该对象(数组+ 2个对象)现在是一个字符串。 您可以使用JSON.parse将字符串转换为JavaScript对象。 您不能使用JSON.parse将JavaScript对象转换为JavaScript对象。 //String - you can use JSON.parse on it var jsonStringNoQuotes = '[{"Id":"10","Name":"Matt"},{"Id": ...
-
Songkick在Web浏览器中加载一个java applet,该applet具有对文件系统的只读访问权限。 它指的是iTunes库文件,例如在Mac上的/Users/username/Music/iTunes/iTunes Library.xml中读取所有曲目及其元数据。 由于iTunes不能用作Web服务,因此它不具备API。 Songkick loads a java applet in web browser that has read-only access to file system. It ...
-
为什么这个JSON.parse返回错误:“意外令牌非法”?(Why does this JSON.parse return error: “unexpected token illegal”?)[2022-12-26]
JSON.parse()语法非常严格。 键/值对应具有以下形式: string:value 所以“first”和“second”应该是JSON对象中的字符串。 将您的JSON更改为以下代码,它应该是正确的 { "first": 1, "second": 2 } JSON.parse() is very strict in grammar. The key/value pairs should have the form: string:value So the "first" and ... -
场地搜索的文档提到了per_page参数,该参数限制了每个请求返回的项目数。 您可以尝试使用: http://api.songkick.com/api/3.0/search/venues.json?query={venue term}&per_page=10&apikey={API KEY} 它接受1到50之间的任何值。 The documentation for venue search mentions the per_page argument, that limits how many items ...
-
JSON.parse()使用Songkick API失败并带有意外令牌(JSON.parse() fails with unexpected token using Songkick API)[2023-11-15]
与其他答案基本相同。 你需要连接数据块并注册一个结束事件并在那里进行解析。 这是我试过的一个,似乎按预期工作。 var http = require('http'); var artist = 'Beatles' http.request({host: 'api.songkick.com', path: '/api/3.0/search/artists.json?query=' + artist + '&apikey=Z2JWQTvgk4tsCdDn'}, function(res) { var r ... -
通话回来的json看起来很好。 将解析更改为: @images = JSON.parse(@jsonresults) The json returned by the call looks fine. Change your parsing to this: @images = JSON.parse(@jsonresults)
-
JSON.parse - 带有构造的JSON字符串的“意外令牌”(JSON.parse — “unexpected token” with constructed JSON string)[2023-06-04]
你有错误的JSON ,你应该把键包装成双引号,就像这样 var text = "notation: 'fixed', precision: 2"; text = text.replace(/\'/g, '"').replace(/(\w+):/g, '"$1":'); console.log( JSON.parse("{" + text + "}") ); You have wrong JSON, you should wrap keys to double quotes, like this var ... -
JSON.parse()在AngularJS TransformResponse中失败(JSON.parse() fails in AngularJS TransformResponse)[2021-12-31]
你可以在解析之前显示数据的console.log吗? Angular的JSON格式有时与原生javascript的json格式不同,您可能希望尝试使用angular.fromJson而不是JSON.parse。 Turns out I was getting a php array from the response. Fixed by setting headers: { 'Accept': 'application/json' } Thanks to DavidLin for helping me ...