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 endpoint for getting list of components with their versions (#324) #335

Merged

Conversation

i-b-dimitrov
Copy link
Contributor

  1. Changed the registry to anticipate 'Accept: application/vnd.oc.info+json'
    HTTP header and if detects it to skip the component rendering and to return
    the component's info only.

  2. Added a new method in the Client - getComponentsInfo(...)
    It prepares the request to the registry with proper accept headers, checks
    for errors and provides a processed result pair (error[], info[]).

  • in case info data is provided for all the requested components then the error
    will be null and the info will have the following structure:
    [{
    componentName: '',
    requestedVersion: '<requested version|undefined>'
    apiResponse: { //// comes from the registry
    href: '',
    name: '',
    renderMode: '<rendered|unrendered>',
    requestVersion: ,
    type: '',
    version: ''
    }
    },
    {
    componentName: '',
    requestedVersion: '<requested version|undefined>'
    apiResponse: {...}
    },
    ...
    ]

  • in case of errors then the info part will skip the apiResponse and will
    include an error field:
    {
    componentName: '',
    requestedVersion: '<requested version|undefined>'
    error: ...
    }

In addition to this the 'error' will be an array holding the
errors corresponding to each component requested. If there's no
error for a particular component then the corresponding element in the 'error'
array will be null:
[
null, //// means the first component is OK
{ message: ..., stackTrace: ... },
null, //// third components is OK as well
...
]

…components#324)

1. Changed the registry to anticipate 'Accept: application/vnd.oc.info+json'
HTTP header and if detects it to skip the component rendering and to return
the component's info only.

2. Added a new method in the Client - getComponentsInfo(...)
It prepares the request to the registry with proper accept headers, checks
for errors and provides a processed result pair (error[], info[]).
- in case info data is provided for all the requested components then the error
will be null and the info will have the following structure:
[{
   componentName: '<name>',
   requestedVersion: '<requested version|undefined>'
   apiResponse: {  //// comes from the registry
      href: '<component url>',
      name: '<name>',
      renderMode: '<rendered|unrendered>',
      requestVersion: <requested version>,
      type: '<type>',
      version: '<actual version>'
   }
},
{
   componentName: '<name>',
   requestedVersion: '<requested version|undefined>'
   apiResponse: {...}
},
...
]

- in case of errors then the info part will skip the apiResponse and will
include an error field:
{
   componentName: '<name>',
   requestedVersion: '<requested version|undefined>'
   error: ...
}

In addition to this the 'error' will be an array holding the
errors corresponding to each component requested. If there's no
error for a particular component then the corresponding element in the 'error'
array will be null:
[
   null,  //// means the first component is OK
   { message: ..., stackTrace: ... },
   null,  //// third components is OK as well
   ...
]
Copy link
Member

@matteofigus matteofigus left a comment

Choose a reason for hiding this comment

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

Hi @ivan-dimitrov-skyscanner

First, my apologies for the delay. I am on holiday now for Xmas but tried to do a quick review anyways 👍

Then, I added a couple of little comments. Overall it looks great, it's just some little improvements/questions.

Thanks for your help!

@@ -1,6 +1,7 @@
'use strict';

var GetComponentHelper = require('./helpers/get-component');
var Settings = require('../../resources/settings');
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this line is not actually needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

if (skipRendering) {
callback({
status: 200,
response: response
Copy link
Member

Choose a reason for hiding this comment

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

This includes renderMode which is not actually very relevant here. Would you mind omitting that property in case skipRendering===true?

Copy link
Member

Choose a reason for hiding this comment

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

Also, the problem of doing this here (instead of around line 78) is that here we go through validation and data closure execution, which I believe is not needed for the info purposes. I think we don't want to just skip rendering, but skip execution at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree with you -- will move it around line 78 to skip most of the stuff done further in the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


it('should return a response with error code and description for the first component', function(){
expect(response[0].response.code).to.be.equal('GENERIC_ERROR');
expect(response[0].response.error).to.be.equal('Component execution error: thisDoesnotExist is not defined');
Copy link
Member

Choose a reason for hiding this comment

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

As previous comment says, I actually am not sure we want this here. I think info should just skip execution at all and give us just the versions. What do you think?


// it('should rerurn the actual version for the second component', function() {
// expect(response[1].response.version).to.be.equal('1.0.0');
// });
Copy link
Member

Choose a reason for hiding this comment

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

Can we get rid of those comments? I think now it is correctly resolving the versions which is what I would expect from info endpoints so those tests are not necessary anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ops, sorry about them. They weren't meant to be there.
Fixed!

- The actual info return was moved at the beginning of get-components.js so it
  will skip most of the validation and rendering logic when takes place
- Fixed the tests so that they are not expecting href and renderMode anymore
@matteofigus matteofigus merged commit 74792a8 into opencomponents:master Jan 3, 2017
@matteofigus
Copy link
Member

Amazing, thanks!

@i-b-dimitrov i-b-dimitrov deleted the 324-Get-Components-Info branch January 12, 2017 10:06
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