Bug: Cannot read property 'schemas' of undefined
Closed this issue · 3 comments
Describe the bug
I have a valid YAML swagger file (validated on editor.swagger.io). It throws the error. If I remove the components
section the error goes away.
To Reproduce
Steps to reproduce the behavior:
- Try starting nodejs with the YAML swagger file provided
Expected behavior
Node.js should load and I should be able to access the API docs url.
Desktop (please complete the following information):
- OS: MacOS
- Browser: Node.js
Additional context
Here is my Swagger YAML file:
paths:
/:
get:
description: >-
Verifies service is running
responses:
'200':
description: Success
default:
description: Service unavailable
/logs:
post:
description: >-
Request to publish log event
requestBody:
required: true
content:
'application/json':
schema:
$ref: '#/components/schemas/LogEvent'
responses:
'201':
description: Created
'400':
description: Invalid log format
default:
description: System error
components:
schemas:
LogEvent:
type: object
properties:
severity:
type: string
log_name:
type: string
event:
type: object
properties:
event_id:
oneOf:
- type: string
- type: number
timestamp:
type: string
env:
enum: [development, test, staging, production]
tenant_ref:
type: string
service:
type: string
process:
type: string
actor_ref:
type: string
target_ref:
type: string
action:
type: string
request:
oneOf:
- type: string
- type: object
response:
oneOf:
- type: string
- type: object
success:
type: boolean
auxiliary:
oneOf:
- type: string
- type: number
- type: object
required:
- timestamp
- env
- tenant_ref
- service
- process
- action
- success
required:
- severity
- log_name
- event
Here is a clip of the JavaScript that initiates Swagger:
const options = {
swaggerDefinition: {
info: {
title: 'REST API',
version: '1.0.0',
description: 'Example docs',
},
},
apis: ['swagger.yaml'],
}
const specs = swaggerJSDoc(options)
this.app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs))
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
can you provide a repo to reproduce your error?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.