如何从私有API的Swagger UI获取原始Swagger文件生成Java客户端?
Absolutely! You can totally pull the raw Swagger/OpenAPI specification from a live Swagger UI instance—here are straightforward, reliable ways to do it:
Check the Swagger UI interface directly
Most Swagger UIs have a built-in download option—look for a button labeled Download (usually in the top-right corner) that lets you save the spec as a JSON or YAML file. If there’s no download button, check the input field next to the Explore button; the URL in that field is the direct link to the raw spec file. Just copy that URL into your browser, and you’ll get the raw JSON/YAML content you can save locally.Use your browser’s Developer Tools
Open your browser’s DevTools (press F12 or Ctrl+Shift+I), go to the Network tab, then refresh the Swagger UI page. Look for network requests ending withswagger.json,swagger.yaml,v2/api-docs, oropenapi.json—these are the raw spec files. Click on the request, go to the Response tab, and copy all the content. Paste it into a text editor and save it as a.jsonor.yamlfile (match the format from the response).Inspect the Swagger UI page source
Right-click the Swagger UI page and select View Page Source. Search forSwaggerUIBundleorswaggerUiin the HTML/JS code—you’ll usually find aurlparameter pointing to the raw spec file (e.g.,url: "/api/v3/openapi.json"). Use that path to construct the full URL (add your API’s base domain if needed) and access it directly to get the raw spec.
Once you have the raw spec file, just import it into Swagger Editor, then use the built-in client generator (or tools like OpenAPI Generator) to generate your Java client code easily.
内容的提问来源于stack exchange,提问作者Tibberzz

