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

Add swagger ui to render api docs #1418

Merged
merged 10 commits into from
Aug 5, 2019
Merged

Add swagger ui to render api docs #1418

merged 10 commits into from
Aug 5, 2019

Conversation

bashofmann
Copy link
Contributor

@bashofmann bashofmann commented Jul 25, 2019

What this PR does / why we need it:
Add swagger ui to render api docs.

This depends on kubermatic/kubermatic#3890.

What we are not sure yet: Where would be the best place to add the link to it, Footer or SideNav?

Fixes: #1411

Release note:

Add Swagger UI

@kubermatic-bot kubermatic-bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jul 25, 2019
@kubermatic-bot
Copy link
Contributor

Hi @bashofmann. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@kubermatic-bot kubermatic-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 25, 2019
package.json Show resolved Hide resolved
src/polyfills.ts Outdated Show resolved Hide resolved
@floreks
Copy link
Contributor

floreks commented Jul 29, 2019

The placement IMHO is fine. The other option would be to move it to the left and make it powered by Loodse - API - version. I'd also maybe shorten it from API Docs to just API.

I'd also hide the sidebar when viewing the API. We can make kubermatic logo a link to main projects view.

@cschieder @maciaszczykm @kgroschoff WDYT?

Zrzut ekranu z 2019-07-29 09-37-41

Zrzut ekranu z 2019-07-29 09-37-54

@kgroschoff
Copy link
Contributor

Absolutely agree with @floreks.
Additionally I think it would be great if you could configure if you want to display the link or not. (like Demo System or Terms of Service)

@maciaszczykm
Copy link
Contributor

+1 to API instead of API Docs.

@bashofmann
Copy link
Contributor Author

I addressed the comments above, renamed the link to "API", moved it to the left of the footer, disabled the sidenav and made the link configurable.

@maciaszczykm
Copy link
Contributor

/test all

@bashofmann
Copy link
Contributor Author

When I add the routerlink to the logo in the NavigationComponent, I get the following error running the tests, no idea how to fix this one though:

HeadlessChrome 76.0.3809 (Mac OS X 10.14.6) NavigationComponent should tell Router to navigate when user logout FAILED
	TypeError: Cannot read property 'root' of undefined
	error properties: Object({ ngDebugContext: DebugContext_({ view: Object({ def: Object({ factory: Function, nodeFlags: 51101697, rootNodeFlags: 1, nodeMatchedQueries: 6, flags: 0, nodes: [ Object({ nodeIndex: 0, parent: null, renderParent: null, bindingIndex: 0, outputIndex: 0, checkIndex: 0, flags: 1, childFlags: 51101697, directChildFlags: 33554433, childMatchedQueries: 6, matchedQueries: Object({  }), matchedQueryIds: 0, references: Object({  }), ngContentIndex: null, childCount: 9, bindings: [  ], bindingFlags: 0, outputs: [  ], element: Object({ ns: '', name: 'header', attrs: [  ], template: null, componentProvider: null, componentView: null, componentRendererType: null, publicProviders: null({  }), allProviders: null({  }), handleEvent: Function }), provider: null, text: null, query: null, ngContent: null }), Object({ nodeIndex: 1, parent: Object({ nodeIndex: 0, parent: null, renderParent: null, bindingIndex: 0, outputIndex: 0, checkIndex: 0, flags: 1, childFlags: 51101697, directChildFlags: 33 ...
	    at <Jasmine>
	    at rootRoute (http://localhost:9877/node_modules/@angular/router/fesm5/router.js:5628:1)
	    at _callFactory (http://localhost:9877/node_modules/@angular/core/fesm5/core.js:20959:1)
	    at _createProviderInstance (http://localhost:9877/node_modules/@angular/core/fesm5/core.js:20915:1)
	    at resolveNgModuleDep (http://localhost:9877/node_modules/@angular/core/fesm5/core.js:20876:1)
	    at NgModuleRef_.get (http://localhost:9877/node_modules/@angular/core/fesm5/core.js:21584:1)
	    at resolveDep (http://localhost:9877/node_modules/@angular/core/fesm5/core.js:21955:1)
	    at createClass (http://localhost:9877/node_modules/@angular/core/fesm5/core.js:21831:1)
	    at createDirectiveInstance (http://localhost:9877/node_modules/@angular/core/fesm5/core.js:21706:1)
	    at createViewNodes (http://localhost:9877/node_modules/@angular/core/fesm5/core.js:29881:1)
	    at callViewAction (http://localhost:9877/node_modules/@angular/core/fesm5/core.js:30197:1)
	TypeError: Cannot read property 'debugElement' of undefined
	    at <Jasmine>
	    at UserContext.<anonymous> (http://localhost:9877/src/app/core/components/navigation/navigation.component.spec.ts:61:30)
	    at TestBedViewEngine.execute (http://localhost:9877/node_modules/@angular/core/fesm5/testing.js:2430:1)
	    at UserContext.<anonymous> (http://localhost:9877/node_modules/@angular/core/fesm5/testing.js:2598:29)
	    at ZoneDelegate../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9877/node_modules/zone.js/dist/zone.js:391:1)
	    at ProxyZoneSpec.onInvoke (http://localhost:9877/node_modules/zone.js/dist/proxy.js:129:1)
	    at ZoneDelegate../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9877/node_modules/zone.js/dist/zone.js:390:1)
	    at Zone../node_modules/zone.js/dist/zone.js.Zone.run (http://localhost:9877/node_modules/zone.js/dist/zone.js:150:1)
	    at runInTestZone (http://localhost:9877/node_modules/zone.js/dist/jasmine-patch.js:177:1)
	    at UserContext.<anonymous> (http://localhost:9877/node_modules/zone.js/dist/jasmine-patch.js:192:1)
	    at <Jasmine>

@bashofmann
Copy link
Contributor Author

When I add the routerlink to the logo in the NavigationComponent, I get the following error running the tests, no idea how to fix this one though

I think I found it :).

@floreks
Copy link
Contributor

floreks commented Jul 30, 2019

Can you regenerate package-lock.json? Almost 7k lines feels way too much for only 2 new dependencies.

*ngIf="showApiDocs()">
<div class="km-separator">–</div>
<a routerLink="api"
matTooltip="API">
Copy link
Contributor

@floreks floreks Jul 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't tooltip with the same message redundant?

@cschieder @maciaszczykm should we elaborate tooltip message here or remove it completely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be fine with both.

@kubermatic-bot kubermatic-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 30, 2019
@bashofmann
Copy link
Contributor Author

Can you regenerate package-lock.json? Almost 7k lines feels way too much for only 2 new dependencies.

I took the package-lock.json from master, ran npm install swagger-ui buffer. The diff is still huge. Any idea what I'm doing wrong?

❯ node -v
v12.6.0

❯ npm -v
6.10.2

@floreks
Copy link
Contributor

floreks commented Jul 30, 2019

To regenerate:

  • Remove node_modules
  • Remove package-lock.json
  • Run npm i

This provides the best result. ~500 lines are reasonable as it also adds the whole dependency tree of added dep.

@kubermatic-bot kubermatic-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 30, 2019
@bashofmann
Copy link
Contributor Author

bashofmann commented Jul 30, 2019

That seems to have made the diff even larger for me :/

@floreks
Copy link
Contributor

floreks commented Jul 30, 2019

😂

Looks like it have just swapped order of dependencies. It does that sometimes, but if you have followed my steps then it's fine. It's better to regenerate it from scratch after adding dependency. Are there any audit issues reported (npm audit)?

@bashofmann
Copy link
Contributor Author

npm audit

                       === npm audit security report ===

# Run  npm install --save-dev cypress@3.4.1  to resolve 1 vulnerability
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ lodash                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ cypress [dev]                                                │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ cypress > lodash                                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1065                            │
└───────────────┴──────────────────────────────────────────────────────────────┘


┌──────────────────────────────────────────────────────────────────────────────┐
│                                Manual Review                                 │
│            Some vulnerabilities require your attention to resolve            │
│                                                                              │
│         Visit https://go.npm.me/audit-guide for additional guidance          │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ underscore.string                                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=3.3.5                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ swagger-ui                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ swagger-ui > remarkable > argparse > underscore.string       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/745                             │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 2 vulnerabilities (1 moderate, 1 high) in 20601 scanned packages
  run `npm audit fix` to fix 1 of them.
  1 vulnerability requires manual review. See the full report for details.

@bashofmann
Copy link
Contributor Author

Should I update cypress in this PR?

@bashofmann
Copy link
Contributor Author

bashofmann commented Jul 30, 2019

The other audit issue has been fixed in remarkable, but not released yet: jonschlinkert/remarkable#357.

Fortunately it does not seem to be a problem in swagger: swagger-api/swagger-ui#5152.

@bashofmann
Copy link
Contributor Author

Why does adding routerLink="projects" to the NavigationComponent introduce an API call that needs mocking?

Or do you mean that the route must not start with /api. The problem there is that if you directly go to the URL (or refresh the page) the Ingress Controller directly directs the request to kubermatic-api and not to the dasbhoard (/~https://github.com/kubermatic/kubermatic/blob/master/config/kubermatic/templates/ingress.yaml#L19)

@floreks
Copy link
Contributor

floreks commented Jul 30, 2019

Ok, so the solution is quite simple. I've had to look into the code. Simply remove {provide: Router, useClass: RouterStub}, from the spec (and your changes). It should work.

@floreks
Copy link
Contributor

floreks commented Jul 31, 2019

/test all

@codecov
Copy link

codecov bot commented Jul 31, 2019

Codecov Report

Merging #1418 into master will decrease coverage by 0.21%.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1418      +/-   ##
==========================================
- Coverage    73.4%   73.19%   -0.22%     
==========================================
  Files         205      206       +1     
  Lines        6288     6316      +28     
  Branches      582      591       +9     
==========================================
+ Hits         4616     4623       +7     
- Misses       1428     1452      +24     
+ Partials      244      241       -3
Impacted Files Coverage Δ
src/app/kubermatic.component.ts 54.16% <0%> (ø) ⬆️
src/polyfills.ts 100% <100%> (ø) ⬆️
src/app/core/components/footer/footer.component.ts 95.23% <100%> (+0.5%) ⬆️
src/app/core/services/api/api.service.ts 36.92% <33.33%> (+1.49%) ⬆️
src/app/wizard/summary/summary.component.ts 57.89% <0%> (-25.83%) ⬇️
...c/app/shared/components/labels/labels.component.ts 41.17% <0%> (-23.53%) ⬇️
.../app/wizard/set-settings/set-settings.component.ts 71.42% <0%> (-14.29%) ⬇️
...ngs/custom-credentials/custom-presets.component.ts 81.08% <0%> (-2.71%) ⬇️
...r/cluster-details/node-list/node-list.component.ts 77.89% <0%> (-0.6%) ⬇️
src/app/sshkey/sshkey.component.ts 88.23% <0%> (-0.18%) ⬇️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 09f51a4...4ffb218. Read the comment docs.

@floreks
Copy link
Contributor

floreks commented Jul 31, 2019

Please rebase as the base of your branch does not contain some of the e2e fixes.

@maciaszczykm
Copy link
Contributor

/test all

@bashofmann bashofmann force-pushed the feature/swagger-ui branch from a98143a to 72abd78 Compare July 31, 2019 09:20
@bashofmann
Copy link
Contributor Author

Rebase done

@cschieder
Copy link
Contributor

Can we fix the lag on the sidebar animation when you go to the API docs somehow? Also on the API page please add the usual shading to the card

@bashofmann
Copy link
Contributor Author

I added the box-shadow, but I'm not sure how I could improve the sidebar animation, the problem is likely that the rendering of the swagger UI that happens at the same time as the animation introduces this lag.

@floreks
Copy link
Contributor

floreks commented Aug 5, 2019

/retest

@floreks
Copy link
Contributor

floreks commented Aug 5, 2019

/lgtm
/approve

@kubermatic-bot kubermatic-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 5, 2019
@kubermatic-bot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 826cb5e0208f596c936f815ac8c2f146f9f154c4

@kubermatic-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: floreks

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

@kubermatic-bot kubermatic-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 5, 2019
@floreks
Copy link
Contributor

floreks commented Aug 5, 2019

/test pull-dashboard-e2e-test

@kubermatic-bot kubermatic-bot merged commit 4adaa20 into master Aug 5, 2019
@kubermatic-bot kubermatic-bot deleted the feature/swagger-ui branch August 5, 2019 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a API page rendering our swagger
6 participants