English 中文(简体)
将Swagger规格JSON改为超文本文件
原标题:Converting Swagger specification JSON to HTML documentation
最佳回答
问题回答

Everything was too difficult or badly documented so I solved this with a simple script swagger-yaml-to-html.py, which works like this

python swagger-yaml-to-html.py < /path/to/api.yaml > doc.html

这对马来那是这样,但为了与马森公司合作而加以修改也是微不足道的。

I spent a lot of time and tried a lot of different solutions - in the end I did it this way :

<html>
    <head>    
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui.css">
        <script src="//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js"></script>
        <script>

            function render() {
                var ui = SwaggerUIBundle({
                    url:  `path/to/my/swagger.yaml`,
                    dom_id:  #swagger-ui ,
                    presets: [
                        SwaggerUIBundle.presets.apis,
                        SwaggerUIBundle.SwaggerUIStandalonePreset
                    ]
                });
            }

        </script>
    </head>

    <body onload="render()">
        <div id="swagger-ui"></div>
    </body>
</html>

You just need to have path/to/my/swagger.yaml served from the same location.
(or use CORS headers)

查阅

  1. Similar looking as Swagger-Editor s right panel
  2. Search / Filter
  3. Schema Folding
  4. Live Feedback
  5. Output as a single html file

I was looking at Swagger Editor and thought it could export the preview pane but turned out it cannot. So I wrote my own version of it.

全面披露: 我是该工具的作者。

See the swagger-api/swagger-codegen project on GitHub ; the project README shows how to use it to generate static HTML. See Generating static html api documentation.

如果你想看到这种夸张。 json You can install the Swagger UI. 你刚刚在网络服务器上部署这个系统(在你打上Gite Hub的邮袋后,左侧夹),并在你的浏览器中看到Swagger UI。 它是 Java本。

EDIT: 2024-04-22
You can now use docker compose like this with openapi.json next to your compose file and containing the spec:

version:  3 
services:
  swagger-ui:
    image: swaggerapi/swagger-ui
    container_name: swagger-ui
    ports:
      - "8080:8080"
    environment:
      SWAGGER_JSON: /openapi/openapi.json
    volumes:
      - ./openapi.json:/openapi/openapi.json

<>斯特凡>

You can also download swagger ui from: https://github.com/swagger-api/swagger-ui, take the dist folder, modify index.html: change the constructor

const ui = SwaggerUIBundle({
    url: ...,

页: 1

const ui = SwaggerUIBundle({
    spec: YOUR_JSON,

如今,左侧有你们所需要的一切,可以按需要加以分配。

Swagger AP 3.0, 网上Swagger编辑制作Html2客户代码,对我很有价值!

Redocly s CLI界面有一个工具从开放式消费物价指数光谱文档中建立超文本。

sudo npm i -g @redocly/cli
redocly build-docs my-swagger.yml -o docs.html

查阅这一链接:

  1. Download phar file https://github.com/zircote/swagger-php/blob/master/swagger.phar
  2. Install Composer https://getcomposer.org/download/
  3. Make composer.json
  4. Clone swagger-php/library
  5. Clone swagger-ui/library
  6. Make Resource and Model php classes for the API
  7. Execute the PHP file to generate the json
  8. Give path of json in api-doc.json
  9. Give path of api-doc.json in index.php inside swagger-ui dist folder

如果需要另一帮助,请表示可以自由要求。

如果你在Gitelab提出“JSON”案,将提交你。

There s a small Java program which generates docs (adoc or md) from a yaml file.

Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
        .withMarkupLanguage(MarkupLanguage.ASCIIDOC)
        .withSwaggerMarkupLanguage(MarkupLanguage.ASCIIDOC)
        .withOutputLanguage(Language.DE)
        .build();

Swagger2MarkupConverter builder = Swagger2MarkupConverter.from(yamlFileAsString).withConfig(config).build();
return builder.toFileWithoutExtension(outFile);

遗憾的是,它只支持OpenAPI 2.0,但不支持

I m 非常满意:https://rapidocweb.com/

为什么我这样说:

  • Easy to use
  • Try option
  • Possible to add code sample.
  • Integration in other html page
  • Possible to add css and change layout




相关问题
Should I use YAML or JSON to store my Perl data? [closed]

I ve been using the YAML format with reasonable success in the last 6 months or so. However, the pure Perl implementation of the YAML parser is fairly fidgety to hand-write a readable file for and ...

How do you put HTML or XML into a YAML?

I would like to store HTML snippets inside a YAML file. What is the best way to do that? Something like: myhtml: | <div> <a href="#">whatever</a> </div>

What is the difference between YAML and JSON?

What are the differences between YAML and JSON, specifically considering the following things? Performance (encode/decode time) Memory consumption Expression clarity Library availability, ease of use ...

热门标签