-
Notifications
You must be signed in to change notification settings - Fork 13
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
Most types on $ are typed as never
#787
Comments
That's intentional but let's talk about it... Assuming the OpenAPI document is correct, if it doesn't specify any parameters, there's no reason to call Does that make sense? What would you expect to see there instead of |
I have run into this as well, but it was always because the OpenApi doc was incorrect. At first I wanted a way to stop Counterfact from fussing about the |
Well, I'm going to take that back. I have paths in the OpenApi spec that define a |
I thought about adding a type parameter to set a "loose" mode.
But if we make "loose" mode loose enough to compensate for incomplete OpenAPI, you might as well replace |
Maybe instead we should add a comment to the file with a link to a page that explains the relationship between that file and OpenAPI? |
BTW, did you know? If your OpenAPI file is local, while Counterfact is running, a change to the OpenAPI file will immediately be reflected in the type definition. |
Thanks! The documentation is fixed. |
This is one of the single best features of CF. |
Done. Check out this PR: #796 |
Wow, sorry this discussion somehow totally went past me. So I guess my use case isn't the intended one. I'm working against an api I do not have ownership over, and need to work/test against data that might not be present or available to me. This is why I like to use this mock server. So I can easily create the scenarios and edge cases to test out my frontend. I'm assuming then that in OpenApi definitions even specific header parameters are defined, which is not the case for the openapi i'm working against. However it does define I was hoping to take a look at the user making the request and returning different mocked data based on that. So I could have a test user that has more of a happy path, another I could use when I want things to go wrong etc. I could also see that case of perhaps wanting to add a custom header for dev, testing purposes, f.e. to specifically target Counterfact. X-TEST-USER=happypath. This wouldn't apply to prod and would be left out of OpenApi def. I can't say I have a silver bullet of an solution. We have options like One thing could be having a |
Thanks. Okay, you've convinced me that A couple other workarounds to consider:
Counterfact can technically be used without OpenAPI at all. You can create all of the files manually in the paths directory -- either ts or js files. (Currently the CLI requires an OpenAPI file. I need to fix that, but in the meantime a dummy OpenAPI file will work.) |
I'm embarrassed to say Counterfact doesn't support that yet. I'll make it a priority. |
That makes sense, and TypeScript errors notwithstanding you should be able to do that now. However, as you get to know Counterfact, I think you'll find there are easier ways to test different scenarios. First, you can change the code and see the results without restarting. (To toggle between error and no error you might comment / uncomment a return statement that has the error response.) Second, instead of looking at the user you can look at the context object. if (context.error.duplicateProductName) {
return $.response[400].json({ error: `A product named ${body.name} already exists.`});
} The you can use the REPL to set the value of Much faster and more flexible than logging out and logging in with a different user! |
Okay, I think I have an elegant solution in #801 I added a new |
Yeah, I think this is a decent solution. We can still enjoy the type safety but opt into edge cases where we don´t fully control the OpenAPI def. |
The |
This means typescript will cry if we try to access something here.
Is this intended, it doesn't fit with the documentations ( which also names
$.header
as$.headers
)The text was updated successfully, but these errors were encountered: