Skip to content

Use of allOf to document a field makes the field disappear #2884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ivucica opened this issue May 16, 2016 · 4 comments
Open

Use of allOf to document a field makes the field disappear #2884

ivucica opened this issue May 16, 2016 · 4 comments

Comments

@ivucica
Copy link
Contributor

ivucica commented May 16, 2016

Cheers,

Let's assume existence of User definition, and Submission definition. The Submission definition can contain User fields author and submitter. I'd like to document author and submitter.

I've went to editor.swagger.io. Having taken the petstore_full.yaml example, I've tried to apply the suggestion from OAI/OpenAPI-Specification#556 (comment 192007034). Taking the Pet definition:

  Pet:
    type: object
    required:
      - name
      - photoUrls
    properties:
      id:
        type: integer
        format: int64
      category:
        $ref: "#/definitions/Category"
    # etc

I've made the following change to category property:

      category:
        description: This is pet's category.
        allOf:
        - $ref: "#/definitions/Category"

I've tried to generate the Go code for this, but (aside from editor itself showing 'undefined' at one point) the generator made that field disappear.

It would be nice if the field didn't disappear, and if the description was put in the leading comment of the Go struct field.

There is an even worse behavior if you try to do this to an operation's parameter:

paths:
  /pets:
    post:
      tags:
        - pet
      summary: Add a new pet to the store
      description: ""
      operationId: addPet
      consumes:
        - application/json
        - application/xml
      produces:
        - application/json
        - application/xml
      parameters:
        - in: body
          name: body
          description: Pet object that needs to be added to the store
          required: false
          schema:
            description: bleh
            allOf:
            - $ref: "#/definitions/Pet"

which causes this (newlines added for readability):

Unable to build target:
Could not process operation: 
Tag: pet
Operation: addPet
Resource: post /pets
Definitions: {User=io.swagger.models.ModelImpl@1e62688a, Category=io.swagger.models.ModelImpl@5e24b60b, Pet=io.swagger.models.ModelImpl@bfb7fbb1, Tag=io.swagger.models.ModelImpl@5e24b60b, Order=io.swagger.models.ModelImpl@b8396aae}
Exception: null

(Of course, this issue applies only if the cited comment isn't misleading -- that is, if the spec is actually supposed to support this way of documenting property usages. I believe it'd be a very useful behavior, but maybe it's really not supposed to be supported at the moment.)

@wing328
Copy link
Contributor

wing328 commented May 17, 2016

@ivucica thanks for reporting the issue. Here are 2 suggestions:

  1. use the latest master to generate the Go API client, which has 35 PRs (enhancement, bug fix) since the last stable release v2.1.6. (editor.swagger.io is using the latest stable version v2.1.6)

  2. Go does not have any support of inheritance/model composition at the moment so I would suggest you to avoid using allOf to define your model for the time being. We plan to provide better support of inheritance/model composition to API clients in coming July

@ivucica
Copy link
Contributor Author

ivucica commented May 19, 2016

Thanks for the response!

  1. Sure. I'm doing this already when building locally, I just didn't verify with the local build.
  2. The only reason for me to use allOf (or be aware of it!) is the above use case in Extra JSON Reference properties ignored - reduces reusability of references OAI/OpenAPI-Specification#556 comment 192007034 -- i.e. documenting how a field referencing a definition is to be used. I'm not really interested, at the moment, in any other use of allOf aside from attaching a piece of documentation to a field. :-)

@wing328 wing328 modified the milestones: v2.2.0, v2.3.0 Jul 7, 2016
@wing328 wing328 modified the milestones: v2.2.1, v2.2.2 Aug 8, 2016
@wing328 wing328 modified the milestones: v2.2.2, v2.2.3 Feb 22, 2017
@wing328 wing328 modified the milestones: v2.2.3, v2.3.0 Jul 16, 2017
@wing328 wing328 modified the milestones: v2.3.0, v2.4.0 Dec 15, 2017
@alexz0000
Copy link

Hi, does the swagger support allof for go now? I use the latest version of swagger, looks it still doesn't support allof.

@roman-sinyakov
Copy link

The same issue in java client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants