Skip to content
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

feat(*): support serving the API documentation page when the server starts #302

Closed
wants to merge 3 commits into from

Conversation

iawia002
Copy link

@iawia002 iawia002 commented Apr 8, 2020

What this PR does / why we need it:

We can now choose to serve the API docs page with the API server itself, take api-basic example project as an example, with this simple config we can let nirvana generates the API docs file and serves the API docs page when the server starts:

cfg.Configure(
	nirvana.Descriptor(v1.Descriptor(), v2.Descriptor()),
	nirvana.APIDocs("github.com/caicloud/nirvana/examples/api-basic", "/docs"),
)

Start the server, API docs related pages will serve under /docs path:

INFO  0408-16:45:44.066+08 config.go:309 | Listening on :8080
INFO  0408-16:45:44.608+08 builder.go:231 | Definitions: 1 Middlewares: 0 Path: /api/v1/applications
INFO  0408-16:45:44.608+08 builder.go:246 |   Method: Create Consumes: [application/json] Produces: [application/json]
INFO  0408-16:45:44.608+08 builder.go:231 | Definitions: 1 Middlewares: 0 Path: /api/v2/applications
INFO  0408-16:45:44.608+08 builder.go:246 |   Method: Create Consumes: [application/json] Produces: [application/json]
INFO  0408-16:45:44.608+08 builder.go:231 | Definitions: 1 Middlewares: 0 Path: /docs/api.v1.json
INFO  0408-16:45:44.608+08 builder.go:246 |   Method: Get Consumes: [] Produces: [application/json]
INFO  0408-16:45:44.608+08 builder.go:231 | Definitions: 1 Middlewares: 0 Path: /docs/api.v2.json
INFO  0408-16:45:44.608+08 builder.go:246 |   Method: Get Consumes: [] Produces: [application/json]
INFO  0408-16:45:44.608+08 builder.go:231 | Definitions: 1 Middlewares: 0 Path: /docs
INFO  0408-16:45:44.608+08 builder.go:246 |   Method: Get Consumes: [] Produces: [text/html]

Screen Shot 2020-04-08 at 16 34 31

And API docs files will be created in the ...examples/api-basic directory.

BTW, ReDoc has been replaced with the Swagger UI.

Which issue(s) this PR is related to (optional, link to 3rd issue(s)):

close #290

Special notes for your reviewer:

/cc @supereagle @kdada

Release note:

support serving the API documentation page when the server starts

@caicloud-bot caicloud-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. caicloud-cla: yes Indicates the PR's author has not signed the Caicloud CLA. labels Apr 8, 2020
@caicloud-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: ddysher

Assign the PR to them by writing /assign @ddysher in a comment when ready.

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@caicloud-bot caicloud-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 8, 2020
@caicloud-bot caicloud-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 8, 2020
@ddysher
Copy link
Member

ddysher commented Apr 9, 2020

IIUC, we don't require a uniform project structure now?

/assign @hezhizhen
/cc @tskdsb since you brought up API generation problem before.

@iawia002
Copy link
Author

iawia002 commented Apr 9, 2020

IIUC, we don't require a uniform project structure now?

We do have a recommended structure, for new projects, they should all use this recommended structure, but for old projects, we haven't forced them to migrate to this recommended structure.

@supereagle
Copy link
Member

It is a good idea that serves the API docs page when the server starts. But I find that it takes a long time to generate API docs for some projects such as Cyclone, which will make the server starts very slowly.

@iawia002
Copy link
Author

But I find that it takes a long time to generate API docs for some projects such as Cyclone, which will make the server starts very slowly.

Yes, of course, that's the price if you want to serve the API documentation page when the server starts. Nirvana needs to do a lot of analysis before starting the server.

@ddysher
Copy link
Member

ddysher commented Apr 14, 2020 via email

@iawia002
Copy link
Author

make it optional and disable by default?

It is disabled by default.

@iawia002
Copy link
Author

Due it may take a long time to generate API docs when the server starts in some big projects, which is unacceptable. So I'm gonna close this PR.

/close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
caicloud-cla: yes Indicates the PR's author has not signed the Caicloud CLA. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API docs generation should not rely on a specified project structure
5 participants