GithubHelp home page GithubHelp logo

Generate parameters array about joi-to-swagger HOT 1 OPEN

twipped avatar twipped commented on August 20, 2024
Generate parameters array

from joi-to-swagger.

Comments (1)

Mairu avatar Mairu commented on August 20, 2024 1

This library is only generating the schemas and it is for OpenApi 3 not for the old version 2 which is known as Swagger.

If you check the OpenApi 3 version, you see that there is always a schema property, which is the one that is generated by this library.

Check out https://petstore3.swagger.io/ and https://petstore3.swagger.io/api/v3/openapi.json, every parameter has its own schema.

If you want to generate an array of such parameters from a Joi schema, you have to create your own function for that.

const queryParametersFromJoi = (joiSchema) => {
  const { swagger: { properties, required = [] } } = joiToSwagger(joiSchema);
  const params = [];
  Object.entries(properties).forEach(([name, schema]) => {
    const { description, ...schemaRest } = schema;
    const paramsProps = {};
    if (schemaRest.type === 'object') {
      paramsProps.style = 'deepObject';
    }
    params.push({
      in: 'query',
      name,
      required: required.includes(name),
      description,
      ...paramsProps,
      schema: schemaRest,
    });
  });
  return params;
};

from joi-to-swagger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.