We are currently using the springfox SWAGGER implementation (it's fantastic
by the way!) and are looking to expose a REST api which accepts and returns
soft-configured JSON objects - xml too, but for now lets focus on the JSON.
The specification for these objects may change per installation and client,
processing of the objects is already configurable via mapping files and
such, but the api validations of the objects need to be configurable and so
too does the accompanying example. In other words, I am looking for a
simple example which could accept a model definition string at runtime
(without recompile), preferably dynamically (without restart) and certainly
without any pre-defined POJOs from which to generate the schema via
reflection.
Currently these JSON objects are being passed as objects and then parsed -
but the swagger ui provides no example or validation etc.
The idea then being that the user/client could update the model
configuration (stored in say a file or DB) to suit their requirements -
adding custom fields, re-arranging hierarchies or branches and renaming the
fields entirely to suit some other system or input and then altering the
data mapping configs accordingly - no recompile.
Please assist with an example which might take a model definition (json
schema or such) and inject it at spring runtime.
I think the below example is perhaps a step in the right direction... with
the highlighted section being perhaps where I need some assistance.
@Component
@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER)
public class TestOperation implements ApiListingScannerPlugin {
// tag::api-listing-plugin[]
@Override
public List<ApiDescription> apply(DocumentationContext context) {
return new ArrayList<ApiDescription>(
Arrays.asList( //<1>
new ApiDescription(
"/bugs/1767",
"This is a bug",
Arrays.asList( //<2>
new OperationBuilder(
new CachingOperationNameGenerator())
.authorizations(new ArrayList())
.codegenMethodNameStem("bug1767GET") //<3>
.method(HttpMethod.GET)
.notes("This is a test method")
.parameters(
Arrays.asList( //<4>
new
ParameterBuilder()
.description("search by description")
.type(new
TypeResolver().resolve(String.class))
.name("description")
.parameterType("query")
.parameterAccess("access")
.required(true)
.modelRef(new ModelRef("string")) //<5>
.build()))
.build()),
false)));
}
// tag::api-listing-plugin[]
@Override
public boolean supports(DocumentationType delimiter) {
return DocumentationType.SWAGGER_2.equals(delimiter);
}
}
>
--
You received this message because you are subscribed to the Google Groups
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.