Java Code Examples for io.swagger.v3.oas.models.media.Schema#getTitle()
The following examples show how to use
io.swagger.v3.oas.models.media.Schema#getTitle() .
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: OpenApiSchemaValidations.java From openapi-generator with Apache License 2.0 | 6 votes |
/** * JSON Schema specifies type: 'null'. * <p> * 'null' type is supported in OpenAPI Specification 3.1 and above. It is not supported in OpenAPI 3.0.x. * Note: the validator invokes checkNullType() for every top-level schema in the OAS document. The method * is not called for nested schemas that are defined inline. * * @param schema An input schema, regardless of the type of schema. * @return {@link ValidationRule.Pass} if the check succeeds, otherwise {@link ValidationRule.Fail} */ private static ValidationRule.Result checkNullType(SchemaWrapper schemaWrapper) { Schema schema = schemaWrapper.getSchema(); ValidationRule.Result result = ValidationRule.Pass.empty(); if (schemaWrapper.getOpenAPI() != null) { SemVer version = new SemVer(schemaWrapper.getOpenAPI().getOpenapi()); if (version.atLeast("3.0") && version.compareTo(new SemVer("3.1")) < 0) { // OAS spec is 3.0.x if (ModelUtils.isNullType(schema)) { result = new ValidationRule.Fail(); String name = schema.getName(); if (name == null) { name = schema.getTitle(); } result.setDetails(String.format(Locale.ROOT, "Schema '%s' uses a 'null' type, which is specified in OAS 3.1 and above, but OAS document is version %s", name, schemaWrapper.getOpenAPI().getOpenapi())); return result; } } } return result; }
Example 2
Source File: OpenApiSchemaValidations.java From openapi-generator with Apache License 2.0 | 6 votes |
/** * JSON Schema uses the 'nullable' attribute. * <p> * The 'nullable' attribute is supported in OpenAPI Specification 3.0.x, but it is deprecated in OpenAPI 3.1 and above. * * @param schema An input schema, regardless of the type of schema * @return {@link ValidationRule.Pass} if the check succeeds, otherwise {@link ValidationRule.Fail} */ private static ValidationRule.Result checkNullableAttribute(SchemaWrapper schemaWrapper) { Schema schema = schemaWrapper.getSchema(); ValidationRule.Result result = ValidationRule.Pass.empty(); if (schemaWrapper.getOpenAPI() != null) { SemVer version = new SemVer(schemaWrapper.getOpenAPI().getOpenapi()); if (version.atLeast("3.1")) { if (ModelUtils.isNullable(schema)) { result = new ValidationRule.Fail(); String name = schema.getName(); if (name == null) { name = schema.getTitle(); } result.setDetails(String.format(Locale.ROOT, "OAS document is version '%s'. Schema '%s' uses 'nullable' attribute, which has been deprecated in OAS 3.1.", schemaWrapper.getOpenAPI().getOpenapi(), name)); return result; } } } return result; }
Example 3
Source File: OpenApiSchemaValidations.java From openapi-generator with Apache License 2.0 | 6 votes |
/** * Validate the OAS document uses supported values for the 'type' attribute. * <p> * The type must be one of the following values: null, boolean, object, array, number, string, integer. * * @param schema An input schema, regardless of the type of schema * @return {@link ValidationRule.Pass} if the check succeeds, otherwise {@link ValidationRule.Fail} */ private static ValidationRule.Result checkInvalidType(SchemaWrapper schemaWrapper) { Schema schema = schemaWrapper.getSchema(); ValidationRule.Result result = ValidationRule.Pass.empty(); if (schema.getType() != null && !validTypes.contains(schema.getType())) { result = new ValidationRule.Fail(); String name = schema.getName(); if (name == null) { name = schema.getTitle(); } result.setDetails(String.format(Locale.ROOT, "Schema '%s' uses the '%s' type, which is not a valid type.", name, schema.getType())); return result; } return result; }
Example 4
Source File: CLibcurlClientCodegen.java From openapi-generator with Apache License 2.0 | 4 votes |
@Override public String toExampleValue(Schema schema) { String example = super.toExampleValue(schema); if (ModelUtils.isNullType(schema) && null != example) { // The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x, // though this tooling supports it. return "NULL"; } // correct "'"s into "'"s after toString() if (ModelUtils.isStringSchema(schema) && schema.getDefault() != null) { example = (String) schema.getDefault(); } if (StringUtils.isNotBlank(example) && !"null".equals(example)) { if (ModelUtils.isStringSchema(schema)) { example = "\"" + example + "\""; } return example; } if (schema.getEnum() != null && !schema.getEnum().isEmpty()) { // Enum case: example = schema.getEnum().get(0).toString(); /* if (ModelUtils.isStringSchema(schema)) { example = "'" + escapeText(example) + "'"; }*/ if (null == example) LOGGER.warn("Empty enum. Cannot built an example!"); return example; } else if (null != schema.get$ref()) { // $ref case: Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI); String ref = ModelUtils.getSimpleRef(schema.get$ref()); if (allDefinitions != null) { Schema refSchema = allDefinitions.get(ref); if (null == refSchema) { return "None"; } else { String refTitle = refSchema.getTitle(); if (StringUtils.isBlank(refTitle) || "null".equals(refTitle)) { refSchema.setTitle(ref); } return toExampleValue(refSchema); } } else { LOGGER.warn("allDefinitions not defined in toExampleValue!\n"); } } if (ModelUtils.isDateSchema(schema)) { example = "\"2013-10-20\""; return example; } else if (ModelUtils.isDateTimeSchema(schema)) { example = "\"2013-10-20T19:20:30+01:00\""; return example; } else if (ModelUtils.isBinarySchema(schema)) { example = "instantiate_binary_t(\"blah\", 5)"; return example; } else if (ModelUtils.isByteArraySchema(schema)) { example = "YQ=="; } else if (ModelUtils.isStringSchema(schema)) { // a BigDecimal: if ("Number".equalsIgnoreCase(schema.getFormat())) {return "1";} if (StringUtils.isNotBlank(schema.getPattern())) return "\"a\""; // I cheat here, since it would be too complicated to generate a string from a regexp int len = 0; if (null != schema.getMinLength()) len = schema.getMinLength().intValue(); if (len < 1) len = 1; example = ""; for (int i=0;i<len;i++) example += i; } else if (ModelUtils.isIntegerSchema(schema)) { if (schema.getMinimum() != null) example = schema.getMinimum().toString(); else example = "56"; } else if (ModelUtils.isNumberSchema(schema)) { if (schema.getMinimum() != null) example = schema.getMinimum().toString(); else example = "1.337"; } else if (ModelUtils.isBooleanSchema(schema)) { example = "1"; } else if (ModelUtils.isArraySchema(schema)) { example = "list_create()"; } else if (ModelUtils.isMapSchema(schema)) { example = "list_create()"; } else if (ModelUtils.isObjectSchema(schema)) { return null; // models are managed at moustache level } else { LOGGER.warn("Type " + schema.getType() + " not handled properly in toExampleValue"); } if (ModelUtils.isStringSchema(schema)) { example = "\"" + escapeText(example) + "\""; } return example; }
Example 5
Source File: OASMergeUtil.java From crnk-framework with Apache License 2.0 | 4 votes |
public static Schema mergeSchema(Schema thisSchema, Schema thatSchema) { if (thatSchema == null) { return thisSchema; } // Overwriting `implementation` is explicitly disallowed // Overwriting `not` is explicitly disallowed // Overwriting `oneOf` is explicitly disallowed // Overwriting `anyOf` is explicitly disallowed // Overwriting `allOf` is explicitly disallowed // Overwriting `name` is explicitly disallowed if (thatSchema.getTitle() != null) { thisSchema.setTitle(thatSchema.getTitle()); } // Overwriting `multipleOf` is explicitly disallowed if (thatSchema.getMaximum() != null) { thisSchema.setMaximum(thatSchema.getMaximum()); } if (thatSchema.getExclusiveMaximum() != null) { thisSchema.setExclusiveMaximum(thatSchema.getExclusiveMaximum()); } if (thatSchema.getMinimum() != null) { thisSchema.setMinimum(thatSchema.getMinimum()); } if (thatSchema.getExclusiveMinimum() != null) { thisSchema.setExclusiveMinimum(thatSchema.getExclusiveMinimum()); } if (thatSchema.getMaxLength() != null) { thisSchema.setMaxLength(thatSchema.getMaxLength()); } if (thatSchema.getMinLength() != null) { thisSchema.setMinLength(thatSchema.getMinLength()); } if (thatSchema.getPattern() != null) { thisSchema.setPattern(thatSchema.getPattern()); } if (thatSchema.getMaxProperties() != null) { thisSchema.setMaxProperties(thatSchema.getMaxProperties()); } if (thatSchema.getMinProperties() != null) { thisSchema.setMinProperties(thatSchema.getMinProperties()); } // RequiredProperties if (thatSchema.getRequired() != null) { thisSchema.setRequired(thatSchema.getRequired()); } // Overwriting `name` is explicitly disallowed if (thatSchema.getDescription() != null) { thisSchema.setDescription(thatSchema.getDescription()); } if (thatSchema.getFormat() != null) { thisSchema.setFormat(thatSchema.getFormat()); } // Overwriting `ref` is explicitly disallowed if (thatSchema.getNullable() != null) { thisSchema.setNullable(thatSchema.getNullable()); } // Overwriting `AccessMode` is explicitly disallowed if (thatSchema.getExample() != null) { thisSchema.setExample(thatSchema.getExample()); } if (thatSchema.getExternalDocs() != null) { thisSchema.setExternalDocs(thatSchema.getExternalDocs()); } if (thatSchema.getDeprecated() != null) { thisSchema.setDeprecated(thatSchema.getDeprecated()); } if (thatSchema.getType() != null) { thisSchema.setType(thatSchema.getType()); } if (thatSchema.getEnum() != null) { thisSchema.setEnum(thatSchema.getEnum()); } if (thatSchema.getDefault() != null) { thisSchema.setDefault(thatSchema.getDefault()); } // Overwriting `discriminator` is explicitly disallowed // Overwriting `hidden` is explicitly disallowed // Overwriting `subTypes` is explicitly disallowed if (thatSchema.getExtensions() != null) { thisSchema.setExtensions(thatSchema.getExtensions()); } return thisSchema; }