Java Code Examples for io.swagger.v3.oas.models.media.ComposedSchema#getAnyOf()

The following examples show how to use io.swagger.v3.oas.models.media.ComposedSchema#getAnyOf() . 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: BodyGenerator.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
private static Schema<?> resolveComposedSchema(ComposedSchema schema) {

        if (schema.getOneOf() != null) {
            return schema.getOneOf().get(0);
        } else if (schema.getAnyOf() != null) {
            return schema.getAnyOf().get(0);
        }
        // Should not be reached, allOf schema is resolved by the parser
        LOG.error("Unknown composed schema type: " + schema);
        return null;
    }
 
Example 2
Source File: InlineModelResolver.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
private void flattenComposedSchema(Schema inner, String key) {

        ComposedSchema composedSchema = (ComposedSchema) inner;
        String inlineModelName = "";

        List<Schema> list = null;
        if (composedSchema.getAllOf() != null) {
            list  = composedSchema.getAllOf();
            inlineModelName = "AllOf";
        }else if (composedSchema.getAnyOf() != null) {
            list  = composedSchema.getAnyOf();
            inlineModelName = "AnyOf";
        }else if (composedSchema.getOneOf() != null) {
            list  = composedSchema.getOneOf();
            inlineModelName = "OneOf";
        }

        for(int i= 0; i<list.size();i++){
            if (list.get(i).get$ref() == null){
                Schema inline = list.get(i);
                if (inline.getProperties()!= null){
                    flattenProperties(inline.getProperties(), key);
                }
                if (this.flattenComposedSchemas) {
                    int position = i+1;
                    inlineModelName = resolveModelName(inline.getTitle(),  key + inlineModelName + "_" + position);
                    list.set(i,new Schema().$ref(inlineModelName));
                    addGenerated(inlineModelName, inline);
                    openAPI.getComponents().addSchemas(inlineModelName, inline);
                }
            }
        }
    }
 
Example 3
Source File: OpenAPIDeserializerTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test
public void testAnyOfSchema(@Injectable List<AuthorizationValue> auths){
    String yaml = "openapi: '3.0'\n" +
        "components:\n" +
        "  schemas:\n" +
        "    id:\n" +
        "      anyOf: \n" +
        "       - type: string\n" +      
        "       - type: number\n" ;
  
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
  
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
  
    SwaggerParseResult result = parser.readContents(yaml,auths,options);
    List<String> messageList = result.getMessages();
    Set<String> messages = new HashSet<>(messageList);
  
    Schema idSchema = result.getOpenAPI().getComponents().getSchemas().get("id");
    assertTrue(idSchema != null);
    assertTrue(idSchema instanceof ComposedSchema);
    
    ComposedSchema idCompSchema = (ComposedSchema) idSchema;
    List<Schema> anyOfSchemas = idCompSchema.getAnyOf();
    assertTrue(anyOfSchemas != null);
    assertEquals(anyOfSchemas.size(), 2);
    
    Schema stringSchema = anyOfSchemas.get(0);
    assertTrue(stringSchema != null);
    assertEquals(stringSchema.getType(), "string");
  
    Schema numberSchema = anyOfSchemas.get(1);
    assertTrue(numberSchema != null);
    assertEquals(numberSchema.getType(), "number");
    
}
 
Example 4
Source File: OpenApi3Utils.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
public static boolean isAnyOfSchema(Schema schema) {
  if (!(schema instanceof ComposedSchema)) return false;
  ComposedSchema composedSchema = (ComposedSchema) schema;
  return (composedSchema.getAnyOf() != null && composedSchema.getAnyOf().size() != 0);
}