Bird
0
0

You want to define a schema for a REST API response that returns a list of users, where each user has a username (string) and roles (array of strings). Which schema snippet correctly represents this?

hard📝 Application Q15 of 15
Rest API - API Documentation
You want to define a schema for a REST API response that returns a list of users, where each user has a username (string) and roles (array of strings). Which schema snippet correctly represents this?
Atype: object properties: users: type: array items: type: object properties: username: type: string roles: type: array items: type: string
Btype: array items: type: object properties: username: string roles: array of strings
Ctype: object properties: users: type: object properties: username: string roles: string
Dtype: array items: type: string properties: username: string roles: array
Step-by-Step Solution
Solution:
  1. Step 1: Understand the data structure

    The response is an object with a "users" property that is an array of user objects.
  2. Step 2: Check each user object schema

    Each user has "username" as string and "roles" as an array of strings, so nested arrays and objects are needed.
  3. Step 3: Match with options

    Only type: object properties: users: type: array items: type: object properties: username: type: string roles: type: array items: type: string correctly nests arrays and objects with proper types and keys.
  4. Final Answer:

    type: object properties: users: type: array items: type: object properties: username: type: string roles: type: array items: type: string -> Option A
  5. Quick Check:

    Nested arrays and objects = type: object properties: users: type: array items: type: object properties: username: type: string roles: type: array items: type: string [OK]
Quick Trick: Use nested objects and arrays for complex data shapes [OK]
Common Mistakes:
MISTAKES
  • Writing array items as plain strings
  • Confusing object and array types
  • Missing nested items key for arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes