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

refactor: move createFromString and resource from Prism Http to CLI #1009

Merged
merged 30 commits into from
May 8, 2020

Conversation

XVincentX
Copy link
Contributor

@XVincentX XVincentX commented Feb 27, 2020

This PR is a proposal of moving the methods createClientFromResource and createClientFromSpec from the prism-http package to prism-cli package

The main rationale behind this is that the dependencies of such feature (json-ref-resolver, json-ref-readers) have an hard dependency on the fs package that makes prism-http a little bit harder to embed in the browser (you need to configure web pack to mock the fs module to empty)


This is technically a breaking change since we're removing a function although we have never "marketed" our client API — I'm summoning @philsturgeon to get his opinion.

If we're going to take this as a breaking change (Prism 4), then I'd take the occasion to also

  1. Change our artefacts directory from dist to lib — it makes more sense and does not make you feel bad when importing stuff // cc @marcelltoth — we had such discussion some time ago
  2. Rename some of the client methods to something that makes a little bit more sense

Closes #1008
Closes stoplightio/elements/issues/261

Copy link
Contributor

@philsturgeon philsturgeon left a comment

Choose a reason for hiding this comment

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

It looks like a change is happening to http-client which is actually something we’ve advertised as useable in the docs. If documented package API is changing then it’ll need to be a major version.

I don’t have many opinions on heather you should bundle other major changes in here. It does make sense to do various necessary breaks in one go, but keep in mind hosted mocking will also need to change and that’s need more QA time, and they’re already fairly busy. If you consider that sort of stuff and make a decision then I support it either way! 🙌🏻

docs/guides/http-client.md Outdated Show resolved Hide resolved
docs/guides/http-client.md Outdated Show resolved Hide resolved
Copy link
Contributor

@karol-maciaszek karol-maciaszek left a comment

Choose a reason for hiding this comment

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

The is a movement in a good direction!

Since we somehow have a green light to break things why not move getHttpOperations(string) to http-spec? The spec type detection (which will be more and more complex over time, see https://github.com/stoplightio/prism/blob/feat/postman-collection/packages/http/src/getHttpOperations.ts#L48) is a good candidate for being shared.

The only problem I see with such an approach is that a folk wanting to put some operations programmatically into prism will need to import http-spec package. But we can do it for him and reexport getHttpOperations in prism. Thoughts?

docs/guides/http-client.md Outdated Show resolved Hide resolved
docs/guides/http-client.md Outdated Show resolved Hide resolved
packages/http-server/src/__tests__/server.oas.spec.ts Outdated Show resolved Hide resolved
packages/http/package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@philsturgeon philsturgeon left a comment

Choose a reason for hiding this comment

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

I don't think I said "green light to break things" haha just, please use cautious and common sense. No leroy jenkins here.

packages/http-server/src/__tests__/server.oas.spec.ts Outdated Show resolved Hide resolved
@XVincentX
Copy link
Contributor Author

Since we're going to ship this as a breaking change I think I will tweak a little bit the function names (the current one might not exactly make that much sense) as well as maybe rearrange the parameters. I'll look into this later today and put something online.

@marcelltoth
Copy link
Contributor

Change our artefacts directory from dist to lib — it makes more sense and does not make you feel bad when importing stuff // cc @marcelltoth — we had such discussion some time ago

Just my two cents here. I think if we are going to need a major bump we should take the time to really define what our public API is. Merely renaming the directory to lib and saying it's OK to import from there is disastrous in my opinion. From that point on changing any export in any file will technically be a major break. I'm sure http\dist\mocker\negotiator\internalHelpers shouldn't be part of a public library distribution. But probably http-server/getHttpConfigFromRequest neither.

Let's take a step back, decide what the goal is for each of the packages (in terms of external use), and what are the key APIs we'd like to offer to the public to achieve them.

Then put these files into somewhere (lib folder, index.ts export / top level files / whatever we decide on), keep the rest where it is, and clearly document what is part of our API and what is not.

@XVincentX
Copy link
Contributor Author

@marcelltoth I understand where you're coming from and I would love to do that, but I do not think we can now. The public JS API will probably be done (if done) once we'll gather from more feedback from hosted Prism, Mocking Tab usage and all these product using the package.

On the other hand, we need to make Prism Http browser-compatible as soon as possible since it's blocking some stuff we're doing — and I took the occasion of the breaking change to do propose some other reorganisation — among these the idea of using lib directory as output instead of dist because it just makes us feel sick. I'm fine deferring this if it's an issue for anybody though.

@marcelltoth
Copy link
Contributor

@XVincentX Then I propose to keep it that way and import from dist as before.

That pushes the "risk" to the consuming packages if they import from dist. Then we sort it out in the next major version, and everyone's happy.

However if we publish a major version where everything is public, how are we going to support that? Do we release a new major every 2 days? Do we break semver? In my eyes either of these are worse than just keeping it in dist and surviving with those ugly imports until we have the time to create an actual long term solution.

@XVincentX
Copy link
Contributor Author

We'll keep the dist directory as it is at the moment — I am fine deferring the discussion when we'll have the time.

That said, we still need this change for our platform and so apparently this change is unenviable unless we publish this as a 4 beta and use it internally, which might be ok with me and with platform.

@XVincentX XVincentX force-pushed the feat/adios-fromSpec branch 2 times, most recently from 9c115c8 to 4894178 Compare March 13, 2020 15:50
@XVincentX XVincentX marked this pull request as ready for review May 7, 2020 17:14
@XVincentX XVincentX force-pushed the feat/adios-fromSpec branch 3 times, most recently from 8cd51a4 to 90d60b2 Compare May 7, 2020 17:43
Copy link
Contributor

@marcelltoth marcelltoth left a comment

Choose a reason for hiding this comment

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

I still have two concerns:

  • Publicly teaching users that it is OK to import stuff from /dist is not great. It'd be OK if we bundled stuff but as we are not, this makes it very difficult to define correct semver versioning.
  • importing a package called cli feels weird. A cli feels like it is intended to be an end-user thing that you run, not something you use in other packages, right?

I understand that this is something you want to work on later separately however, so this one is good to go. It is definitely a great improvement and does what it promises.

@@ -4,7 +4,7 @@ import { Scope as NockScope } from 'nock';
import * as nock from 'nock';
import { basename, resolve } from 'path';
import { createInstance, IHttpProxyConfig, IHttpRequest, IHttpResponse, ProblemJsonError } from '../';
import { getHttpOperationsFromResource } from '../getHttpOperations';
import { getHttpOperationsFromResource } from '@stoplight/prism-cli/src/operations';
Copy link
Contributor

Choose a reason for hiding this comment

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

Is /src/ in the bundle? Should it?

In the example (README.md) you are importing it from /dist/ which looks more appropriate.

This applies to ~10 other places as well.

packages/http/src/client.ts Outdated Show resolved Hide resolved
docs/guides/http-client.md Outdated Show resolved Hide resolved
Copy link
Contributor

@karol-maciaszek karol-maciaszek left a comment

Choose a reason for hiding this comment

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

Looks good 👍

packages/http/src/mocker/index.ts Show resolved Hide resolved
@XVincentX
Copy link
Contributor Author

@marcelltoth

I'll address all the comments here:

Publicly teaching users that it is OK to import stuff from /dist is not great. It'd be OK if we bundled stuff but as we are not, this makes it very difficult to define correct semver versioning.

That is very correct, and it was a mistake, I admit it. We aren't going to release this breaking change soon; most likely we'll be still on 3.x for a while. The idea is to accumulate all the breaking changes (included your very good ideas on defining a public API) and then release. So at the moment, no harms has been done

importing a package called cli feels weird. A cli feels like it is intended to be an end-user thing that you run, not something you use in other packages, right?

It is a bit weird, but I really do not see any good reason to create a prism-utils package. If we can find another part where we can paste this, I'm all for it. Maybe http-spec? I have no clue

Is /src/ in the bundle? Should it?

Eheheh ok this is complicated — essentially is a trick to use TypeScript in VSCode without having to compile the code first. I agree that's not great, but

  • It's in the tests — not shipped code
  • We can fix that by exporting stuff from the main package (which unfortunately though has some side effects, so not viable right now)

@XVincentX XVincentX merged commit 15db66a into master May 8, 2020
@XVincentX XVincentX deleted the feat/adios-fromSpec branch May 8, 2020 16:52
dnascimento added a commit to dnascimento/prism that referenced this pull request May 3, 2021
In stoplightio#1009 the getHttpOperationsFromSpec moved to the prism-cli package. The documentation needs to be updated accordingly
pytlesk4 added a commit that referenced this pull request Aug 23, 2021
…#1820)

* Update Http-server doc with new location of getHttpOperationsFromSpec
In #1009 the getHttpOperationsFromSpec moved to the prism-cli package. The documentation needs to be updated accordingly

* Update packages/http-server/README.md

Co-authored-by: Thomas Pytleski <[email protected]>
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.

Remove createClientFromSpec method from Http Issues with fs library?
4 participants