Java Code Examples for io.swagger.v3.oas.models.media.Schema#getName()
The following examples show how to use
io.swagger.v3.oas.models.media.Schema#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: 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: ModelConverter.java From servicecomb-toolkit with Apache License 2.0 | 5 votes |
private static void ensureSchemaNameExist(Schema schema) { if (schema.getName() != null) { return; } if (schema.get$ref() != null) { schema.setName((String) RefUtils.extractSimpleName(schema.get$ref()).getKey()); return; } }
Example 5
Source File: ClientGeneratorUtils.java From spring-openapi with MIT License | 5 votes |
public static String determineParentClassName(String childClassToFind, Map<String, Schema> allComponents) { Schema childClass = allComponents.get(childClassToFind); if (childClass instanceof ComposedSchema) { ComposedSchema childClassComposed = (ComposedSchema) childClass; if (CollectionUtils.isNotEmpty(childClassComposed.getAllOf())) { String parentClassRef = childClassComposed.getAllOf().get(0).get$ref(); if (parentClassRef == null) { throw new IllegalArgumentException("Unsupported inheritance model. AllOf $ref for parent class has to be defined"); } return getNameFromRef(parentClassRef); } } throw new IllegalArgumentException("Unsupported inheritance model for " + (childClass == null ? "null" : childClass.getName())); }
Example 6
Source File: ModelConverter.java From servicecomb-toolkit with Apache License 2.0 | 4 votes |
public static boolean shouldExtractRef(Schema schema) { if (schema.getName() != null || schema.get$ref() != null) { return true; } return false; }
Example 7
Source File: InlineModelResolver.java From swagger-parser with Apache License 2.0 | 4 votes |
public Schema createModelFromProperty(Schema schema, String path) { String description = schema.getDescription(); String example = null; List<String> requiredList = schema.getRequired(); Object obj = schema.getExample(); if (obj != null) { example = obj.toString(); } String name = schema.getName(); XML xml = schema.getXml(); Map<String, Schema> properties = schema.getProperties(); if (schema instanceof ComposedSchema && this.flattenComposedSchemas){ ComposedSchema composedModel = (ComposedSchema) schema; composedModel.setDescription(description); composedModel.setExample(example); composedModel.setName(name); composedModel.setXml(xml); composedModel.setType(schema.getType()); composedModel.setRequired(requiredList); return composedModel; } else { Schema model = new Schema();//TODO Verify this! model.setDescription(description); model.setExample(example); model.setName(name); model.setXml(xml); model.setType(schema.getType()); model.setRequired(requiredList); if (properties != null) { flattenProperties(properties, path); model.setProperties(properties); } return model; } }