本文整理了Java中io.swagger.v3.oas.models.OpenAPI.getComponents()
方法的一些代码示例,展示了OpenAPI.getComponents()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OpenAPI.getComponents()
方法的具体详情如下:
包路径:io.swagger.v3.oas.models.OpenAPI
类名称:OpenAPI
方法名:getComponents
[英]returns the components property from a OpenAPI instance.
[中]从OpenAPI实例返回components属性。
代码示例来源:origin: swagger-api/swagger-core
@Override
public void setConfiguration(OpenAPIConfiguration openApiConfiguration) {
if (openApiConfiguration != null) {
this.config = ContextUtils.deepCopy(openApiConfiguration);
if (openApiConfiguration.getOpenAPI() != null) {
this.openAPI = this.config.getOpenAPI();
if (this.openAPI.getComponents() != null) {
this.components = this.openAPI.getComponents();
}
}
}
}
代码示例来源:origin: swagger-api/swagger-core
protected void locateReferencedDefinitions(String ref, Set<String> nestedReferencedDefinitions, OpenAPI openAPI) {
// if not already processed so as to avoid infinite loops
if (!nestedReferencedDefinitions.contains(ref)) {
nestedReferencedDefinitions.add(ref);
String simpleName = (String) RefUtils.extractSimpleName(ref).getLeft();
Schema model = openAPI.getComponents().getSchemas().get(simpleName);
if (model != null) {
addSchemaRef(model, nestedReferencedDefinitions);
}
}
}
}
代码示例来源:origin: swagger-api/swagger-core
protected OpenAPI removeBrokenReferenceDefinitions(OpenAPI openApi) {
if (openApi == null || openApi.getComponents() == null || openApi.getComponents().getSchemas() == null) {
return openApi;
}
Set<String> referencedDefinitions = new TreeSet<>();
if (openApi.getPaths() != null) {
for (String resourcePath : openApi.getPaths().keySet()) {
PathItem pathItem = openApi.getPaths().get(resourcePath);
addPathItemSchemaRef(pathItem, referencedDefinitions);
}
}
Set<String> nestedReferencedDefinitions = new TreeSet<>();
for (String ref : referencedDefinitions) {
locateReferencedDefinitions(ref, nestedReferencedDefinitions, openApi);
}
referencedDefinitions.addAll(nestedReferencedDefinitions);
openApi.getComponents().getSchemas().keySet().retainAll(referencedDefinitions.stream().map(s -> (String) RefUtils.extractSimpleName(s).getLeft()).collect(Collectors.toSet()));
return openApi;
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void shouldNotRemoveGoodRefs() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
assertNotNull(openAPI.getComponents().getSchemas().get("PetHeader"));
final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
assertNotNull(filtered.getComponents().getSchemas().get("PetHeader"));
assertNotNull(filtered.getComponents().getSchemas().get("Category"));
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "recursive models, e.g. A-> A or A-> B and B -> A should not result in stack overflow")
public void removeUnreferencedDefinitionsOfRecuriveModels() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_RECURSIVE_MODELS);
final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
assertNotNull(filtered.getComponents().getSchemas().get("SelfReferencingModel"));
assertNotNull(filtered.getComponents().getSchemas().get("IndirectRecursiveModelA"));
assertNotNull(filtered.getComponents().getSchemas().get("IndirectRecursiveModelB"));
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should retain non-broken reference model composed properties")
public void retainNonBrokenReferenceModelComposedProperties() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_REFERRED_SCHEMAS);
assertNotNull(openAPI.getComponents().getSchemas().get("User"));
final NoOpOperationsFilter noOperationsFilter = new NoOpOperationsFilter();
OpenAPI filtered = new SpecFilter().filter(openAPI, noOperationsFilter, null, null, null);
assertNotNull(filtered.getComponents().getSchemas().get("User"));
final RemoveUnreferencedDefinitionsFilter refFilter = new RemoveUnreferencedDefinitionsFilter();
filtered = new SpecFilter().filter(openAPI, refFilter, null, null, null);
assertNotNull(filtered.getComponents().getSchemas().get("User"));
assertNotNull(filtered.getComponents().getSchemas().get("Pet"));
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should deserialize the composition test")
public void testCompositionTest() throws IOException {
final String json = ResourceUtils.loadClassResource(getClass(), "specFiles/compositionTest-3.0.json");
final Object deserialized = m.readValue(json, OpenAPI.class);
assertTrue(deserialized instanceof OpenAPI);
OpenAPI openAPI = (OpenAPI) deserialized;
Schema lizardSchema = openAPI.getComponents().getSchemas().get("Lizard");
assertTrue(lizardSchema instanceof ComposedSchema);
assertEquals(((ComposedSchema) lizardSchema).getAllOf().size(), 2);
Schema petSchema = openAPI.getComponents().getSchemas().get("Pet");
assertEquals(petSchema.getDiscriminator().getPropertyName(), "pet_type");
assertEquals(petSchema.getDiscriminator().getMapping().get("cachorro"), "#/components/schemas/Dog");
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "should deserialize a string property with constraints")
public void testDeserializeConstrainedStringProperty() throws Exception {
OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/propertiesWithConstraints.json", OpenAPI.class);
StringSchema property = (StringSchema) oas.getComponents().getSchemas().get("Health").getProperties().get("string_with_constraints");
assertEquals(property.getMinLength(), Integer.valueOf(10));
assertEquals(property.getMaxLength(), Integer.valueOf(100));
assertEquals(property.getPattern(), "apattern");
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "Retain models referenced from additonalProperties")
public void retainModelsReferencesFromAdditionalProperties() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_REFERRED_SCHEMAS);
final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
assertNotNull(filtered.getComponents().getSchemas().get("Order"));
assertNotNull(filtered.getComponents().getSchemas().get("ReferredOrder"));
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void shouldRemoveBrokenRefs() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
openAPI.getPaths().get("/pet/{petId}").getGet().getResponses().getDefault().getHeaders().remove("X-Rate-Limit-Limit");
assertNotNull(openAPI.getComponents().getSchemas().get("PetHeader"));
final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
assertNull(filtered.getComponents().getSchemas().get("PetHeader"));
assertNotNull(filtered.getComponents().getSchemas().get("Category"));
assertNotNull(filtered.getComponents().getSchemas().get("Pet"));
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should filter away internal model properties")
public void filterAwayInternalModelProperties() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
final InternalModelPropertiesRemoverFilter filter = new InternalModelPropertiesRemoverFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
for (Map.Entry<String, Schema> entry : filtered.getComponents().getSchemas().entrySet()) {
for (String propName : (Set<String>) entry.getValue().getProperties().keySet()) {
assertFalse(propName.startsWith("_"));
}
}
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "should deserialize a property with vendor extensions of different types")
public void testDeserializePropertyWithVendorExtensions() throws Exception {
OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/propertyWithVendorExtensions.json", OpenAPI.class);
Map<String, Object> oasVendorExtensions = oas.getExtensions();
Map<String, Object> vendorExtensions = ((Schema) oas.getComponents().getSchemas().get("Health").getProperties().get("status")).getExtensions();
assertVendorExtensions(oasVendorExtensions);
assertVendorExtensions(vendorExtensions);
//check for vendor extensions in array property types
vendorExtensions = ((Schema) oas.getComponents().getSchemas().get("Health").getProperties().get("array")).getExtensions();
String xStringValue = (String) vendorExtensions.get("x-string-value");
assertNotNull(xStringValue);
assertEquals(xStringValue, "string_value");
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "broken references should not result in NPE")
public void removeUnreferencedModelOverride() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_REFERRED_SCHEMAS);
final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
assertNotNull(filtered.getComponents().getSchemas().get("Order"));
}
代码示例来源:origin: swagger-api/swagger-core
if (filteredOpenAPI.getComponents() != null) {
clone.components(new Components());
clone.getComponents().setSchemas(filterComponentsSchema(filter, filteredOpenAPI.getComponents().getSchemas(), params, cookies, headers));
clone.getComponents().setSecuritySchemes(filteredOpenAPI.getComponents().getSecuritySchemes());
clone.getComponents().setCallbacks(filteredOpenAPI.getComponents().getCallbacks());
clone.getComponents().setExamples(filteredOpenAPI.getComponents().getExamples());
clone.getComponents().setExtensions(filteredOpenAPI.getComponents().getExtensions());
clone.getComponents().setHeaders(filteredOpenAPI.getComponents().getHeaders());
clone.getComponents().setLinks(filteredOpenAPI.getComponents().getLinks());
clone.getComponents().setParameters(filteredOpenAPI.getComponents().getParameters());
clone.getComponents().setRequestBodies(filteredOpenAPI.getComponents().getRequestBodies());
clone.getComponents().setResponses(filteredOpenAPI.getComponents().getResponses());
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "should deserialize an array property with constraints")
public void testDeserializeConstrainedArrayProperties() throws Exception {
OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/propertiesWithConstraints.json", OpenAPI.class);
Map<String, Schema> properties = oas.getComponents().getSchemas().get("Health").getProperties();
ArraySchema withMin = (ArraySchema) properties.get("array_with_min");
assertEquals(withMin.getMinItems(), Integer.valueOf(5));
assertNull(withMin.getMaxItems());
assertNull(withMin.getUniqueItems());
ArraySchema withMax = (ArraySchema) properties.get("array_with_max");
assertNull(withMax.getMinItems());
assertEquals(withMax.getMaxItems(), Integer.valueOf(10));
assertNull(withMax.getUniqueItems());
ArraySchema withUnique = (ArraySchema) properties.get("array_with_unique");
assertNull(withUnique.getMinItems());
assertNull(withUnique.getMaxItems());
assertEquals(withUnique.getUniqueItems(), Boolean.TRUE);
ArraySchema withAll = (ArraySchema) properties.get("array_with_all");
assertEquals(withAll.getMinItems(), Integer.valueOf(1));
assertEquals(withAll.getMaxItems(), Integer.valueOf(10));
assertEquals(withAll.getUniqueItems(), Boolean.TRUE);
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should filter with null definitions")
public void filterWithNullDefinitions() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
openAPI.getComponents().setSchemas(null);
final InternalModelPropertiesRemoverFilter filter = new InternalModelPropertiesRemoverFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
assertNotNull(filtered);
}
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should filter any Pet Ref in Schemas")
public void filterAwayPetRefInSchemas() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
final OpenAPI filtered = new SpecFilter().filter(openAPI, new NoPetRefSchemaFilter(), null, null, null);
validateSchemasInComponents(filtered.getComponents(), PET_MODEL);
}
代码示例来源:origin: swagger-api/swagger-core
assertEquals(security.size(), 3);
final Map<String, SecurityScheme> securitySchemes = swagger.getComponents().getSecuritySchemes();
assertNotNull(securitySchemes);
assertEquals(securitySchemes.size(), 4);
代码示例来源:origin: swagger-api/swagger-core
if (!isEmptyComponents(components) && openAPI.getComponents() == null) {
openAPI.setComponents(components);
代码示例来源:origin: io.swagger/swagger-codegen-generators
protected Parameter getParameterFromRef(String ref, OpenAPI openAPI) {
String parameterName = ref.substring(ref.lastIndexOf('/') + 1);
Map<String, Parameter> parameterMap = openAPI.getComponents().getParameters();
return parameterMap.get(parameterName);
}
内容来源于网络,如有侵权,请联系作者删除!