restish icon indicating copy to clipboard operation
restish copied to clipboard

questions around the spec document

Open kpayson opened this issue 4 years ago • 5 comments

I have a few questions related to the openApi spec document

  1. can the spec_files array contain urls?

  2. There may be a bug related to path resolution in the spec array. I copied the openapi.json file to my ~/.restish folder but I discovered that I can not specify the path relative to ~ ex "spec_files": [ "~/.restish/ls-openapi.json"] leads to an error goroutine 1 [running]: github.com/danielgtaylor/restish/cli.Run() /home/runner/work/restish/restish/cli/cli.go:486 +0x9f2 main.main() /home/runner/work/restish/restish/main.go:27 +0x177 but "spec_files": [ "./ls-openapi.json"] works.

  3. If I want to combine the hosted openapi.json file with a local-api.json file that has some customizations, will that be possible?

kpayson avatar Mar 10 '21 19:03 kpayson

If this section: https://github.com/danielgtaylor/restish/blob/ba45f05bb4e26ae9796be91231de0e0cb05b0415/cli/api.go#L155 was updated to support passing in the URI to a spec, instead of trying to guess, then it would be a lot easier to use. cli/api.go:155

kpayson avatar Mar 10 '21 20:03 kpayson

  1. can the spec_files array contain urls?

Not today. It reads a local file from disk and simulates an HTTP response with its contents.

  1. There may be a bug related to path resolution in the spec array...

The ~ is a shell construct and we don't resolve it in the config files so it is seeing it as a literal ~ instead of meaning your home directory. You can always use an absolute path.

  1. If I want to combine the hosted openapi.json file with a local-api.json file that has some customizations, will that be possible?

Currently that's not possible. Local files will override any hosted OpenAPI file. You can pull the hosted one and add your customizations to it, then tell Restish to load that.

danielgtaylor avatar Apr 02 '21 13:04 danielgtaylor

I am curious if there is defined or expected behavior for the case where multiple spec_files are provided, and the same operationId is specified in more than one. Which one gets called?

tfsJoe avatar Apr 13 '22 21:04 tfsJoe

@tfsJoe the merge logic is here: https://github.com/danielgtaylor/restish/blob/3e64e178a384a996d2f15810bde1421aca17eb16/cli/api.go#L32-L42 then each operation registers a command with the API root command. I would say right now the behavior is undefined, but I'm open to a PR which would do "first wins" or "last wins" or something. What would you expect to happen?

danielgtaylor avatar Apr 13 '22 22:04 danielgtaylor

Personally I don't have a strong preference as long as it's predictable or gives a clear warning. I'll try to get a PR together!

tfsJoe avatar Apr 14 '22 16:04 tfsJoe