Giter Club home page Giter Club logo

Comments (2)

LonelyPrincess avatar LonelyPrincess commented on May 26, 2024

Hello, @NolanChan,

You can specify the structure of objects by using @typedef to define schemas, such as this example in the documentation:

/**
 * A song type
 * @typedef {object} Song
 * @property {string} title.required
 * @property {string} artist
 * @property {number} year
 */

As you can see here, Song will be an object, and you can use @property to define the different properties an instance of Song can have.

If you want to tell the library that your endpoint is going to return an object with this structure, you can just assign it the type Song after having defined the type with @typedef, as in the example above.

/**
 * GET /api/v1/song/:songId
 * @return {Song} 200 - success response - application/json
 */

If you want to define the structure of an object property inside of an existing schema, the procedure would be the same: you'll have to define a model with the structure your property is supposed to have. The following is an example of a Song object with an artist property that will be an object with two fields: name and age.

/**
 * @typedef {object} Artist
 * @property {string} name.required
 * @property {number} age
 */

/**
 * @typedef {object} Song
 * @property {string} title.required
 * @property {Artist} artist
 * @property {number} year
 */

Hope that helps! 🙂

from express-jsdoc-swagger.

kevinccbsg avatar kevinccbsg commented on May 26, 2024

I'm closing this due to inactivity @NolanChan feel free to re-open in case your problem was not solved with the previous comment 👍

from express-jsdoc-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.