You’re doing nothing wrong, it’s a known bug in swagger-ui about using allOf 
inside arrays.

It should be fixed within a few weeks.

 

 

From: <[email protected]> on behalf of 
"[email protected]" <[email protected]>
Reply-To: "[email protected]" 
<[email protected]>
Date: Wednesday, 1 March 2017 at 9:27
To: Swagger <[email protected]>
Subject: Trouble with the usage of allOf in combination with the swagger UI

 

Hi, 

 

First of all : I'm sorry if this is a duplicate question, I can't find a search 
button ;).

 

This is my example swagger file that produces the problem in json is pasted at 
the bottom of this question:

 

swagger: '2.0'

info:

  title: Example

  description: API

  version: "1.0.0"

# the domain of the service

host: Dont_know

# array of all schemes that your API supports

schemes:

  - https

# will be prefixed to all paths

basePath: /v1

produces:

  - application/json

 

paths:

  /services:

    get:

      summary: List available services.

      description: This request lists all services.

      responses:

        200:

          description: An array containing the services

          schema:

            $ref: "#/definitions/ServiceBase"

 

  /services/{service_id}:

    get:

      summary: Get details of this specific service

      description: Returns specific information about this service

 

      parameters:

        - name: service_id

          in: path

          required: true

          description: The id of the service

          type: string

      

      responses:

        200:

          description: A more detailed description of a specific service.

          schema:

            $ref: "#/definitions/ServicePlus"

 

definitions:

  

  ServiceBase:

    type: object

    properties:

      id:

        type: string

        description: The id of the service.

      display_name:

        type: string

        description: Name of the service

  

  ServicePlus:

    type: array

    items:

      type: object

      allOf:

        - $ref: "#/definitions/ServiceBase"

        - properties:

            extra_info:

              type: string

              description: Extra information concerning this service.

        

          

I'm trying to do some form of subclassing by having a ServiceBase model and a 
ServicePlus model which "inherits" the properties off the ServiceBase and 
extends it with another property. From what I've read online this should work, 
and the editor does not error. However when opening the swagger file in the 
json the GET request for Services works as expected, but the for the specific 
service it shows 

Model:

 

ServicePlus [ 

Inline Model 1

]

Inline Model 1 {}

 

or when looking at the Example Value I just get an empty list:

 

[

 {} ]



 

This probably means I have done something wrong, or something else is going 
amiss. Is there a fix for this behaviour or an alternative for allOf that will 
suit my needs?

 

 

 

 

Swagger file in json.

 

{

  "swagger" : "2.0",

  "info" : {

    "description" : "API",

    "version" : "1.0.0",

    "title" : "Example"

  },

  "host" : "Dont_know",

  "basePath" : "/v1",

  "schemes" : [ "https" ],

  "produces" : [ "application/json" ],

  "paths" : {

    "/services" : {

      "get" : {

        "summary" : "List available services.",

        "description" : "This request lists all services.",

        "parameters" : [ ],

        "responses" : {

          "200" : {

            "description" : "An array containing the services",

            "schema" : {

              "$ref" : "#/definitions/ServiceBase"

            }

          }

        }

      }

    },

    "/services/{service_id}" : {

      "get" : {

        "summary" : "Get details of this specific service",

        "description" : "Returns specific information about this service",

        "parameters" : [ {

          "name" : "service_id",

          "in" : "path",

          "description" : "The id of the service",

          "required" : true,

          "type" : "string"

        } ],

        "responses" : {

          "200" : {

            "description" : "A more detailed description of a specific 
service.",

            "schema" : {

              "$ref" : "#/definitions/ServicePlus"

            }

          }

        }

      }

    }

  },

  "definitions" : {

    "ServiceBase" : {

      "type" : "object",

      "properties" : {

        "id" : {

          "type" : "string",

          "description" : "The id of the service."

        },

        "display_name" : {

          "type" : "string",

          "description" : "Name of the service"

        }

      }

    },

    "ServicePlus" : {

      "type" : "array",

      "items" : {

        "type" : "object",

        "properties" : { }

      }

    }

  }

}

-- 
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 [email protected].
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to