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

Feature/rest api several doc links #3306

Merged
merged 7 commits into from
Jan 10, 2018

Conversation

matleppa
Copy link
Member

@matleppa matleppa commented Jan 5, 2018

Closes #3220

Changes

  • POST /apis and PUT /apis
    • external documentation links stored into array instead of one field
    • checking of update operation outcome is added
    • rollback in case tried to update both API object and documentation and update fails partially
  • DELETE /apis/id/documents
    • without query parameters the apiDoc document for API in question is removed
    • with query parameter (DELETE /apis/id/documents?url=) the identified documentation link is removed
      • links are removed one at a time
      • matching link is removed, checking is started from openAPI document link, then external documentation links

Developer checklist

This checklist is to be completed by the PR developer:

  • Alternative solutions were compared/discussed before writing code
    • trade-offs with this solution are considered acceptable
  • Code in this PR adheres to the project styleguide
  • This pull request does not decrease project test coverage
  • If the code changes existing database collection(s), migration has been written
  • If UI texts are added or changed, all texts are internationalized

Reviewer checklist

Reviewed by: @username1

This list is to be completed by the pull request reviewer:

  • Code works as described/expected
  • Code seems to be error free
    • no browser console errors visible
    • no server console errors visible
    • passes CI build
  • Code is written in a way that promotes maintainability
    • easy to understand
    • well organized
    • follows project coding standards and conventions
    • well documented

- added simpleSchema
- changed documentation fields to validate with regex
- changed apiDocs updates to update external documentation array
- added checking of operation integrity and rollback if needed
@ghost ghost assigned matleppa Jan 5, 2018
@ghost ghost added the in progress label Jan 5, 2018
remoteFileUrl: bodyParams.documentationUrl,
},
$push: { otherUrl: bodyParams.externalDocumentation } },
{ upsert: true },
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not wrong place to make "upstream" of ApiDoc because there is POST method for API and for every case it will be "insert" operation

Return "insert" operation in the POST method

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed.

Oh well, what an amount of unnecessary work by me.

At first place being blind for obvious solution

  • (insert and otherUrl: [externalDocumentation],)

and trying to use $push instead, which lead to following error:
"When the validation object contains mongo operators, you must set the modifier option to true", which lead to complicated work-around

  • (update, $push and upsert)

Blimey!

if (!isValid) {
// Check link validity
const regexUrl = regex.test(documentationUrl);
if (!regexUrl) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use regex.test(variable) directly in the if condition

if (!regex.text(documentationUrl)) { ... }

Because for every URL variable has owned checking function and I don't see any reason to store every result of testing in the separated variable. On another hand, the variable regexUrl is used only once

Remove all variables regexUrl and use regex.text() directly

// Check link to Documentation URL
if (documentationUrl) {
// Check link validity
const regexUrl = regex.test(documentationUrl);
Copy link
Contributor

Choose a reason for hiding this comment

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

What will regex.text(undefined) return? Does it really need to check if documentationUrl exists?

Copy link
Member Author

Choose a reason for hiding this comment

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

Check for variable existence is needed, because regex.text(undefined) returns error.

});
},
$push: { otherUrl: bodyParams.externalDocumentation } },
{ upsert: true },
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment with couple words above about "upsert" option

// Prepare data to response, extend it with Documentation URLs
const responseData = Object.assign(
// Get updated value of API
Apis.findOne(apiId),
Copy link
Contributor

Choose a reason for hiding this comment

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

Variable api already contains the API data and it doesn't need to be fetched again

Use "api" variable instead of Apis.findOne(apiId)

const removeResult = ApiDocs.update(
{ apiId },
{ $set: {
type: 'url',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to update type in this case? For example, If the documentation is uploaded as file and a user removes the external URL via DELETE method then it doesn't expect to change type

Remove that

- use regex test in decisions
- replaced complicated ApiDocs.update with simple ApiDocs.insert in POST
/apis endpoint
- additions anf fixes in comments
- removed unnecessary setting of field type when removing external
documentation link
- removed unnecessary duplicate Api read when returning API object data
@marla-singer marla-singer merged commit 8b677ec into develop Jan 10, 2018
@ghost ghost removed the Ready for review label Jan 10, 2018
@marla-singer marla-singer deleted the feature/rest-api-several-doc-links branch January 10, 2018 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants