DefinitionDocumentResolverFromOperation extends DefinitionDocumentResolverDefault { public String apply(String definitionName) { String defaultResolver = super.apply(definitionName); if (defaultResolver != null && config.isSeparatedOperationsEnabled()) return defaultString(config.getInterDocumentCrossReferencesPrefix()) + new File("..", defaultResolver).getPath(); else return defaultResolver; } DefinitionDocumentResolverFromOperation(Swagger2MarkupConverter.SwaggerContext context); String apply(String definitionName);  }
@Test public void testDefault() { Swagger2MarkupConverter.SwaggerContext context = createContext(); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")).isNull(); }
@Test public void testWithSeparatedDefinitions() { Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withSeparatedDefinitions() .build(); Swagger2MarkupConverter.SwaggerContext context = createContext(config); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")).isNull(); }
@Test public void testWithSeparatedOperationsAndInterDocumentCrossReferences() { Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withSeparatedOperations() .withInterDocumentCrossReferences() .build(); Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")) .isEqualTo(".." + fileSeparator + "definitions.adoc"); }
@Test public void testWithSeparatedOperationsAndSeparatedDefinitionsAndInterDocumentCrossReferences() { Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withSeparatedOperations() .withSeparatedDefinitions() .withInterDocumentCrossReferences() .build(); Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")) .isEqualTo(".." + fileSeparator + "definitions" + fileSeparator + "DefinitionName.adoc"); }
@Test public void testWithInterDocumentCrossReferences() { Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")) .isEqualTo("definitions.adoc"); }
@Test public void testWithInterDocumentCrossReferencesAndNoOutputPath() { Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .build(); Swagger2MarkupConverter.SwaggerContext context = createContext(config); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")) .isNull(); }
@Test public void testWithInterDocumentCrossReferencesAndPrefix() { Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences("prefix_") .build(); Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")) .isEqualTo("prefix_definitions.adoc"); }
@Test public void testWithInterDocumentCrossReferencesAndMarkdown() { Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withInterDocumentCrossReferences() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); Swagger2MarkupConverter.SwaggerContext context = createContext(config); context.setOutputPath(Paths.get("/tmp")); assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")) .isEqualTo("definitions.md"); }