OpenAPI reuse part of definition without defining a new one

17 views
Skip to first unread message

Gabriele Proietti Mattia

unread,
Oct 17, 2017, 3:42:31 AM10/17/17
to Swagger

Suppose that I have this definition in a yaml OpenApi definition

definitions:
  User:
    description: "User"
    type: "object"
    properties:
      firstname:
        type: "string"
      lastname:
        type: "string"
      password:
        type: "string"
      email:
        type: "string"
      username:
        type: "string"

If in a parameters specification I need specific fields of a definition how can I refer them without defining another model as below?

definitions:
  UserLogin:
    description: "User"
    type: "object"
    properties:
      password:
        type: "string"
      email:
        type: "string"

Ron Ratovsky

unread,
Oct 17, 2017, 12:28:10 PM10/17/17
to swagger-sw...@googlegroups.com

You can’t. JSON Schema doesn’t allow you to pick fields out of a definition.

You can define the smaller instance, and make the bigger one an extension of the smaller one to avoid repetition.

--
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.

Reply all
Reply to author
Forward
0 new messages