Skip to content

Fix an issue where JSON schema member names collided#200

Merged
mtdowling merged 1 commit intomasterfrom
deconflict-generated-shapes
Nov 5, 2019
Merged

Fix an issue where JSON schema member names collided#200
mtdowling merged 1 commit intomasterfrom
deconflict-generated-shapes

Conversation

@mtdowling
Copy link
Copy Markdown
Member

TODO: break this API to make this work more reliably.

This is addressed by temporarily setting a de-conflicting ref
strategy. This is the minimal change needed to fix a reported
bug, but it is a hack and we should break this API before GA.

We want to do the right thing by default. However, the default
that was previously chosen didn't account for the possibility
of shape name conflicts when converting members to JSON schema
pointers. For example, consider the following shapes:

  • A member of a list, foo.baz#PageScripts$member
  • A member of a structure, foo.baz#Page$scripts

If we only rely on the RefStrategy#createDefaultStrategy, then
we would actually generate the same JSON schema shape name for
both of the above member shapes: FooBazPageScriptsMember. To
avoid this, we need to know the shape index being converted and
automatically handle conflicts. However, because this class is
mutable, we have to do some funky stuff with state to "do the
right thing" by lazily creating a
RefStrategy#createDefaultDeconflictingStrategy in this method
once a ShapeIndex is available (given as an argument).

A better API would use a builder that builds a JsonSchemaConverter
that has a fixed shape index, ref strategy, etc. This would allow
ref strategies to do more up-front computations, and allow them to
even become implementation details of JsonSchemaConverter by exposing
a similar API that delegates from a converter into the strategy.

There's also quite a bit of awkward code in the OpenAPI conversion code
base that tries to deal with merging configuration values and deriving
a default JsonSchemaConverter if one isn't set. A better API there would
be to not even allow the injection of a custom JsonSchemaConverter at all.

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

TODO: break this API to make this work more reliably.

This is addressed by temporarily setting a de-conflicting ref
strategy. This is the minimal change needed to fix a reported
bug, but it is a hack and we should break this API before GA.

We want to do the right thing by default. However, the default
that was previously chosen didn't account for the possibility
of shape name conflicts when converting members to JSON schema
pointers. For example, consider the following shapes:

- A member of a list, foo.baz#PageScripts$member
- A member of a structure, foo.baz#Page$scripts

If we only rely on the RefStrategy#createDefaultStrategy, then
we would actually generate the same JSON schema shape name for
both of the above member shapes: FooBazPageScriptsMember. To
avoid this, we need to know the shape index being converted and
automatically handle conflicts. However, because this class is
mutable, we have to do some funky stuff with state to "do the
right thing" by lazily creating a
RefStrategy#createDefaultDeconflictingStrategy in this method
once a ShapeIndex is available (given as an argument).

A better API would use a builder that builds a JsonSchemaConverter
that has a fixed shape index, ref strategy, etc. This would allow
ref strategies to do more up-front computations, and allow them to
even become implementation details of JsonSchemaConverter by exposing
a similar API that delegates from a converter into the strategy.

There's also quite a bit of awkward code in the OpenAPI conversion code
base that tries to deal with merging configuration values and deriving
a default JsonSchemaConverter if one isn't set. A better API there would
be to not even allow the injection of a custom JsonSchemaConverter at all.
@mtdowling mtdowling requested a review from kstich November 5, 2019 07:43
@mtdowling mtdowling merged commit 6c44750 into master Nov 5, 2019
@mtdowling mtdowling deleted the deconflict-generated-shapes branch November 14, 2019 06:51
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.

2 participants