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

$ref ignored in body parameter schemas #96

Open
smil2k opened this issue Dec 25, 2018 · 2 comments
Open

$ref ignored in body parameter schemas #96

smil2k opened this issue Dec 25, 2018 · 2 comments

Comments

@smil2k
Copy link

smil2k commented Dec 25, 2018

Example:
...

...
put:
    parameters:
    - name: body
      required: true
      in: body
      schema:
        $ref: '#/definitions/employeeFull'

validator.js does not call $ref resolution before enjoi at line 97. Suggested fix:

  if ((parameter.in === 'body' || parameter.in === 'formData') && template.schema) {
               iif (template.schema.$ref) {
                    template.schema = refresolver(schemas, template.schema.$ref);
                } // resolve schema!
                schema = enjoi(template.schema, {
                    subSchemas: schemas,
                    types: types
                });
            }

@smil2k
Copy link
Author

smil2k commented Dec 25, 2018

Maybe resolving all of the refs makes it easier. I do it externally currently, but I would have expected it to be done:

const http = require('http');
const express = require('express');
const swaggerize = require('swaggerize-express');
const refParser = require('json-schema-ref-parser');
const morgan = require('morgan');
app = express();

const server = http.createServer(app);

refParser.dereference('./api-docs/swagger.yaml')
  .then(function(schema) {
      app.use(morgan("dev"));
      app.use(swaggerize({
          api: schema,
          docspath: '/api-docs',
          handlers: './handlers'
      }));

      server.listen(10010, 'localhost', function () {
          app.swagger.api.host = server.address().address + ':' + server.address().port;
      });
  })
  .catch(function(err) {
    console.error(err);
  });

@djMax
Copy link

djMax commented May 1, 2020

I think I'm running into exactly this on query parameters as well. It's partly because it's using it as a key in a dictionary:

            if (def.parameters) {
                def.parameters.forEach(function (parameter) {
                    validators[parameter.in + parameter.name] = parameter;
                });
            }

And with a ref, those things aren't there.

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

2 participants