-
-
Notifications
You must be signed in to change notification settings - Fork 213
Safely access schema to prevent crashes #881
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -182,7 +182,7 @@ function plainJsonObjectToOpenapi3 (container, jsonSchema, externalSchemas, secu | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // description should be optional | ||||||||||||||
| if (jsonSchemaElement.description) result.description = jsonSchemaElement.description | ||||||||||||||
| if (jsonSchemaElement?.description) result.description = jsonSchemaElement.description | ||||||||||||||
| return result | ||||||||||||||
| } | ||||||||||||||
| break | ||||||||||||||
|
|
@@ -239,16 +239,16 @@ function resolveSchemaExamplesRecursive (schema) { | |||||||||||||
| function schemaToMedia (schema) { | ||||||||||||||
| const media = { schema } | ||||||||||||||
|
|
||||||||||||||
| if (schema.examples?.length === 1) { | ||||||||||||||
| if (schema?.examples?.length === 1) { | ||||||||||||||
| media.example = schema.examples[0] | ||||||||||||||
| delete schema.examples | ||||||||||||||
| } else if (schema.examples?.length > 1) { | ||||||||||||||
| } else if (schema?.examples?.length > 1) { | ||||||||||||||
| media.examples = convertExamplesArrayToObject(schema.examples) | ||||||||||||||
| // examples is invalid property of media object schema | ||||||||||||||
| delete schema.examples | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if (schema[xExamples]) { | ||||||||||||||
| if (schema && schema[xExamples]) { | ||||||||||||||
| media.examples = schema[xExamples] | ||||||||||||||
| delete schema[xExamples] | ||||||||||||||
|
Comment on lines
+251
to
253
|
||||||||||||||
| if (schema && schema[xExamples]) { | |
| media.examples = schema[xExamples] | |
| delete schema[xExamples] | |
| if (schema?.[xExamples]) { | |
| media.examples = schema?.[xExamples] | |
| delete schema?.[xExamples] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent defensive programming: optional chaining is used in the condition check, but
jsonSchemaElement.descriptionis accessed directly in the assignment. IfjsonSchemaElementcould be null/undefined, the assignment should also use optional chaining:result.description = jsonSchemaElement?.description. However, this defensive check appears unnecessary sincejsonSchemaElementis always passed as a parameter from line 194 where it's accessed asobj[propKey], suggesting it should always be defined. Consider removing the optional chaining from the condition or applying it consistently.