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

Can you provide a simple entrypoint to compare 2 API instances #16

Closed
dalewking opened this issue Dec 15, 2018 · 5 comments
Closed

Can you provide a simple entrypoint to compare 2 API instances #16

dalewking opened this issue Dec 15, 2018 · 5 comments
Labels
0.2.1 enhancement New feature or request

Comments

@dalewking
Copy link

Since you are splitting out the CLI from the core library, was hoping you could provide a simple entry point that takes in 2 OpenAPI instances and returns the list of breaking changes.

Here is the code I am currently doing on my side, but you could do it much easier in the library:

private static Collection<BreakingChange> invokeSwaggerBrake(@NotNull OpenAPI oldApi, @NotNull OpenAPI newApi) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            RunnerConfiguration.class, ReporterConfiguration.class,
            MavenConfiguration.class, CoreConfiguration.class);

    final String beanName = context.getBeanNamesForType(
            ResolvableType.forClassWithGenerics(Transformer.class, OpenAPI.class, Specification.class))[0];

    @SuppressWarnings("unchecked")
    final Transformer<OpenAPI, Specification> transformer
            = (Transformer<OpenAPI, Specification>)context.getBean(beanName);

    return context.getBean(BreakChecker.class).check(transformer.transform(oldApi), transformer.transform(newApi));
}

Should be easy if you extract this expression on Runner to a new method called check:

breakChecker.check(transformer.transform(oldApi), transformer.transform(newApi));

Extract everything before .run(options) in Starter.start to a getRunner method. Then add this method to Starter:

public static Collection<BreakingChange> check(@NotNull OpenAPI oldApi, @NotNull OpenAPI newApi) {
    return getRunner().check(oldApi, newApi);
}
@galovics
Copy link
Member

Done. Please check if it suits your use-case. :-)

@dalewking
Copy link
Author

Was looking for a static method to call that hid all the dependency injection from me the way Stater.start does. What you have here requires me to still instantiate the Context to get the Checker.

@galovics
Copy link
Member

I mean if I provide a static method which does all the configuration in advance, it's undermining the modularity of swagger-brake. Now you want to use only a a single component of Swagger Brake so you have to do the configuration for sure.

Is it really a big issue that you have to do the configuration?

@dalewking
Copy link
Author

I don't see how it is undermining modularity. You provide that with Starter.start. All I am asking for is Starter to look like this:

public class Starter {
    private static BeanFactory getBeanFactory() {
        return new AnnotationConfigApplicationContext(RunnerConfiguration.class, ReporterConfiguration.class,
                MavenConfiguration.class, CoreConfiguration.class);
    }

    public static Collection<BreakingChange> start(Options options) {
        return getBeanFactory().getBean(Runner.class).run(options);
    }

    public static Collection<BreakingChange> check(OpenAPI oldApi, OpenAPI newApi) {
        return getBeanFactory().getBean(Checker.class).check(oldApi, newApi);
    }
}

@galovics
Copy link
Member

You got it @dalewking. :-)

@galovics galovics added enhancement New feature or request 0.3.0 0.2.1 and removed 0.3.0 labels Dec 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.2.1 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants