Java Code Examples for io.swagger.v3.oas.models.media.Schema#getRequired()
The following examples show how to use
io.swagger.v3.oas.models.media.Schema#getRequired() .
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: VaadinConnectTsGenerator.java From flow with Apache License 2.0 | 6 votes |
private List<ParameterInformation> getParamsList(Schema requestSchema) { Map<String, Schema> properties = requestSchema.getProperties(); List<ParameterInformation> paramsList = new ArrayList<>(); List<String> requiredParams = requestSchema.getRequired() != null ? requestSchema.getRequired() : Collections.emptyList(); for (Map.Entry<String, Schema> entry : properties.entrySet()) { String name = entry.getKey(); boolean isRequired = requiredParams.contains(name); name = isReservedWord(name) ? escapeReservedWord(name) : name; String type = getTypeDeclaration(entry.getValue()); String description = entry.getValue().getDescription(); if (GeneratorUtils.isBlank(description)) { description = getDescriptionFromParameterExtension(name, requestSchema); } ParameterInformation parameterInformation = new ParameterInformation( name, isRequired, type, description); paramsList.add(parameterInformation); } return paramsList; }
Example 2
Source File: AbstractEndpointGenerationTest.java From flow with Apache License 2.0 | 6 votes |
private void assertRequestSchema(Schema requestSchema, Class<?>[] parameterTypes, Parameter[] parameters) { Map<String, Schema> properties = requestSchema.getProperties(); assertEquals( "Request schema should have the same amount of properties as the corresponding endpoint method parameters number", parameterTypes.length, properties.size()); int index = 0; for (Map.Entry<String, Schema> stringSchemaEntry : properties .entrySet()) { assertSchema(stringSchemaEntry.getValue(), parameterTypes[index]); List requiredList = requestSchema.getRequired(); if (parameters[index].isAnnotationPresent(Nullable.class) || Optional.class.isAssignableFrom(parameters[index].getType())) { boolean notRequired = requiredList == null || !requiredList.contains(stringSchemaEntry.getKey()); assertTrue("@Nullable or Optional request parameter " + "should not be required", notRequired); } else { assertTrue(requiredList.contains(stringSchemaEntry.getKey())); } index++; } }
Example 3
Source File: ComponentSchemaTransformer.java From spring-openapi with MIT License | 5 votes |
private void updateRequiredFields(Schema schema, List<String> requiredFields) { if (requiredFields == null || requiredFields.isEmpty()) { return; } if (schema.getRequired() == null) { schema.setRequired(requiredFields); return; } schema.getRequired().addAll(requiredFields); }
Example 4
Source File: AbstractEndpointGenerationTest.java From flow with Apache License 2.0 | 5 votes |
private void assertSchemaProperties(Class<?> expectedSchemaClass, Schema schema) { int expectedFieldsCount = 0; Map<String, Schema> properties = schema.getProperties(); assertNotNull(properties); assertTrue(properties.size() > 0); for (Field expectedSchemaField : expectedSchemaClass .getDeclaredFields()) { if (Modifier.isTransient(expectedSchemaField.getModifiers()) || Modifier.isStatic(expectedSchemaField.getModifiers()) || expectedSchemaField .isAnnotationPresent(JsonIgnore.class)) { continue; } expectedFieldsCount++; Schema propertySchema = properties .get(expectedSchemaField.getName()); assertNotNull(String.format("Property schema is not found %s", expectedSchemaField.getName()), propertySchema); assertSchema(propertySchema, expectedSchemaField.getType()); if (Optional.class .isAssignableFrom(expectedSchemaField.getType()) || expectedSchemaField.isAnnotationPresent(Nullable.class)) { boolean notRequired = schema.getRequired() == null || !schema.getRequired() .contains(expectedSchemaField.getName()); assertTrue(notRequired); } else { assertTrue(schema.getRequired() .contains(expectedSchemaField.getName())); } } assertEquals(expectedFieldsCount, properties.size()); }
Example 5
Source File: V2ConverterTest.java From swagger-parser with Apache License 2.0 | 5 votes |
@Test(description = "OpenAPI v2 converter - required Form parameters are converted as optional ") public void testIssue600() throws Exception { OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_600_JSON); RequestBody requestBody = oas.getPaths().get(LOGIN_PATH).getPost().getRequestBody(); assertNotNull(requestBody); assertTrue(requestBody.getRequired()); Schema schema = requestBody.getContent().get(CONTENT_TYPE).getSchema(); List required = schema.getRequired(); assertNotNull(required); assertEquals(required.size(), REQUIRED_SIZE); }
Example 6
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; }
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; } }
Example 8
Source File: OpenApi3Utils.java From vertx-web with Apache License 2.0 | 4 votes |
public static boolean isRequiredParam(Schema schema, String parameterName) { return schema != null && schema.getRequired() != null && schema.getRequired().contains(parameterName); }
Example 9
Source File: OpenApi3Utils.java From vertx-web with Apache License 2.0 | 4 votes |
public ObjectField(Schema schema, String name, Schema superSchema) { this.schema = schema; this.required = superSchema.getRequired() != null && superSchema.getRequired().contains(name); }