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: add http adapter #265

Closed
wants to merge 4 commits into from
Closed

feat: add http adapter #265

wants to merge 4 commits into from

Conversation

Souvikns
Copy link
Member

@Souvikns Souvikns commented Mar 7, 2022

Description

Learning the codebase by creating an HTTP adapter.

Aims to -

  • connect HTTP server as per the specification
  • Handle incoming messages only on the channels specified in the specification
  • Send appropriate responses from the registered function.

See also #25

@coveralls
Copy link

coveralls commented Mar 7, 2022

Pull Request Test Coverage Report for Build 2087142664

Warning: This coverage report may be inaccurate.

We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
To ensure accuracy in future PRs, please see these guidelines.
A quick fix for this PR: rebase it; your next report should be accurate.

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 79.57%

Totals Coverage Status
Change from base Build 1929261406: 0.0%
Covered Lines: 232
Relevant Lines: 276

💛 - Coveralls

@sonarcloud
Copy link

sonarcloud bot commented Apr 4, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Comment on lines +61 to +71
if (query) {
const {isValid, humanReadableError, errors} = validateData(searchParams, query);
if(!isValid){
const err = new GleeError({humanReadableError, errors});
console.log('ERROR', err);
this.emit('error', err);
res.end('HTTP/1.1 400 Bad Request\r\n\r\n');
return;
}
}
}
Copy link
Member Author

@Souvikns Souvikns Apr 4, 2022

Choose a reason for hiding this comment

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

I am trying to validate the query parameters but getting an issue. All the query parameters are being treated as a string so if my query defined in asyncapi.yaml as a string then whatever the query is validation results in positive.

bindings:
      http:
        bindingVersion: 0.1.0
        type: request
        method: GET
        query:
          type: object
          properties:
            name:
              type: string

for this ?name=shreak, ?name and ?name=12 get validated positively which is something that shouldn't happen.

@fmvilas can you give me some tip on this.

Copy link
Member

Choose a reason for hiding this comment

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

🤔 I think you have to try to find the type on purpose. It's true that query parameters are always treated as strings so you'll only get positives in this case. You can probably do this: try Number(query.name) and if you don't get NaN it means it's a number so you can safely do query.name = Number(query.name). Same with null. If you get that query.name is undefined or null then you can safely assign it to null.

That said, you don't check for query.name but for each key in the object. Don't forget about array values. Hope that helps :)

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.

3 participants