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

Expander refactoring #96

Closed
fredbi opened this issue Jul 4, 2019 · 1 comment
Closed

Expander refactoring #96

fredbi opened this issue Jul 4, 2019 · 1 comment

Comments

@fredbi
Copy link
Member

fredbi commented Jul 4, 2019

Most of this lib complexity lies with the resolver and expander features, but these ones bear almost no specifics about swagger specs.

Factoring out this complex but battle-tested feature could simplify the move to OAI 3.

IMHO, spec expansion should be refactored along the following lines:

  • moves the core functionality to a separate package (e.g go-openapi/spec/expander)
  • make individual spec objects Resolvable and Expandable
  • expose additional tooling like normalization, etc which could be factorized with go-openapi/flatten which now overlaps with this logics quite a bit
  • further factorization with analysis to single out common $ref functionality used by spec flattening: complete flattening logics (like name resolution, etc) would remain swagger-specific in analysis, but building blocks such as rebasing refs, replacing refs or schemas could be added to the new common set of tools

e.g. something like equipping spec objects with:

type Resolvable interface {
  ResolveWithRoot(root interface{}, opts ...*ExpandOptions, caches ...ResolutionCache) error
  ResolveWithBase(root interface{}, ref Refable, opts ...*ExpandOptions, caches ...ResolutionCache)  error
}

type Expandable interface {
  ExpandWithRoot(root interface{}, ref Refable, opts ...*ExpandOptions, cache ...ResolutionCache) 
  ExpandWithBase(root interface{}, ref Refable, opts ...*ExpandOptions, cache ...ResolutionCache) 
}

We could provide backward compatibility by leaving methods a the package level.

@fredbi
Copy link
Member Author

fredbi commented Jan 4, 2021

Merged two refactoring-only PRs, without changing the interface. This essentially improves readability. I give up on any change of the interface.

@fredbi fredbi closed this as completed Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant