Skip to content

Conversation

erunion
Copy link
Member

@erunion erunion commented May 29, 2020

🧰 What's being changed?

This creates a new package, httpsnippet-client-api, that allows for the creation of Node code samples, via httpsnippet, for the api module.

Using the new plugin architecture I've PR'd to HTTP Snippet, we can load in this new client with the following lines:

const client = require('httpsnippet-client-api');
HTTPSnippet.addTargetClient('node', client);

And once it's loaded, you can use HTTP Snippet as you would any other target+client combination:

const snippet = new HTTPSnippet(harObject);
console.log(
  snippet.convert('node', 'api', { 
    apiDefinitionPath: 'https://example.com/openapi.json'
  })
);

🧪 Testing

Since the unit tests for httpsnippet are pretty ingrained into that repository, I've extracted the target-related tests and all their fixtures to facilitate testing this module. As such since we're pulling in code I didn't write, I am also pulling in their license.

Ideally this code/plugin infrastructure would be available in a generator package like generator-eslint, but that is way out of scope for this right now. Maybe once the plugin PR is accepted into httpsnippet, and we start building additional api clients for different languages, we can work on something there. Until then, yolo.

🗳 Checklist

💡 If answering yes to any of the following, include additional info, before/after links, screenshots, etc. where appropriate!

  • 🆕 I'm adding something new!
  • 🐛 I'm fixing a bug!

@erunion erunion added the enhancement New feature or request label May 29, 2020
@erunion erunion requested review from julshotal and kanadgupta May 29, 2020 07:16
Copy link

@julshotal julshotal left a comment

Choose a reason for hiding this comment

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

Was on call while this was being worked on, tests are very concise and produced the correct output

Base automatically changed from chore/monorepo to master May 29, 2020 18:55
@erunion erunion merged commit cf72740 into master May 29, 2020
@erunion erunion deleted the feat/httpsnippet-target branch May 29, 2020 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants