kogosoftwarellc / open-api

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

Swagger 2.0: response schema type file is invalid #745

Closed nguyentranchung closed 2 years ago

nguyentranchung commented 3 years ago

I got this error

Error: schema is invalid: data.properties['response'].type should be equal to one of the allowed values,
data.properties['response'].type should be array, data.properties['response'].type should match some schema in anyOf
at Ajv.validateSchema (C:\Users\xxx\node_modules\ajv\lib\ajv.js:177:16)
    at Ajv._addSchema (C:\Users\xxx\node_modules\ajv\lib\ajv.js:306:10)
    at Ajv.compile (C:\Users\xxx\node_modules\ajv\lib\ajv.js:112:24)
    at C:\Users\xxx\node_modules\openapi-response-validator\index.ts:154:26
    at Array.forEach (<anonymous>)
    at compileValidators (C:\Users\xxx\node_modules\openapi-response-validator\index.ts:153:24)
    at new OpenAPIResponseValidator (C:\Users\xxx\node_modules\openapi-response-validator\index.ts:107:23)
    at C:\Users\xxx\node_modules\openapi-framework\index.ts:439:28
    at Set.forEach (<anonymous>)
    at C:\Users\xxx\node_modules\openapi-framework\index.ts:348:45
    at Array.forEach (<anonymous>)
    at OpenAPIFramework.initialize (C:\Users\xxx\node_modules\openapi-framework\index.ts:320:12)
    at Object.initialize (C:\Users\xxx\node_modules\express-openapi\index.ts:85:13)  
    at App.initOpenAPI (C:\Users\xxx\server\app.ts:72:5)
    at C:\Users\xxx\server\app.ts:38:14
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Here is the definition

swagger: '2.0'
info:
  title: xxx
  description: xxx
  version: 1.0.0
  contact:
    name: xxx
basePath: /api
schemes:
  - http
consumes:
  - application/json
securityDefinitions:
  APIKeyHeader:
    type: apiKey
    in: header
    name: authorization
security:
  - APIKeyHeader: []
parameters:
  Timestamp:
    in: header
    name: Timestamp
    required: true
    type: string
    description: Timestamp of the request.
  Timezone-Offset:
    in: header
    name: Timezone-Offset
    required: false
    type: string
    description: 'The time zone difference, in minutes, from current locale (host system settings) to UTC.'
  Accept:
    in: header
    name: Accept
    required: true
    type: string
    description: 'Informs the server which Content-Type the client is able to understand. Available are application/json, application/xml'
  Accept-Encoding:
    in: header
    name: Accept-Encoding
    required: false
    type: string
    description: Informs the server about the encoding algorithm. Default is no encoding. Available is Gzip
  Accept-Language:
    in: header
    name: Accept-Language
    required: false
    type: string
    description: Informs the server about the language the server is expected to send back.(Example ja/ en)
  Accept-Charset:
    in: header
    name: Accept-Charset
    required: false
    type: string
    description: Informs the server about which character set the client is able to understand. Default is UTF-8
  Content-Type:
    in: header
    name: Content-Type
    required: false
    type: string
    description: Indicates the media type of the resource. (Example is application/json)
  Prefer:
    in: header
    name: Prefer
    required: false
    type: string
    description: 'is return the created or updated resource in the response.(Example return=minimal, return=representation, return=rawall)'
paths:
  /v1/file:
    parameters:
      - $ref: '#/parameters/Timestamp'
      - $ref: '#/parameters/Timezone-Offset'
      - $ref: '#/parameters/Accept'
      - $ref: '#/parameters/Accept-Encoding'
      - $ref: '#/parameters/Accept-Language'
      - $ref: '#/parameters/Accept-Charset'
    get:
      tags:
        - XXX
      summary: Download File.
      parameters:
        - in: query
          name: projectID
          type: string
          description: Project ID
          required: true
        - in: query
          name: domainID
          description: Domain ID.
          required: true
          type: string
      responses:
        '200':
          description: xxx
          headers:
            Date:
              type: string
              description: "Timestamp the response was processed, based on the server's clock, in\_RFC 5322\_date and time format."
            Content-Type:
              type: string
              description: The content type. Indicates the media type of the message body (MIME).
          schema:
            type: file
jsdevel commented 3 years ago

please submit a pr