io.swagger.models.parameters.RefParameter Java Examples
The following examples show how to use
io.swagger.models.parameters.RefParameter.
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: OAS2Parser.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Creates a json string using the swagger object. * * @param swaggerObj swagger object * @return json string using the swagger object * @throws APIManagementException error while creating swagger json */ private String getSwaggerJsonString(Swagger swaggerObj) throws APIManagementException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(SerializationFeature.INDENT_OUTPUT); //this is to ignore "originalRef" in schema objects mapper.addMixIn(RefModel.class, IgnoreOriginalRefMixin.class); mapper.addMixIn(RefProperty.class, IgnoreOriginalRefMixin.class); mapper.addMixIn(RefPath.class, IgnoreOriginalRefMixin.class); mapper.addMixIn(RefParameter.class, IgnoreOriginalRefMixin.class); mapper.addMixIn(RefResponse.class, IgnoreOriginalRefMixin.class); //this is to ignore "responseSchema" in response schema objects mapper.addMixIn(Response.class, ResponseSchemaMixin.class); try { return new String(mapper.writeValueAsBytes(swaggerObj)); } catch (JsonProcessingException e) { throw new APIManagementException("Error while generating Swagger json from model", e); } }
Example #2
Source File: OASParserUtil.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Creates a json string using the swagger object. * * @param swaggerObj swagger object * @return json string using the swagger object * @throws APIManagementException error while creating swagger json */ public static String getSwaggerJsonString(Swagger swaggerObj) throws APIManagementException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(SerializationFeature.INDENT_OUTPUT); //this is to ignore "originalRef" in schema objects mapper.addMixIn(RefModel.class, IgnoreOriginalRefMixin.class); mapper.addMixIn(RefProperty.class, IgnoreOriginalRefMixin.class); mapper.addMixIn(RefPath.class, IgnoreOriginalRefMixin.class); mapper.addMixIn(RefParameter.class, IgnoreOriginalRefMixin.class); mapper.addMixIn(RefResponse.class, IgnoreOriginalRefMixin.class); //this is to ignore "responseSchema" in response schema objects mapper.addMixIn(Response.class, ResponseSchemaMixin.class); try { return new String(mapper.writeValueAsBytes(swaggerObj)); } catch (JsonProcessingException e) { throw new APIManagementException("Error while generating Swagger json from model", e); } }
Example #3
Source File: JaxrsReaderTest.java From swagger-maven-plugin with Apache License 2.0 | 6 votes |
@Test public void createCommonParameters() throws Exception { reader = new JaxrsReader(new Swagger(), Mockito.mock(Log.class)); Swagger result = reader.read(CommonParametersApi.class); Parameter headerParam = result.getParameter("headerParam"); assertTrue(headerParam instanceof HeaderParameter); Parameter queryParam = result.getParameter("queryParam"); assertTrue(queryParam instanceof QueryParameter); result = reader.read(ReferenceCommonParametersApi.class); Operation get = result.getPath("/apath").getGet(); List<Parameter> parameters = get.getParameters(); for (Parameter parameter : parameters) { assertTrue(parameter instanceof RefParameter); } ObjectMapper mapper = Json.mapper(); ObjectWriter jsonWriter = mapper.writer(new DefaultPrettyPrinter()); String json = jsonWriter.writeValueAsString(result); JsonNode expectJson = mapper.readTree(this.getClass().getResourceAsStream("/expectedOutput/swagger-common-parameters.json")); JsonAssert.assertJsonEquals(expectJson, json); }
Example #4
Source File: ProtoApiFromOpenApi.java From api-compiler with Apache License 2.0 | 5 votes |
/** * Ensures the parameters are all resolved and return just the list of parameters that are fully * resolved by the swagger core parser. */ private static ImmutableList<Parameter> getResolvedParameters( final DiagCollector diagCollector, ImmutableList<Parameter> parameters, final Location location) { ImmutableList<Parameter> resolvedParameters = FluentIterable.from(parameters) .filter( new Predicate<Parameter>() { @Override public boolean apply(Parameter parameter) { if (parameter instanceof RefParameter) { /* * This is an invalid state. Reference parameters should automatically get * resolved into parameter objects by the swagger core parser, because only * references that are allowed are to parameters that are defined at the * Swagger Object's parameters which are in the same file. If we reach here * it would mean the reference cannot be resolved and nothing this converter * can do. */ diagCollector.addDiag( Diag.warning( location, "Reference %s cannot be resolved", ((RefParameter) parameter).get$ref())); return false; } else { return true; } } }) .toList(); return resolvedParameters; }
Example #5
Source File: SwaggerConverter.java From swagger-parser with Apache License 2.0 | 5 votes |
private boolean isRefABodyParam(io.swagger.models.parameters.Parameter param) { if (param instanceof RefParameter) { RefParameter refParameter = (RefParameter) param; String simpleRef = refParameter.getSimpleRef(); io.swagger.models.parameters.Parameter parameter = globalV2Parameters.get(simpleRef); return "body".equals(parameter.getIn()); } return false; }
Example #6
Source File: SwaggerConverter.java From swagger-parser with Apache License 2.0 | 5 votes |
private boolean isRefAFormParam(io.swagger.models.parameters.Parameter param) { if (param instanceof RefParameter) { RefParameter refParameter = (RefParameter) param; String simpleRef = refParameter.getSimpleRef(); io.swagger.models.parameters.Parameter parameter = globalV2Parameters.get(simpleRef); return "formData".equals(parameter.getIn()); } return false; }
Example #7
Source File: SwaggerExtension.java From Web-API with MIT License | 4 votes |
@Override public void decorateOperation(Operation operation, Method method, Iterator<io.swagger.jaxrs.ext.SwaggerExtension> chain) { // Automatically add query params operation.addParameter(new RefParameter("details")); operation.addParameter(new RefParameter("accept")); operation.addParameter(new RefParameter("pretty")); // Automatically add 500 as a possible response operation.addResponse("500", new RefResponse("500")); // Automatically add error codes depending on thrown exceptions for (Class<?> execClass : method.getExceptionTypes()) { if (BadRequestException.class.isAssignableFrom(execClass)) { operation.addResponse("400", new RefResponse("400")); } if (NotFoundException.class.isAssignableFrom(execClass)) { operation.addResponse("404", new RefResponse("404")); } if (NotImplementedException.class.isAssignableFrom(execClass)) { operation.addResponse("501", new RefResponse("501")); } } Permission[] perms = method.getAnnotationsByType(Permission.class); if (perms.length > 0) { // Automatically add 401 & 403 as a possible response operation.addResponse("401", new RefResponse("401")); operation.addResponse("403", new RefResponse("403")); // Automatically add required permission notes if we have a @Permission annotation Path path = method.getDeclaringClass().getAnnotation(Path.class); String prefix = path != null ? path.value() + "." : ""; StringBuilder permStr = new StringBuilder(" \n\n **Required permissions:** \n\n"); for (Permission perm : perms) { permStr.append("- **").append(prefix).append(String.join(".", perm.value())).append("** \n"); } operation.setDescription(operation.getDescription() + permStr.toString()); // Add security definitions operation.addSecurity("ApiKeyHeader", new ArrayList<>()); operation.addSecurity("ApiKeyQuery", new ArrayList<>()); } super.decorateOperation(operation, method, chain); }