0

How can i define same endpoint with different roles in swaggerhub api documentation.

/register:
    post:
      summary: Creates a new Driver.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/User'

      responses:
        200:
           description: OK  
        201:
          description: 'User created successfully.'
          content:
              application/json:
                schema:
                  type: object
                  properties:
                    success:
                      type: boolean
                      example: true
                    code:
                      type: integer
                      example: 201
                    message:
                      type: string
                      example: User Registered Successfully.
                    data:
                      type: object
                      properties:
                        user_id:
                          type: integer
                        name: 
                          type: string
                        full_name:
                          type: string
                        email:
                          type: string
                        mobile_number:
                          type: string
                        is_verified:
                          type: boolean
                        is_active:
                          type: boolean


components:
  schemas:
    User:
      properties:
        mobile_number:
          type: string
        email:
          type: string
        gender:
          type: string
          enum: ['male','female','others']
        password:
          type: string
        full_name:
          type: string
        role_id:
          type: integer
        vehicle_type:
          type: string
          enum: ['Bike','Car','Bicycle','Other']


      # All properties are required
      required:  
        - mobile_number
        - gender
        - full_name
        - role_id
        - password
        - vehicle_type

Now, is there any way to use same endpoint for different role_id. so i can use same resource with other validation fields. i want to user same register resource for different-different roles.

Anyone has an idea about this?

Manish J
  • 686
  • 1
  • 8
  • 24
  • Could you please clarify what you mean by "to use same endpoint for different role_id. so i can use same resource with other validation fields"? Do you mean the request body needs to have different fields depending on the `role_id`? If you could post some actual JSON request examples, that would help understand your use case. – Helen Oct 10 '18 at 11:02
  • See if this helps: [Swagger Inheritance and Composition](https://stackoverflow.com/q/27862407/113116), [Creating an extendible model using Swagger/ OpenAPI](https://stackoverflow.com/q/42496266/113116), [Swagger: variant schema shape dependant on field value](https://stackoverflow.com/q/46557096/113116). – Helen Oct 10 '18 at 11:10

0 Answers0