mohsen1 / multi-file-swagger-example

Multi-file Swagger example
http://azimi.me/2015/07/16/split-swagger-into-smaller-files.html
168 stars 39 forks source link

I want to break each PATH OPERATION into its own file #20

Open ericweidl opened 5 years ago

ericweidl commented 5 years ago

The situation: my API has a public and a private version. The public version can basically only GET, the private version supports GET and POST.

My directory structure is:

/paths
    /foo
        get.yaml
        post.yaml

I want to be able to create index files which only include the appropriate paths for the particular API.

For example, for the public version of my API, my root index would be something like:

swagger: '2.0'
info:
  description: The public API...
...
paths:
  $ref: ./paths/index-public.yaml
...

And the index for the private version of my API would be something like:

swagger: '2.0'
info:
  description: The private API...
...
paths:
  $ref: ./paths/index-private.yaml
...

The corresponding files would then contain:

/paths/index-public.yaml:

/foo:
  $ref: ./foo/get.yaml

/paths/index-private.yaml:

/foo:
  $ref: ./foo/get.yaml
  $ref: ./foo/post.yaml

I get a "duplicate key" error when I use multi-file-swagger to bundle the private API.

Can you give me any tips on how I can achieve my goal?

mohsen1 commented 5 years ago

Have you thought about having two index entry points for public and private? It might be a bit more verbose that will work for sure:

#private index.yml
paths:
  /foo:
    $ref: ./foo/get.yaml
    $ref: ./foo/post.yaml
  /bar:
   # ...
#public index.yml
paths:
  /foo:
    $ref: ./foo/get.yaml
  /bar:
   # ...
ericweidl commented 5 years ago

When I try that approach, I get a "duplicate key" error:

C:\...\npm\node_modules\multi-file-swagger\node_modules\js-yaml\lib\js-yaml\loader.js:171
  throw generateError(state, message);
  ^
YAMLException: duplicated mapping key at line 61, column 5:
        $ref: ./foo/post.yaml
        ^