SwaggerGenerator { public Swagger writeSwagger(Iterable<ApiConfig> configs, boolean writeInternal, SwaggerContext context) throws ApiConfigException { try { TypeLoader typeLoader = new TypeLoader(SwaggerGenerator.class.getClassLoader()); SchemaRepository repo = new SchemaRepository(typeLoader); GenerationContext genCtx = new GenerationContext(); genCtx.validator = new ApiConfigValidator(typeLoader, repo); genCtx.writeInternal = writeInternal; genCtx.schemata = new SchemaRepository(typeLoader); return writeSwagger(configs, context, genCtx); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } }  Swagger writeSwagger(Iterable<ApiConfig> configs, boolean writeInternal,
      SwaggerContext context);  }
@Test public void testWriteSwagger_FooEndpoint() throws Exception { ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), FooEndpoint.class); Swagger swagger = generator.writeSwagger(ImmutableList.of(config), false, context); Swagger expected = readExpectedAsSwagger("foo_endpoint.swagger"); checkSwagger(expected, swagger); }
@Test public void testWriteSwagger_FooEndpointDefaultContext() throws Exception { ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), FooEndpoint.class); Swagger swagger = generator.writeSwagger(ImmutableList.of(config), false, new SwaggerContext()); Swagger expected = readExpectedAsSwagger("foo_endpoint_default_context.swagger"); checkSwagger(expected, swagger); }
@Test public void testWriteSwagger_FooEndpoint_internal() throws Exception { ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), FooEndpoint.class); Swagger swagger = generator.writeSwagger(ImmutableList.of(config), true, context); Swagger expected = readExpectedAsSwagger("foo_endpoint_internal.swagger"); checkSwagger(expected, swagger); }
@Test public void testWriteSwagger_ThirdPartyAuthEndpoint() throws Exception { ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), ThirdPartyAuthEndpoint.class); Swagger swagger = generator.writeSwagger(ImmutableList.of(config), true, context); Swagger expected = readExpectedAsSwagger("third_party_auth.swagger"); checkSwagger(expected, swagger); }
@Test public void testWriteSwagger_GoogleAuthEndpoint() throws Exception { ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), GoogleAuthEndpoint.class); Swagger swagger = generator.writeSwagger(ImmutableList.of(config), true, context); Swagger expected = readExpectedAsSwagger("google_auth.swagger"); checkSwagger(expected, swagger); }
@Test public void testWriteSwagger_ApiKeys() throws Exception { ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), ApiKeysEndpoint.class); Swagger swagger = generator.writeSwagger(ImmutableList.of(config), true, context); Swagger expected = readExpectedAsSwagger("api_keys.swagger"); checkSwagger(expected, swagger); }
@Test public void testWriteSwagger_FooEndpointWithDescription() throws Exception { ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), FooDescriptionEndpoint.class); Swagger swagger = generator.writeSwagger(ImmutableList.of(config), false, context); Swagger expected = readExpectedAsSwagger("foo_with_description_endpoint.swagger"); checkSwagger(expected, swagger); }
@Test public void testWriteSwagger_MultiResourceEndpoint() throws Exception { ServiceContext serviceContext = ServiceContext.create(); ImmutableList<ApiConfig> configs = ImmutableList.of( configLoader.loadConfiguration(serviceContext, NoResourceEndpoint.class), configLoader.loadConfiguration(serviceContext, Resource1Endpoint.class), configLoader.loadConfiguration(serviceContext, Resource2Endpoint.class)); Swagger swagger = generator.writeSwagger(configs, false, context); Swagger expected = readExpectedAsSwagger("multi_resource_endpoint.swagger"); checkSwagger(expected, swagger); }
@Test public void testWriteSwagger_MultiVersionEndpoint() throws Exception { ServiceContext serviceContext = ServiceContext.create(); ImmutableList<ApiConfig> configs = ImmutableList.of( configLoader.loadConfiguration(serviceContext, Version1Endpoint.class), configLoader.loadConfiguration(serviceContext, Version2Endpoint.class)); Swagger swagger = generator.writeSwagger(configs, false, context); Swagger expected = readExpectedAsSwagger("multi_version_endpoint.swagger"); checkSwagger(expected, swagger); }