restish
restish copied to clipboard
questions around the spec document
I have a few questions related to the openApi spec document
-
can the spec_files array contain urls?
-
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 errorgoroutine 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 +0x177but"spec_files": [ "./ls-openapi.json"]works. -
If I want to combine the hosted openapi.json file with a local-api.json file that has some customizations, will that be possible?
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
- can the spec_files array contain urls?
Not today. It reads a local file from disk and simulates an HTTP response with its contents.
- 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.
- 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.
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 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?
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!