Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue where conversion to openapi 3 from swagger 2 definition was failing due to TypeError. #647

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

VShingala
Copy link

@VShingala VShingala commented Jun 20, 2023

Overview

This PR fixes one of the issue causing TypeError while converting Swagger 2.0 definition to OpenAPI 3.0. Issue was happening due to expecting certain property of definition schemaOrRef as string always. This results in a TypeError if this property is non-string and it can be non-string as rather than mentioning $ref here, one can use schema directly.

TypeError: SWAGGER2.0: schemaOrRef.startsWith is not a function
  File "/var/www-api/node_modules/swagger2openapi/index.js", line 182, col 29, in fixUpSubSchemaExtensions
    if (schemaOrRef.startsWith('#/definitions/')) {
  File "/var/www-api/node_modules/swagger2openapi/index.js", line 191, col 9, in null.<anonymous>
    fixUpSubSchemaExtensions(schema,parent);
  File "/var/www-api/node_modules/oas-schema-walker/index.js", line 53, col 5, in walkSchema
    callback(schema,parent,state);
  File "/var/www-api/node_modules/oas-schema-walker/index.js", line 96, col 13, in walkSchema
    walkSchema(subSchema,schema,state,callback);
  File "/var/www-api/node_modules/oas-schema-walker/index.js", line 64, col 9, in walkSchema
    walkSchema(schema.items,schema,state,callback);
  File "/var/www-api/node_modules/oas-schema-walker/index.js", line 82, col 13, in Object.walkSchema
    walkSchema(subSchema,schema,state,callback);

Fix

Fix does not affect any existing use case and only aims to avoid TypeError in certain case by checking type to be string before accessing string-related prototype function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant