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

Swagger: use dynamic schema in reusable requests #24

Open
HamedFirouzi opened this issue May 18, 2020 · 0 comments
Open

Swagger: use dynamic schema in reusable requests #24

HamedFirouzi opened this issue May 18, 2020 · 0 comments

Comments

@HamedFirouzi
Copy link

I tried to write reusable requests (post, put etc.) inside swagger.js file (just like default definitions) and use them inside yml file.

The problem is the schema related to each route is different and since the the request is defined in swagger config and used in yml many times, I cannot find a way to dynamically use related schema inside the body of each request. this is my request in yml:

/admin/order: 
 post: 
  tags: 
  - "Order"
  summary: "my summary"
  $ref: "#/reusables/post"

And this is the way I defined POST method in swagger.js file:

      definitions: {
        ...
      },
      reusables: {
        post: {
          parameters: [
            body: {
            description: "order body",
            in: 'body',
            name: 'body',
            required: true,
            schema: {  
              $ref: `#/definitions/${dynamicSchema}`
            }
          ],
          responses: {
            200: {
              description: "success res"
            }
          }
        },
      }

Is there any way I could write a request once and use multiple times for different routes?

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

No branches or pull requests

1 participant