Java Code Examples for io.swagger.v3.oas.models.parameters.Parameter#getName()
The following examples show how to use
io.swagger.v3.oas.models.parameters.Parameter#getName() .
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: ParameterTransformer.java From swagger-brake with Apache License 2.0 | 6 votes |
@Override public RequestParameter transform(Parameter from) { RequestParameterInType inType = requestParameterInTypeResolver.resolve(from.getIn()); String name = from.getName(); boolean required = BooleanUtils.toBoolean(from.getRequired()); Schema swSchema = from.getSchema(); if (swSchema != null) { // Validation for detecting when a request parameter is used with an actual schema object // even though its forbidden by the spec // https://github.com/redskap/swagger-brake/issues/28 if (swSchema.getType() == null) { throw new IllegalStateException("schema does not have any type"); } return new RequestParameter(inType, name, required, schemaTransformer.transform(swSchema)); } return new RequestParameter(inType, name, required); }
Example 2
Source File: OASMergeUtil.java From crnk-framework with Apache License 2.0 | 6 votes |
public static Parameter mergeParameter(Parameter thisParameter, Parameter thatParameter) { if (thatParameter.getName() != null) { thisParameter.setName(thatParameter.getName()); } if (thatParameter.getIn() != null) { thisParameter.setIn(thatParameter.getIn()); } if (thatParameter.getDescription() != null) { thisParameter.setDescription(thatParameter.getDescription()); } if (thatParameter.getRequired() != null) { thisParameter.setRequired(thatParameter.getRequired()); } if (thatParameter.getDeprecated() != null) { thisParameter.setDeprecated(thatParameter.getDeprecated()); } if (thatParameter.getAllowEmptyValue() != null) { thisParameter.setAllowEmptyValue(thatParameter.getAllowEmptyValue()); } if (thatParameter.get$ref() != null) { thisParameter.set$ref(thatParameter.get$ref()); } return thisParameter; }
Example 3
Source File: OpenAPIV3ParserTest.java From swagger-parser with Apache License 2.0 | 6 votes |
@Test public void testIssue357() { OpenAPIV3Parser parser = new OpenAPIV3Parser(); final OpenAPI openAPI = parser.read("src/test/resources/issue_357.yaml"); assertNotNull(openAPI); List<Parameter> getParams = openAPI.getPaths().get("/testApi").getGet().getParameters(); assertEquals(2, getParams.size()); for (Parameter param : getParams) { switch (param.getName()) { case "pathParam1": assertEquals(param.getSchema().getType(), "integer"); break; case "pathParam2": assertEquals(param.getSchema().getType(), "string"); break; default: fail("Unexpected parameter named " + param.getName()); break; } } }
Example 4
Source File: OpenAPI3RequestValidationHandlerImpl.java From vertx-web with Apache License 2.0 | 6 votes |
private void magicParameterExplodedStyleSimpleTypeObject(Parameter parameter) { ObjectTypeValidator objectTypeValidator = ObjectTypeValidator.ObjectTypeValidatorFactory .createObjectTypeValidator(ContainerSerializationStyle.simple_exploded_object, false); this.resolveObjectTypeFields(objectTypeValidator, parameter.getSchema()); switch (parameter.getIn()) { case "path": this.addPathParamRule(ParameterValidationRuleImpl.ParameterValidationRuleFactory .createValidationRuleWithCustomTypeValidator(parameter.getName(), objectTypeValidator, !OpenApi3Utils .isRequiredParam(parameter), OpenApi3Utils.resolveAllowEmptyValue(parameter), ParameterLocation.PATH)); break; case "header": this.addHeaderParamRule(ParameterValidationRuleImpl.ParameterValidationRuleFactory .createValidationRuleWithCustomTypeValidator(parameter.getName(), objectTypeValidator, !OpenApi3Utils .isRequiredParam(parameter), OpenApi3Utils.resolveAllowEmptyValue(parameter), ParameterLocation.HEADER)); break; default: throw new SpecFeatureNotSupportedException("combination of style, type and location (in) of parameter fields " + "not supported for parameter " + parameter.getName()); } }
Example 5
Source File: GenericParameterBuilder.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Merge parameter parameter. * * @param existingParamDoc the existing param doc * @param paramCalcul the param calcul * @return the parameter */ public static Parameter mergeParameter(List<Parameter> existingParamDoc, Parameter paramCalcul) { Parameter result = paramCalcul; if (paramCalcul != null && paramCalcul.getName() != null) { final String name = paramCalcul.getName(); Parameter paramDoc = existingParamDoc.stream().filter(p -> name.equals(p.getName())).findAny().orElse(null); if (paramDoc != null) { mergeParameter(paramCalcul, paramDoc); result = paramDoc; } else existingParamDoc.add(result); } return result; }
Example 6
Source File: OpenApiParameterValidations.java From openapi-generator with Apache License 2.0 | 5 votes |
/** * Apache and Nginx default to legacy CGI behavior in which header with underscore are ignored. Raise this for awareness to the user. * * @param parameter Any spec doc parameter. The method will handle {@link HeaderParameter} evaluation. * @return {@link ValidationRule.Pass} if the check succeeds, otherwise {@link ValidationRule.Fail} with details "[key] contains an underscore." */ private static ValidationRule.Result apacheNginxHeaderCheck(ParameterWrapper parameterWrapper) { Parameter parameter = parameterWrapper.getParameter(); if (parameter == null || !parameter.getIn().equals("header")) return ValidationRule.Pass.empty(); ValidationRule.Result result = ValidationRule.Pass.empty(); String headerName = parameter.getName(); if (StringUtils.isNotEmpty(headerName) && StringUtils.contains(headerName, '_')) { result = new ValidationRule.Fail(); result.setDetails(String.format(Locale.ROOT, "%s contains an underscore.", headerName)); } return result; }
Example 7
Source File: BallerinaParameter.java From product-microgateway with Apache License 2.0 | 5 votes |
@Override public BallerinaParameter buildContext(Parameter parameter, ExtendedAPI api) throws BallerinaServiceGenException { this.name = parameter.getName(); this.in = parameter.getIn(); this.description = parameter.getDescription(); this.required = parameter.getRequired(); this.allowEmptyValue = parameter.getAllowEmptyValue(); return this; }
Example 8
Source File: InputModeller.java From tcases with MIT License | 5 votes |
/** * Returns the {@link IVarDef input variable definition} for the given parameter. */ private IVarDef parameterVarDef( OpenAPI api, Parameter parameter) { String parameterName = parameter.getName(); return resultFor( parameterName, () -> { String parameterIn = expectedValueOf( parameter.getIn(), "in", parameterName); if( parameterIn.equals( "cookie") && !Characters.TOKEN.allowed( parameterName)) { throw new IllegalStateException( String.format( "Parameter name='%s' contains characters not allowed in a cookie name", parameterName)); } String parameterVarName = toIdentifier( parameterName); Schema<?> parameterSchema = parameterSchema( api, parameter); String parameterType = parameterSchema.getType(); return VarSetBuilder.with( parameterVarName) .type( parameterIn) .has( "paramName", parameterName) .members( parameterDefinedVar( parameterVarName, parameterType, parameter)) .members( instanceSchemaVars( parameterVarName, parameterSchema)) .build(); }); }
Example 9
Source File: HeadersGenerator.java From zap-extensions with Apache License 2.0 | 5 votes |
private void generateCustomHeader(Operation operation, List<HttpHeaderField> headers) { if (operation.getParameters() != null) { for (Parameter parameter : operation.getParameters()) { if (parameter == null) { continue; } if (HEADER.equals(parameter.getIn())) { String name = parameter.getName(); String value = dataGenerator.generate(name, parameter); HttpHeaderField header = new HttpHeaderField(name, value); headers.add(header); } } } }
Example 10
Source File: OpenAPI3RequestValidationHandlerImpl.java From vertx-web with Apache License 2.0 | 5 votes |
private void magicParameterExplodedObject(Parameter parameter) { Map<String, OpenApi3Utils.ObjectField> properties = OpenApi3Utils.solveObjectParameters(parameter.getSchema()); for (Map.Entry<String, OpenApi3Utils.ObjectField> entry : properties.entrySet()) { if ("query".equals(parameter.getIn())) { this.addQueryParamRule(ParameterValidationRuleImpl.ParameterValidationRuleFactory .createValidationRuleWithCustomTypeValidator(entry.getKey(), new ExpandedObjectFieldValidator(this .resolveInnerSchemaPrimitiveTypeValidator(entry.getValue().getSchema(), true), parameter.getName(), entry.getKey()), !entry.getValue().isRequired(), OpenApi3Utils.resolveAllowEmptyValue(parameter), ParameterLocation.QUERY)); } else if ("cookie".equals(parameter.getIn())) { this.addCookieParamRule(ParameterValidationRuleImpl.ParameterValidationRuleFactory .createValidationRuleWithCustomTypeValidator(entry.getKey(), new ExpandedObjectFieldValidator(this .resolveInnerSchemaPrimitiveTypeValidator(entry.getValue().getSchema(), true), parameter.getName(), entry.getKey()), !entry.getValue().isRequired(), false, ParameterLocation.COOKIE)); } else if ("path".equals(parameter.getIn())) { this.addPathParamRule(ParameterValidationRuleImpl.ParameterValidationRuleFactory .createValidationRuleWithCustomTypeValidator(entry.getKey(), new ExpandedObjectFieldValidator(this .resolveInnerSchemaPrimitiveTypeValidator(entry.getValue().getSchema(), true), parameter.getName(), entry.getKey()), !entry.getValue().isRequired(), false, ParameterLocation.PATH)); } else { throw new SpecFeatureNotSupportedException("combination of style, type and location (in) of parameter fields " + "" + "not supported for parameter " + parameter.getName()); } } if (parameter.getSchema().getAdditionalProperties() instanceof Schema) { if ("query".equals(parameter.getIn())) { this.setQueryAdditionalPropertyHandler( this.resolveInnerSchemaPrimitiveTypeValidator((Schema)parameter.getSchema().getAdditionalProperties(), true), parameter.getName() ); } else if ("cookie".equals(parameter.getIn())) { this.setCookieAdditionalPropertyHandler( this.resolveInnerSchemaPrimitiveTypeValidator((Schema)parameter.getSchema().getAdditionalProperties(), true), parameter.getName() ); } else { throw new SpecFeatureNotSupportedException("additionalProperties with exploded object fields not supports in path parameter " + parameter.getName()); } } }
Example 11
Source File: OpenAPI3RequestValidationHandlerImpl.java From vertx-web with Apache License 2.0 | 5 votes |
private void magicParameterExplodedStyleDeepObjectTypeObject(Parameter parameter) { Map<String, OpenApi3Utils.ObjectField> properties = OpenApi3Utils.solveObjectParameters(parameter.getSchema()); for (Map.Entry<String, OpenApi3Utils.ObjectField> entry : properties.entrySet()) { if (parameter.getIn().equals("query")) { this.addQueryParamRule(ParameterValidationRuleImpl.ParameterValidationRuleFactory .createValidationRuleWithCustomTypeValidator(parameter.getName() + "[" + entry.getKey() + "]", new ExpandedObjectFieldValidator(this .resolveInnerSchemaPrimitiveTypeValidator(entry.getValue().getSchema(), true), parameter.getName(), entry.getKey()), !entry.getValue().isRequired(), OpenApi3Utils.resolveAllowEmptyValue(parameter), ParameterLocation.QUERY)); } else { throw new SpecFeatureNotSupportedException("combination of style, type and location (in) of parameter fields " + "" + "not supported for parameter " + parameter.getName()); } } }
Example 12
Source File: PythonAbstractConnexionServerCodegen.java From openapi-generator with Apache License 2.0 | 4 votes |
@Override public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) { // XXX - Revert the original parameter (and path) names to make sure we have // a consistent REST interface across other server/client languages: // // XXX - Reverts `x-python-connexion-openapi-name` back to the original (query/path) parameter name. // We do not want to have our REST API itself being converted to pythonic params. // This would be incompatible with other server implementations. OpenAPI openAPI = (OpenAPI) objs.get("openAPI"); Map<String, PathItem> paths = openAPI.getPaths(); if (paths != null) { List<String> pathnames = new ArrayList(paths.keySet()); for (String pythonPathname : pathnames) { PathItem path = paths.get(pythonPathname); // Fix path parameters back to original casing Map<String, Object> pathExtensions = path.getExtensions(); if (pathExtensions != null) { // Get and remove the (temporary) vendor extension String openapiPathname = (String) pathExtensions.remove("x-python-connexion-openapi-name"); if (openapiPathname != null && !openapiPathname.equals(pythonPathname)) { LOGGER.info("Path '" + pythonPathname + "' is not consistant with the original OpenAPI definition. It will be replaced back by '" + openapiPathname + "'"); paths.remove(pythonPathname); paths.put(openapiPathname, path); } } Map<HttpMethod, Operation> operationMap = path.readOperationsMap(); if (operationMap != null) { for (HttpMethod method : operationMap.keySet()) { Operation operation = operationMap.get(method); if (operation.getParameters() != null) { for (Parameter parameter : operation.getParameters()) { Map<String, Object> parameterExtensions = parameter.getExtensions(); if (parameterExtensions != null) { // Get and remove the (temporary) vendor extension String swaggerParameterName = (String) parameterExtensions.remove("x-python-connexion-openapi-name"); if (swaggerParameterName != null) { String pythonParameterName = parameter.getName(); if (!swaggerParameterName.equals(pythonParameterName)) { LOGGER.info("Reverting name of parameter '" + pythonParameterName + "' of operation '" + operation.getOperationId() + "' back to '" + swaggerParameterName + "'"); parameter.setName(swaggerParameterName); } else { LOGGER.debug("Name of parameter '" + pythonParameterName + "' of operation '" + operation.getOperationId() + "' was unchanged."); } } else { LOGGER.debug("x-python-connexion-openapi-name was not set on parameter '" + parameter.getName() + "' of operation '" + operation.getOperationId() + "'"); } } } } } } } // Sort path names after variable name fix List<String> recoveredPathnames = new ArrayList(paths.keySet()); Collections.sort(recoveredPathnames); for (String pathname : recoveredPathnames) { PathItem pathItem = paths.remove(pathname); paths.put(pathname, pathItem); } } generateJSONSpecFile(objs); generateYAMLSpecFile(objs); for (Map<String, Object> operations : getOperations(objs)) { @SuppressWarnings("unchecked") List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation"); List<Map<String, Object>> opsByPathList = sortOperationsByPath(ops); operations.put("operationsByPath", opsByPathList); } return super.postProcessSupportingFileData(objs); }
Example 13
Source File: DefaultGenerator.java From openapi-generator with Apache License 2.0 | 4 votes |
private static String generateParameterId(Parameter parameter) { return parameter.getName() + ":" + parameter.getIn(); }
Example 14
Source File: AbstractRequestBuilder.java From springdoc-openapi with Apache License 2.0 | 2 votes |
/** * Is valid parameter boolean. * * @param parameter the parameter * @return the boolean */ public boolean isValidParameter(Parameter parameter) { return parameter != null && (parameter.getName() != null || parameter.get$ref() != null); }