public static String name(Type type) { return name(Json.mapper().constructType(type)); }
/** * Mostly for kotlin null safe operator and immutable properties. * * @param type Target type. * @param model Model. * @return Input model. */ private Model doModel(Type type, Model model) { Map<String, Property> properties = model.getProperties(); if (properties != null) { BeanDescription desc = Json.mapper().getSerializationConfig() .introspect(Json.mapper().constructType(type)); for (BeanPropertyDefinition beanProperty : desc.findProperties()) { Property property = properties.get(beanProperty.getName()); if (property != null) { property.setRequired(beanProperty.isRequired()); } } } return model; }
router.get(options.path + "/swagger.json", options.path + "/swagger.yml", req -> { Map<String, Object> hash = conf.getConfig("swagger").root().unwrapped(); Swagger base = Json.mapper().convertValue(hash, Swagger.class); Swagger swagger = new SwaggerBuilder(options.tagger) .build(base, provider.apply(req.require(M))); return Results.json(Json.mapper().writer().writeValueAsBytes(swagger)); boolean json = req.path().endsWith(".json"); if (json) { return Results.json(Json.mapper().writer().writeValueAsBytes(swagger));
Config conf = req.require(Config.class); Map<String, Object> hash = conf.getConfig("raml").root().unwrapped(); Raml base = Json.mapper().convertValue(hash, Raml.class); Raml raml = Raml.build(base, provider.apply(req.require(M))); if (configurer != null) {
private void configureObjectMapperFeatures(List<String> features, boolean enabled) throws Exception { for (String feature : features) { int i= feature.lastIndexOf("."); Class clazz = Class.forName(feature.substring(0,i)); Enum e = Enum.valueOf(clazz,feature.substring(i+1)); getLog().debug("enabling " + e.getDeclaringClass().toString() + "." + e.name() + ""); Method method = Json.mapper().getClass().getMethod("configure",e.getClass(),boolean.class); method.invoke(Json.mapper(),e,enabled); } }
private static ObjectMapper findMapper() { ObjectMapper mapper = Json.mapper(); mapper.registerModule(new EnumModuleExt()); return mapper; }
public BodyParameter createBodyParameter(String paramName) { String modelType = ParamUtils.generateBodyParameterName(operationGenerator.getProviderMethod()); RefModel model = toRefModel(modelType); setName(paramName); setSchema(model); try { return Json.mapper().readValue(Json.mapper().writeValueAsString(this), BodyParameter.class); } catch (IOException e) { throw new IllegalStateException("failed to createBodyParameter.", e); } }
public void loadModelModifier() throws GenerateException, IOException { ObjectMapper objectMapper = Json.mapper(); if (apiSource.isUseJAXBAnnotationProcessor()) { JaxbAnnotationModule jaxbAnnotationModule = new JaxbAnnotationModule();
public JsonApiModelResolver(EntityDictionary dictionary) { super(Json.mapper()); this.dictionary = dictionary; }
/** * Initializes a service parser for swagger. * * @param httpAlias The alias for ballerina/http module. * @param swaggerAlias The alias for ballerina.swagger module. */ public SwaggerServiceMapper(String httpAlias, String swaggerAlias) { // Default object mapper is JSON mapper available in swagger utils. this.httpAlias = httpAlias; this.swaggerAlias = swaggerAlias; this.objectMapper = Json.mapper(); }
/** * Default constructor. */ public ByteArrayFixerModelConverter() { super(Json.mapper()); }
@Override public Swagger read(JsonNode node) throws IOException { if (node == null) { return null; } return Json.mapper().convertValue(node, Swagger.class); } }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String pathInfo = request.getRequestURI(); if (pathInfo.endsWith("/swagger.json")) { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().println(Json.mapper().writeValueAsString(request.getServletContext().getAttribute("swagger"))); } else { response.setStatus(404); } }
private String generateSchemaString(Object model, String modelName, Map<String, io.swagger.models.Model> definitions) { try { String modelSchema = Json.mapper().writeValueAsString(model); String models = Json.mapper().writeValueAsString(definitions); // inline all references String schema = new SchemaTransformer().flatten(modelSchema, models); LOG.info("Generated json-schema for model " + modelName + ": " + schema); return schema; } catch (IOException e) { throw new IllegalArgumentException("Could not process model", e); } }
/** * Creates a Swagger schema validator based on the given JSON-based Swagger spec. * * @param swaggerSpec the Swagger spec (in JSON format) * @return a validator for that spec * @throws IOException if the Swagger spec is not a valid JSON object */ public static SwaggerValidator forJsonSchema(Reader swaggerSpec) throws IOException { return new SwaggerValidator(Json.mapper().readTree(swaggerSpec)); }
public Property property(ObjectNode node, String location, ParseResult result) { if(node != null) { if(node.get("type") == null) { // may have an enum where type can be inferred JsonNode enumNode = node.get("enum"); if(enumNode != null && enumNode.isArray()) { String type = inferTypeFromArray((ArrayNode) enumNode); node.put("type", type); } } } return Json.mapper().convertValue(node, Property.class); }
private String getAuthorizationType(Operation op) { String authType = "NONE"; if (op.getVendorExtensions() != null) { Object objectNode = op.getVendorExtensions().get(EXTENSION_AUTH); Map<String, String> authExtension = Json.mapper().convertValue( objectNode, Map.class ); if (authExtension != null) { authType = authExtension.get("type").toUpperCase(); } } return authType; }
public static <T> T readYamlValue(String contents, Class<T> expectedType) { org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(new SafeConstructor()); return Json.mapper().convertValue(yaml.load(contents), expectedType); } }
public BodyParameter createBodyParameter(String paramName) { String modelType = ParamUtils.generateBodyParameterName(operationGenerator.getProviderMethod()); RefModel model = toRefModel(modelType); setName(paramName); setSchema(model); try { return Json.mapper().readValue(Json.mapper().writeValueAsString(this), BodyParameter.class); } catch (IOException e) { throw new IllegalStateException("failed to createBodyParameter.", e); } }
private void swaggerApiHandle(RakamHttpRequest request) { String content; try { content = Json.mapper().writeValueAsString(swagger); } catch (JsonProcessingException e) { request.response("Error").end(); return; } request.response(content).end(); }