Java Code Examples for io.swagger.models.Swagger#addDefinition()

The following examples show how to use io.swagger.models.Swagger#addDefinition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwaggerReader.java    From netty-rest with Apache License 2.0 6 votes vote down vote up
public SwaggerReader(Swagger swagger, ObjectMapper mapper, BiConsumer<Method, Operation> swaggerOperationConsumer, Map<Class, PrimitiveType> externalTypes)
{
    this.swagger = swagger;
    modelConverters = new ModelConverters(mapper);
    this.swaggerOperationConsumer = swaggerOperationConsumer;
    modelConverters.addConverter(new ModelResolver(mapper));
    if (externalTypes != null) {
        setExternalTypes(externalTypes);
    }
    mapper.registerModule(
            new SimpleModule("swagger", Version.unknownVersion()) {
                @Override
                public void setupModule(SetupContext context) {
                    context.insertAnnotationIntrospector(new SwaggerJacksonAnnotationIntrospector());
                }
            });
    errorProperty = modelConverters.readAsProperty(HttpServer.ErrorMessage.class);
    swagger.addDefinition("ErrorMessage", modelConverters.read(HttpServer.ErrorMessage.class).entrySet().iterator().next().getValue());
}
 
Example 2
Source File: SwaggerUtils.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public static void addDefinitions(Swagger swagger, Type paramType) {
  Map<String, Model> models = ModelConverters.getInstance().readAll(paramType);
  for (Entry<String, Model> entry : models.entrySet()) {
    if (null != swagger.getDefinitions()) {
      Model tempModel = swagger.getDefinitions().get(entry.getKey());
      if (null != tempModel && !tempModel.equals(entry.getValue())) {
        LOGGER.warn("duplicate param model: " + entry.getKey());
        throw new IllegalArgumentException("duplicate param model: " + entry.getKey());
      }
    }
    swagger.addDefinition(entry.getKey(), entry.getValue());
  }
}