Skip to content

Instantly share code, notes, and snippets.

View swagger-spec-assembler.js
/**
* Combine the swagger specification parts into a single YAML file.
*/
var resolve = require('json-refs').resolveRefs;
var YAML = require('js-yaml');
var fs = require('fs');
process.chdir('spec');
@norbertpotocki
norbertpotocki / basketServiceAPI.yaml
Created Mar 30, 2016
API for a simple basket service
View basketServiceAPI.yaml
swagger: '2.0'
info:
title: BasketService API
version: "1.0.0"
host: api.myservice.com
schemes:
- https
basePath: /v1
View bootstrapSample.yaml
---
spring:
profiles: local
configuration:
endpoint:
protocol: http
hostname: localhost
port: 8500
View sampleConfig.yaml
databasePool:
url: jdbc:mysql://localhost:3306/SomeDb
maxPoolSize: 60
connectionTimeouMs: 1000
idleTimeoutMs: 120000
maxLifetimeMs: 1800000
search:
defaultQuery: Hey Norbert!
View create-docs-pr.step
assemble-single-spec-file:
description: Assembles a single YAML spec file from partial files
command: node swagger-spec-assembler.js > api-spec.yaml
create-documentation-pull-request:
description: Create a PR against the documentation repository
command:
export GIT_BRANCH=update-from-specs-`date +%Y-%m-%-d-%H-%M`
&& git clone git@git.mydomain.com:MyService/documentation.git
&& cd documentation
@norbertpotocki
norbertpotocki / Cfg4jGitSource.java
Created Mar 17, 2016
Configuration source backed by git
View Cfg4jGitSource.java
@Bean
ConfigurationProvider configurationProvider(@Value("${configuration.environment}") String configurationEnvironment) {
ConfigurationSource GitSource = new GitConfigurationSourceBuilder()
.withRepositoryURI("https://Github.com/myUser/my-config-fork.Git")
.build();
return new ConfigurationProviderBuilder()
.withConfigurationSource(GitSource)
.withEnvironment(new ImmutableEnvironment("app/" + configurationEnvironment + "/feature"))
.withReloadStrategy(new PeriodicalReloadStrategy(30, TimeUnit.SECONDS))
@norbertpotocki
norbertpotocki / Cfg4jConfigurationMerge.java
Created Mar 17, 2016
Merge configuration using MergeConfigurationSource
View Cfg4jConfigurationMerge.java
@Bean
ConfigurationProvider configurationProvider(ConfigurationSource configurationSource,
@Value("${configuration.environment}") String configurationEnvironment) {
ConfigurationSource localOverrideSource = new FilesConfigurationSource(() -> Collections.singletonList(Paths.get("application.properties")));
MergeConfigurationSource mergeConfigurationSource = new MergeConfigurationSource(localOverrideSource, configurationSource);
return new ConfigurationProviderBuilder()
.withConfigurationSource(mergeConfigurationSource)
.withEnvironment(new ImmutableEnvironment("app/" + configurationEnvironment + "/feature"))
@norbertpotocki
norbertpotocki / Cfg4jBindInject.java
Created Mar 17, 2016
Configuration injection via “interface binding” (will reload as config changes)
View Cfg4jBindInject.java
SearchConfig config = configurationProvider.bind("search", SearchConfig.class);
// in search method
if(queryEmpty()) {
return config.defaultQuery();
}
@norbertpotocki
norbertpotocki / Cfg4jDirectInject.java
Created Mar 17, 2016
Direct configuration injection (won’t reload as config changes)
View Cfg4jDirectInject.java
String defaultQuery = configurationProvider.getProperty("search.defaultQuery", String.class);
if(queryEmpty()) {
return defaultQuery;
}
@norbertpotocki
norbertpotocki / Cfg4jBeansConfig.java
Created Mar 17, 2016
Using dependency injection for injecting configuration.
View Cfg4jBeansConfig.java
import org.cfg4j.provider.ConfigurationProvider;
import org.cfg4j.provider.ConfigurationProviderBuilder;
import org.cfg4j.source.ConfigurationSource;
import org.cfg4j.source.consul.ConsulConfigurationSourceBuilder;
import org.cfg4j.source.context.environment.ImmutableEnvironment;
import org.cfg4j.source.reload.strategy.PeriodicalReloadStrategy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;