Schema as body (not in body)?

18 views
Skip to first unread message

Anthony Liatsis

unread,
May 28, 2016, 9:02:28 PM5/28/16
to Swagger
Hi is it possible to define a json schema as the body instead of a named parameter in the body of a POST request?
For example, if I had a User schema, can I define the request body as the user object instead of needing a 'user' parameter within the body?

Thanks in advance!

Ron Ratovsky

unread,
May 29, 2016, 6:30:29 PM5/29/16
to swagger-sw...@googlegroups.com

Unfortunately, I don’t follow the question. Can you clarify?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anthony Liatsis

unread,
May 29, 2016, 7:12:32 PM5/29/16
to Swagger
Hi, so for example:

I've seen Swagger docs use a schema as a parameter in the body like this :

paths:
  /user:
    post:
      summary: Create a User
      parameters:
        - name: user
          in: body
          required: true
          schema: 
            $ref: '#/definitions/User'

which means the POST request body must provide the user in the nested field `user` like this:
{
  user: {
    firstName: 'John',
    lastName: 'Smith'
  }
}


My question is if the User schema can define the body parameters itself without needing the nested object in the request body like this:
{
  firstName: 'John',
  lastName: 'Smith'
}


Thanks in advance!

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron Ratovsky

unread,
May 29, 2016, 7:16:36 PM5/29/16
to swagger-sw...@googlegroups.com

How is your '#/definitions/User' defined?

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--

You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Anthony Liatsis

unread,
May 29, 2016, 9:08:43 PM5/29/16
to Swagger
For example:

definitions:
  User:
    type: object
    properties:
      firstName:
        type: string
        description: First name of the user
      lastName:
        type: string
        description: Last name of the user

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron Ratovsky

unread,
May 29, 2016, 9:58:44 PM5/29/16
to swagger-sw...@googlegroups.com

 

Then there’s no problem. There’s nothing wrapping the request in another layer with the user property.

The name defined for the parameter doesn’t affect the input.

For example:

 

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Anthony Liatsis

unread,
May 29, 2016, 10:06:08 PM5/29/16
to Swagger
wow you are very correct!

I guess I was just getting thrown off by it being called a parameter and having a name.

Thanks for the help!

For example:

 

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron Ratovsky

unread,
May 29, 2016, 10:15:05 PM5/29/16
to swagger-sw...@googlegroups.com

Yes, I’m often surprised by my level of correctness too! Just don’t tell others, to not raise their expectations ;)

 

Glad we got it sorted out, feel free to reach out again in the future.

For example:

 

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages