swagger.addDefinition(entry.getKey(), doModel(type, entry.getValue()));
public static void addDefinitions(Swagger swagger, Type paramType) { Map<String, Model> models = ModelConverters.getInstance().readAll(paramType); for (Map.Entry<String, Model> entry : models.entrySet()) { swagger.addDefinition(entry.getKey(), entry.getValue()); } }
private RefModel toRefModel(String modelType) { if (RefProperty.class.isInstance(property)) { return (RefModel) PropertyBuilder.toModel(property); } ModelImpl modelImpl = new ModelImpl(); modelImpl.setType("object"); modelImpl.setName(name); modelImpl.addProperty(name, property); operationGenerator.getSwagger().addDefinition(modelType, modelImpl); RefModel refModel = new RefModel(); refModel.setReference("#/definitions/" + modelType); return refModel; } }
public Swagger model(String name, Model model) { this.addDefinition(name, model); return this; }
/** * Add the {@code clazz} model to Swagger. The model is a class annotated with * {@link ApiModel}. The definition in {@link Swagger} is in the form of a map * with the keys being the class names and the values - a {@link Model} object * defined by Swagger. The models contain different {@link io.swagger.models.properties.Property} * objects which vary depending on the class fields. * * @param clazz The class which specifies the model. */ private void createApiModel(Class<?> clazz) { swagger.addDefinition(clazz.getSimpleName(), model(clazz)); }
public static void addDefinitions(Swagger swagger, Type paramType) { Map<String, Model> models = ModelConverters.getInstance().readAll(paramType); for (Map.Entry<String, Model> entry : models.entrySet()) { swagger.addDefinition(entry.getKey(), entry.getValue()); } }
private void createDefinition(OperationEnum operationEnum, String resourceName, String resourceParentName, DelegatingResourceHandler<?> resourceHandler) { String definitionName = getSchemaName(resourceName, resourceParentName, operationEnum); Model model = null; Model modelRef = null; Model modelFull = null; if (definitionName.endsWith("Get")) { model = resourceHandler.getGETModel(Representation.DEFAULT); modelRef = resourceHandler.getGETModel(Representation.REF); modelFull = resourceHandler.getGETModel(Representation.FULL); } else if (definitionName.endsWith("Create")) { model = resourceHandler.getCREATEModel(Representation.DEFAULT); modelFull = resourceHandler.getCREATEModel(Representation.FULL); } else if (definitionName.endsWith("Update")) { model = resourceHandler.getUPDATEModel(Representation.DEFAULT); } if (model != null) { swagger.addDefinition(definitionName, model); } if (modelRef != null) { swagger.addDefinition(definitionName + "Ref", modelRef); } if (modelFull != null) { swagger.addDefinition(definitionName + "Full", modelFull); } }
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()); }
swagger.addDefinition(name, model); model.name(name);
private RefModel toRefModel(String modelType) { if (RefProperty.class.isInstance(property)) { return (RefModel) PropertyBuilder.toModel(property); } ModelImpl modelImpl = new ModelImpl(); modelImpl.setType("object"); modelImpl.setName(name); modelImpl.addProperty(name, property); operationGenerator.getSwagger().addDefinition(modelType, modelImpl); RefModel refModel = new RefModel(); refModel.setReference("#/definitions/" + modelType); return refModel; } }
Map<String, Model> subProperty = modelConverters.read(parameter.getParameterizedType()); String simpleRef = ((RefProperty) property).getSimpleRef(); swagger.addDefinition(simpleRef, subProperty.get(simpleRef)); swagger.addDefinition(entry.getKey(), entry.getValue()); bodyParameter.setSchema(new RefModel(model.getName())); bodyParameter.setRequired(true); swagger.addDefinition(name, model); builder.add(bodyParameter);
swagger.addDefinition(modelTag.getName(), model);
swagger.addDefinition(name, model);
swagger.addDefinition(entry.getKey(), entry.getValue());
if(existingModel == null) { swagger.addDefinition(newRef, model); cache.addReferencedKey(newRef);
private void addDefaultDefinitions() { // schema of the default response // received from fetchAll and search operations swagger.addDefinition("FetchAll", new ModelImpl() .property("results", new ArrayProperty() .items(new ObjectProperty() .property("uuid", new StringProperty()) .property("display", new StringProperty()) .property("links", new ArrayProperty() .items(new ObjectProperty() .property("rel", new StringProperty().example("self")) .property("uri", new StringProperty(StringProperty.Format.URI))))))); }
@Test public void swaggerSerializeTest() { final Info info = new Info().version("1.0.0").title("Swagger WebServices REST"); Swagger swagger = new Swagger().info(info).securityDefinition("basicAuth", new BasicAuthDefinition()) .scheme(Scheme.HTTP).consumes("application/json").produces("application/json"); final Model patientModel = ModelConverters.getInstance().read(Patient.class).get("Patient"); swagger.addDefinition("Patient", patientModel); final String swaggerJson = Json.pretty(swagger); assertNotNull(swaggerJson); }
/** * Manually register the Pippo Error class as Swagger model. * * @param swagger * @return a ref for the Error model */ protected RefProperty registerErrorModel(Swagger swagger) { String ref = Error.class.getSimpleName(); if (swagger.getDefinitions() != null && swagger.getDefinitions().containsKey(ref)) { // model already registered return new RefProperty(ref); } ModelImpl model = new ModelImpl(); swagger.addDefinition(ref, model); model.setDescription("an error message"); model.addProperty("statusCode", new IntegerProperty().readOnly().description("http status code")); model.addProperty("statusMessage", new StringProperty().readOnly().description("description of the http status code")); model.addProperty("requestMethod", new StringProperty().readOnly().description("http request method")); model.addProperty("requestUri", new StringProperty().readOnly().description("http request path")); model.addProperty("message", new StringProperty().readOnly().description("application message")); if (settings.isDev()) { // in DEV mode the stacktrace is returned in the error message model.addProperty("stacktrace", new StringProperty().readOnly().description("application stacktrace")); } return new RefProperty(ref); }
/** * Manually register the Pippo Error class as Swagger model. * * @param swagger * @return a ref for the Error model */ protected RefProperty registerErrorModel(Swagger swagger) { String ref = Error.class.getSimpleName(); if (swagger.getDefinitions() != null && swagger.getDefinitions().containsKey(ref)) { // model already registered return new RefProperty(ref); } ModelImpl model = new ModelImpl(); swagger.addDefinition(ref, model); model.setDescription("an error message"); model.addProperty("statusCode", new IntegerProperty().readOnly().description("http status code")); model.addProperty("statusMessage", new StringProperty().readOnly().description("description of the http status code")); model.addProperty("requestMethod", new StringProperty().readOnly().description("http request method")); model.addProperty("requestUri", new StringProperty().readOnly().description("http request path")); model.addProperty("message", new StringProperty().readOnly().description("application message")); if (settings.isDev()) { // in DEV mode the stacktrace is returned in the error message model.addProperty("stacktrace", new StringProperty().readOnly().description("application stacktrace")); } return new RefProperty(ref); }
.schemes(Arrays.asList(new Scheme[] {Scheme.HTTP})); expectedSwagger.addDefinition("AnnotatedServiceDocumentMock", model); expectedSwagger.tags(expectedTags.stream().map(tag -> new Tag().name(tag)).collect(Collectors.toList())); expectedSwagger.path(PATH + "/{id}", getPath);