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

Fix an issue where JSON schema member names collided #200

Merged
merged 1 commit into from
Nov 5, 2019

Conversation

mtdowling
Copy link
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