fix: edge case where component would sometimes be marked a string #174
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🆘 Problem
This resolves an edge case that was introduced in some logic I added to repair schemas without a
type
that was sometimes marking the schema object as astring
. This would result in the following "broken" UI:You can see it in action here: http://bin.readme.com/s/5eaa651315dd18002423bd32
Now if we remove the
InputErrorResponse
, we'll see that it's resolved:Now what if you move the
InputErrorResponse
schema belowNewPreauthorization
?😬
🚧 Resolution
So the reason this was happening was that since our
cleanupSchemaDefaults
method forrequestBody
and component schema objects is recursive, and we were invoking it against thecomponents
object, and not individual schemas, it was difficult for us to ascertain when we were first processing a component schema and when we should add a missingtype
at the top level of a schema if it didn't have one.For this specific case, what was tripping up our logic was a few things:
InputErrorResponse
andNewPreauthorization
schemas didn't have a definedtype
.InputErrorResponse
as an object because we hadn't seen a top-levelproperties
property yet until that point, and when we did we immediately knew that we were processing an object, and could mark it as such.NewPreauthorization
schema, and after we had already processedInputErrorResponse
, we had the following data in our internal recursiveprevProps
memory state:Since we retained knowledge of parsing
properties
, our code misinterpreted this as having already seen this schema before, is it not parsing properties again for it and since it's missing atype
to addstring
so it's still valid JSON Schema.Resolving this involved a couple things:
components
level. This way we'll know exactly when we're first seeing a component schema.prevProps
memory state to clean itself out if we don't have aprevProp
. This will resolve the issue ofprevProps
retaining data from previously processed schemas.