kogosoftwarellc / open-api

A Monorepo of various packages to power OpenAPI in node
MIT License
892 stars 235 forks source link

parameters from Swagger 2.0 (openapi 2.0) YAML file are not caught by express-openapi #885

Closed bhargavtenali closed 1 year ago

bhargavtenali commented 1 year ago

Hi,

I was migrating from swagger-express-mw to express-openapi in Express Node js based backend Application

Previously we are using swagger 2.0 doc

swagger.yml file:

/publications/latest:
    x-swagger-router-controller: publication
    get:
      security:
        - JWScopeSecurity: ['user']
      summary: Get latest publications
      operationId: getLatestPublications
      tags:
        - publication
      parameters:
        - in: query
          name: size
          default: 10
          minimum: 0
          maximum: 3000
          required: true
          description: Number of results.
          type: number
        - in: query
          name: product
          required: false
          description: Use to filter on a specific product. Expecting product id
          type: array
          items:
            type: string
          collectionFormat: csv
      responses:
        403: *response403
        404: *response404
        500: *response500
        200:
          description: OK
          schema:
            type: array
            items:
              $ref: '#/definitions/Publication'

app.js file:

initialize({
  app: app,
  apiDoc: "./api/swagger/swagger.yaml",
  securityHandlers: {
    securityHandlers
  },
  operations: {
    ...allOperations as key value pairs
  }
});

Operation definition:

const getLatestPublications = async (req, res) => {
  try {
    let product = req.swagger.params.product?.value
    const size = req.swagger.params.size?.value

   // some opertion code

Here in above code how can i access the query params correctly as per swagger.yml I tried accessing them with req.query but they were coming as string instead of array (as mentioned in yml file)

Thanks in advance

bhargavtenali commented 1 year ago

Duplicate to #886 By mistake issue got posted twice

bhargavtenali commented 1 year ago

Duplicate to https://github.com/kogosoftwarellc/open-api/issues/886 By mistake issue got posted twice