Can't Setup Swagger - Cannot Read Property 'parameters' Of Undefined
I am having a problem with setting up the swagger into my node.js application. I am using swagger-jsdoc and swagger-ui-express for creating documentation. Here are the versions 's
Solution 1:
OpenAPI does not support $ref
everywhere. $ref
can only be used in specific places where the OpenAPI Specification explicitly states that the value of a field can be a "Reference Object".
For example, $ref
is not allowed directly under paths
, under components/parameters
and components/schemas
- you can only reference individual paths, parameters and schemas.
The correct version of your example is:
paths:/foo:$ref:'#/paths/index.yml#/~1foo'# $ref to root node `/foo` in `paths/index.yml`/bar:$ref:'#/paths/index.yml#/~1bar'# $ref to root node `/bar` in `paths/index.yml`components:parameters:param1:$ref:'components/parameters/index.yml#/param1'param2:$ref:'components/parameters/index.yml#/param2'schemas:schema1:$ref:'components/schemas/index.yml#/schema1'schema2:$ref:'components/schemas/index.yml#/schema2'
If you want to use $ref
in random places, you'll have to pre-process your definition using a parser/tool that can resolve arbitrary $refs; this will give you a valid OpenAPI file that can be used with OpenAPI-compliant tools. One such pre-processing tool is json-refs, you can find an example of pre-processing here.
Post a Comment for "Can't Setup Swagger - Cannot Read Property 'parameters' Of Undefined"